Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix-15877: add disabled state styles to Picker #16449

Merged
merged 4 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/components/Picker/Picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,16 @@ const propTypes = {

/** Additional events passed to the core Picker for specific platforms such as web */
additionalPickerEvents: PropTypes.func,

/** Hint text that appears below the picker */
hintText: PropTypes.string,
};

const defaultProps = {
label: '',
isDisabled: false,
errorText: '',
hintText: '',
containerStyles: [],
backgroundColor: undefined,
inputID: undefined,
Expand Down Expand Up @@ -172,6 +176,27 @@ class Picker extends PureComponent {
render() {
const hasError = !_.isEmpty(this.props.errorText);

if (this.props.isDisabled) {
return (
<View>
{this.props.label && (
<Text style={[styles.textLabelSupporting, styles.mb1]} numberOfLines={1}>
{this.props.label}
</Text>
)}
<Text numberOfLines={1}>
{this.props.value}
</Text>
{this.props.hintText
&& (
<Text style={[styles.textLabel, styles.colorMuted, styles.mt2]}>
{this.props.hintText}
</Text>
)}
</View>
);
}

return (
<>
<View
Expand Down Expand Up @@ -230,6 +255,12 @@ class Picker extends PureComponent {
/>
</View>
<FormHelpMessage message={this.props.errorText} />
{this.props.hintText
allroundexperts marked this conversation as resolved.
Show resolved Hide resolved
&& (
<Text style={[styles.textLabel, styles.colorMuted, styles.mt2]}>
{this.props.hintText}
</Text>
)}
</>
);
}
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,7 @@ export default {
nameIsRequiredError: 'You need to define a name for your workspace.',
currencyInputLabel: 'Default currency',
currencyInputHelpText: 'All expenses on this workspace will be converted to this currency.',
currencyInputDisabledText: 'The default currency can\'t be changed because this workspace is linked to a USD bank account.',
save: 'Save',
genericFailureMessage: 'An error occurred updating the workspace, please try again.',
avatarUploadFailureMessage: 'An error occurred uploading the avatar, please try again.',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,7 @@ export default {
nameIsRequiredError: 'Debes definir un nombre para tu espacio de trabajo.',
currencyInputLabel: 'Moneda por defecto',
currencyInputHelpText: 'Todas los gastos en este espacio de trabajo serán convertidos a esta moneda.',
currencyInputDisabledText: 'La moneda predeterminada no se puede cambiar porque este espacio de trabajo está vinculado a una cuenta bancaria en USD.',
save: 'Guardar',
genericFailureMessage: 'Se produjo un error al guardar el espacio de trabajo. Por favor, inténtalo de nuevo.',
avatarUploadFailureMessage: 'No se pudo subir el avatar. Por favor, inténtalo de nuevo.',
Expand Down
9 changes: 5 additions & 4 deletions src/pages/workspace/WorkspaceSettingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import lodashGet from 'lodash/get';
import ONYXKEYS from '../../ONYXKEYS';
import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize';
import styles from '../../styles/styles';
import Text from '../../components/Text';
import compose from '../../libs/compose';
import * as Policy from '../../libs/actions/Policy';
import * as Expensicons from '../../components/Icon/Expensicons';
Expand Down Expand Up @@ -136,11 +135,13 @@ class WorkspaceSettingsPage extends React.Component {
items={this.getCurrencyItems()}
isDisabled={hasVBA}
defaultValue={this.props.policy.outputCurrency}
hintText={
hasVBA
? this.props.translate('workspace.editor.currencyInputDisabledText')
: this.props.translate('workspace.editor.currencyInputHelpText')
}
/>
</View>
<Text style={[styles.textLabel, styles.colorMuted, styles.mt2]}>
{this.props.translate('workspace.editor.currencyInputHelpText')}
</Text>
</OfflineWithFeedback>
</Form>
)}
Expand Down
5 changes: 5 additions & 0 deletions src/stories/Picker.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const Default = Template.bind({});
Default.args = {
label: 'Default picker',
name: 'Default',
hintText: 'Default hint text',
items: [
{
label: 'Orange',
Expand All @@ -48,6 +49,7 @@ PickerWithValue.args = {
label: 'Picker with defined value',
name: 'Picker with defined value',
value: 'apple',
hintText: 'Picker with hint text',
items: [
{
label: 'Orange',
Expand All @@ -64,6 +66,7 @@ const ErrorStory = Template.bind({});
ErrorStory.args = {
label: 'Picker with error',
name: 'PickerWithError',
hintText: 'Picker hint text',
errorText: 'This field has an error.',
items: [
{
Expand All @@ -81,7 +84,9 @@ const Disabled = Template.bind({});
Disabled.args = {
label: 'Picker disabled',
name: 'Disabled',
value: 'orange',
isDisabled: true,
hintText: 'Picker hint text',
items: [
{
label: 'Orange',
Expand Down