parent
a066b0dd40
commit
0ba137617e
@ -1,104 +0,0 @@ |
||||
import React from 'react'; |
||||
|
||||
import { Button } from '../../basic/Button'; |
||||
import { Icon } from '../../basic/Icon'; |
||||
import { MarkdownText } from '../../basic/MarkdownText'; |
||||
import { RawText } from '../../basic/RawText'; |
||||
import { useTranslation } from '../../providers/TranslationProvider'; |
||||
import { useFieldActions } from './EditingState'; |
||||
|
||||
|
||||
function GenericSettingInput({ _id, value, placeholder, readonly, autocomplete, disabled, onChange }) { |
||||
const handleChange = (event) => { |
||||
const { value } = event.currentTarget; |
||||
onChange({ value }); |
||||
}; |
||||
|
||||
return <input type='text' className='rc-input__element' name={_id} value={value} placeholder={placeholder} |
||||
disabled={disabled} readOnly={readonly} autoComplete={autocomplete === false ? 'off' : undefined} |
||||
onChange={handleChange} />; |
||||
} |
||||
|
||||
function BooleanSettingInput({ _id, disabled, readonly, autocomplete, value, onChange }) { |
||||
const t = useTranslation(); |
||||
|
||||
const handleChange = (event) => { |
||||
const value = event.currentTarget.value === '1'; |
||||
onChange({ value }); |
||||
}; |
||||
|
||||
return <> |
||||
<label> |
||||
<input type='radio' name={_id} value='1' checked={value === true} disabled={disabled} readOnly={readonly} |
||||
autoComplete={autocomplete === false ? 'off' : undefined} onChange={handleChange} /> {t('True')} |
||||
</label> |
||||
<label> |
||||
<input type='radio' name={_id} value='0' checked={value === false} disabled={disabled} readOnly={readonly} |
||||
autoComplete={autocomplete === false ? 'off' : undefined} onChange={handleChange} /> {t('False')} |
||||
</label> |
||||
</>; |
||||
} |
||||
|
||||
export function Field({ field }) { |
||||
const t = useTranslation(); |
||||
const { update, reset, disabled } = useFieldActions(field); |
||||
|
||||
const inputProps = { ...field, disabled, onChange: update }; |
||||
|
||||
const { |
||||
_id, |
||||
disableReset, |
||||
readonly, |
||||
type, |
||||
value, |
||||
packageValue, |
||||
blocked, |
||||
changed, |
||||
i18nLabel, |
||||
i18nDescription, |
||||
alert, |
||||
} = field; |
||||
|
||||
const hasResetButton = !disableReset && !readonly && type !== 'asset' && value !== packageValue && !blocked; |
||||
const onResetButtonClick = () => { |
||||
reset(); |
||||
}; |
||||
|
||||
return <div className={['input-line', 'double-col', changed && 'setting-changed'].filter(Boolean).join(' ')}> |
||||
<label className='setting-label' title={_id}>{(i18nLabel && t(i18nLabel)) || (_id || t(_id))}</label> |
||||
<div className='setting-field'> |
||||
{(type === 'boolean' && <BooleanSettingInput {...inputProps} />) |
||||
|| <GenericSettingInput {...inputProps} />} |
||||
{/* {setting.type === 'string' && <StringSettingInput setting={setting} />} */} |
||||
{/* {setting.type === 'relativeUrl' && <RelativeUrlSettingInput setting={setting} />} */} |
||||
{/* {setting.type === 'password' && <PasswordSettingInput setting={setting} />} */} |
||||
{/* {setting.type === 'int' && <IntSettingInput setting={setting} />} */} |
||||
{/* {setting.type === 'select' && <SelectSettingInput setting={setting} />} */} |
||||
{/* {setting.type === 'language' && <LanguageSettingInput setting={setting} />} */} |
||||
{/* {setting.type === 'color' && <ColorSettingInput setting={setting} />} */} |
||||
{/* {setting.type === 'font' && <FontSettingInput setting={setting} />} */} |
||||
{/* {setting.type === 'code' && <CodeSettingInput setting={setting} />} */} |
||||
{/* {setting.type === 'action' && <ActionSettingInput setting={setting} didSectionChange={didSectionChange} />} */} |
||||
{/* {setting.type === 'asset' && <AssetSettingInput setting={setting} />} */} |
||||
{/* {setting.type === 'roomPick' && <RoomPickSettingInput setting={setting} />} */} |
||||
|
||||
{t.has(i18nDescription) && <div className='settings-description secondary-font-color'> |
||||
<MarkdownText>{t(i18nDescription)}</MarkdownText> |
||||
</div>} |
||||
|
||||
{alert && <div className='settings-alert pending-color pending-background pending-border'> |
||||
<Icon icon='icon-attention' /> |
||||
<RawText>{t(alert)}</RawText> |
||||
</div>} |
||||
</div> |
||||
|
||||
{hasResetButton && <Button |
||||
aria-label={t('Reset')} |
||||
children={<Icon icon='icon-ccw' className='color-error-contrast' />} |
||||
className='reset-setting' |
||||
data-setting={_id} |
||||
cancel |
||||
onClick={onResetButtonClick} |
||||
/>} |
||||
</div>; |
||||
} |
||||
@ -0,0 +1,18 @@ |
||||
import { Text } from '@rocket.chat/fuselage'; |
||||
import React from 'react'; |
||||
|
||||
import { Icon } from '../../basic/Icon'; |
||||
import { useTranslation } from '../../providers/TranslationProvider'; |
||||
|
||||
export function ResetSettingButton({ onClick }) { |
||||
const t = useTranslation(); |
||||
|
||||
return <Text |
||||
aria-label={t('Reset')} |
||||
dangerColor |
||||
title={t('Reset')} |
||||
onClick={onClick} |
||||
> |
||||
<Icon icon='icon-ccw' /> |
||||
</Text>; |
||||
} |
||||
@ -0,0 +1,68 @@ |
||||
import { |
||||
Callout, |
||||
Field, |
||||
} from '@rocket.chat/fuselage'; |
||||
import React from 'react'; |
||||
|
||||
import { MarkdownText } from '../../basic/MarkdownText'; |
||||
import { RawText } from '../../basic/RawText'; |
||||
import { useTranslation } from '../../providers/TranslationProvider'; |
||||
import { useFieldActions } from './EditingState'; |
||||
import { GenericSettingInput } from './inputs/GenericSettingInput'; |
||||
import { BooleanSettingInput } from './inputs/BooleanSettingInput'; |
||||
import { StringSettingInput } from './inputs/StringSettingInput'; |
||||
|
||||
export function SettingField({ field }) { |
||||
const t = useTranslation(); |
||||
const { update, reset, disabled } = useFieldActions(field); |
||||
|
||||
const { |
||||
_id, |
||||
disableReset, |
||||
readonly, |
||||
type, |
||||
value, |
||||
packageValue, |
||||
blocked, |
||||
i18nLabel, |
||||
i18nDescription, |
||||
alert, |
||||
} = field; |
||||
|
||||
const label = (i18nLabel && t(i18nLabel)) || (_id || t(_id)); |
||||
const hint = t.has(i18nDescription) && <MarkdownText>{t(i18nDescription)}</MarkdownText>; |
||||
const callout = alert && <RawText>{t(alert)}</RawText>; |
||||
|
||||
const hasResetButton = !disableReset && !readonly && type !== 'asset' && value !== packageValue && !blocked; |
||||
const onResetButtonClick = () => { |
||||
reset(); |
||||
}; |
||||
|
||||
const inputProps = { |
||||
...field, |
||||
label, |
||||
disabled, |
||||
onChange: update, |
||||
hasResetButton, |
||||
onResetButtonClick, |
||||
}; |
||||
|
||||
return <Field> |
||||
{(type === 'boolean' && <BooleanSettingInput {...inputProps} />) |
||||
|| (type === 'string' && <StringSettingInput {...inputProps} />) |
||||
// || (type === 'relativeUrl' && <RelativeUrlSettingInput {...inputProps} />)
|
||||
// || (type === 'password' && <PasswordSettingInput {...inputProps} />)
|
||||
// || (type === 'int' && <IntSettingInput {...inputProps} />)
|
||||
// || (type === 'select' && <SelectSettingInput {...inputProps} />)
|
||||
// || (type === 'language' && <LanguageSettingInput {...inputProps} />)
|
||||
// || (type === 'color' && <ColorSettingInput {...inputProps} />)
|
||||
// || (type === 'font' && <FontSettingInput {...inputProps} />)
|
||||
// || (type === 'code' && <CodeSettingInput {...inputProps} />)
|
||||
// || (type === 'action' && <ActionSettingInput {...inputProps} />)
|
||||
// || (type === 'asset' && <AssetSettingInput {...inputProps} />)
|
||||
// || (type === 'roomPick' && <RoomPickSettingInput {...inputProps} />)
|
||||
|| <GenericSettingInput {...inputProps} />} |
||||
{hint && <Field.Hint>{hint}</Field.Hint>} |
||||
{callout && <Callout type='warning' title={callout} />} |
||||
</Field>; |
||||
} |
||||
@ -0,0 +1,39 @@ |
||||
import { |
||||
Field, |
||||
Label, |
||||
ToggleSwitch, |
||||
} from '@rocket.chat/fuselage'; |
||||
import React from 'react'; |
||||
|
||||
import { ResetSettingButton } from '../ResetSettingButton'; |
||||
|
||||
export function BooleanSettingInput({ |
||||
_id, |
||||
label, |
||||
disabled, |
||||
readonly, |
||||
autocomplete, |
||||
value, |
||||
onChange, |
||||
hasResetButton, |
||||
onResetButtonClick, |
||||
}) { |
||||
const handleChange = (event) => { |
||||
const value = event.currentTarget.checked; |
||||
onChange({ value }); |
||||
}; |
||||
|
||||
return <Field.Row> |
||||
<Label position='end' text={label} title={_id}> |
||||
<ToggleSwitch |
||||
value='true' |
||||
checked={value === true} |
||||
disabled={disabled} |
||||
readOnly={readonly} |
||||
autoComplete={autocomplete === false ? 'off' : undefined} |
||||
onChange={handleChange} |
||||
/> |
||||
</Label> |
||||
{hasResetButton && <ResetSettingButton onClick={onResetButtonClick} />} |
||||
</Field.Row>; |
||||
} |
||||
@ -0,0 +1,42 @@ |
||||
import { |
||||
Field, |
||||
Label, |
||||
TextInput, |
||||
} from '@rocket.chat/fuselage'; |
||||
import React from 'react'; |
||||
|
||||
import { ResetSettingButton } from '../ResetSettingButton'; |
||||
|
||||
export function GenericSettingInput({ |
||||
_id, |
||||
label, |
||||
value, |
||||
placeholder, |
||||
readonly, |
||||
autocomplete, |
||||
disabled, |
||||
onChange, |
||||
hasResetButton, |
||||
onResetButtonClick, |
||||
}) { |
||||
const handleChange = (event) => { |
||||
const { value } = event.currentTarget; |
||||
onChange({ value }); |
||||
}; |
||||
|
||||
return <> |
||||
<Field.Row> |
||||
<Label htmlFor={_id} text={label} title={_id} /> |
||||
{hasResetButton && <ResetSettingButton onClick={onResetButtonClick} />} |
||||
</Field.Row> |
||||
<TextInput |
||||
id={_id} |
||||
value={value} |
||||
placeholder={placeholder} |
||||
disabled={disabled} |
||||
readOnly={readonly} |
||||
autoComplete={autocomplete === false ? 'off' : undefined} |
||||
onChange={handleChange} |
||||
/> |
||||
</>; |
||||
} |
||||
@ -0,0 +1,55 @@ |
||||
import { |
||||
Field, |
||||
Label, |
||||
TextAreaInput, |
||||
TextInput, |
||||
} from '@rocket.chat/fuselage'; |
||||
import React from 'react'; |
||||
|
||||
import { ResetSettingButton } from '../ResetSettingButton'; |
||||
|
||||
export function StringSettingInput({ |
||||
_id, |
||||
label, |
||||
disabled, |
||||
multiline, |
||||
placeholder, |
||||
readonly, |
||||
autocomplete, |
||||
value, |
||||
onChange, |
||||
hasResetButton, |
||||
onResetButtonClick, |
||||
}) { |
||||
const handleChange = (event) => { |
||||
const { value } = event.currentTarget; |
||||
onChange({ value }); |
||||
}; |
||||
|
||||
return <> |
||||
<Field.Row> |
||||
<Label htmlFor={_id} text={label} title={_id} /> |
||||
{hasResetButton && <ResetSettingButton onClick={onResetButtonClick} />} |
||||
</Field.Row> |
||||
{multiline |
||||
? <TextAreaInput |
||||
id={_id} |
||||
rows={4} |
||||
value={value} |
||||
placeholder={placeholder} |
||||
disabled={disabled} |
||||
readOnly={readonly} |
||||
autoComplete={autocomplete === false ? 'off' : undefined} |
||||
onChange={handleChange} |
||||
/> |
||||
: <TextInput |
||||
id={_id} |
||||
value={value} |
||||
placeholder={placeholder} |
||||
disabled={disabled} |
||||
readOnly={readonly} |
||||
autoComplete={autocomplete === false ? 'off' : undefined} |
||||
onChange={handleChange} |
||||
/> } |
||||
</>; |
||||
} |
||||
Loading…
Reference in new issue