Skip to content

Commit

Permalink
Code Review
Browse files Browse the repository at this point in the history
  • Loading branch information
Kmaschta committed Mar 18, 2019
1 parent b981270 commit 6076f49
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 22 deletions.
2 changes: 1 addition & 1 deletion docs/Inputs.md
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ import { PasswordInput } from 'react-admin';
![Password Input](./img/password-input.png)
It is possible to change the default behavior and display the value by default via the `initiallyHidden` prop:
It is possible to change the default behavior and display the value by default via the `initiallyVisible` prop:
```jsx
import { PasswordInput } from 'react-admin';
Expand Down
4 changes: 1 addition & 3 deletions examples/data-generator/src/customers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ export default (db, { serializeDate }) =>
const last_name = name.lastName();
const email = internet.email(first_name, last_name);
const birthday = has_ordered ? date.past(60) : null;
const password = internet.password();

return {
id,
first_name,
last_name,
email,
password,
address: has_ordered ? address.streetName() : null,
zipcode: has_ordered ? address.zipCode() : null,
city: has_ordered ? address.city() : null,
Expand All @@ -31,6 +29,6 @@ export default (db, { serializeDate }) =>
has_newsletter: has_ordered ? weightedBoolean(30) : true,
groups: [], // finalize
nb_commands: 0,
total_spent: 0,
total_spent: 0
};
});
14 changes: 3 additions & 11 deletions examples/demo/src/visitors/VisitorEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import {
ReferenceManyField,
TabbedForm,
TextField,
TextInput,
PasswordInput,
TextInput
} from 'react-admin';
import withStyles from '@material-ui/core/styles/withStyles';

Expand All @@ -40,7 +39,6 @@ const VisitorEdit = ({ classes, ...props }) => (
formClassName={classes.email}
/>
<DateInput source="birthday" formClassName={classes.birthday} />
<PasswordInput source="password" formClassName={classes.password} />
</FormTab>
<FormTab label="resources.customers.tabs.address" path="address">
<LongTextInput source="address" formClassName={classes.address} />
Expand All @@ -58,10 +56,7 @@ const VisitorEdit = ({ classes, ...props }) => (
<DateField source="date" />
<TextField source="reference" />
<NbItemsField />
<NumberField
source="total"
options={{ style: 'currency', currency: 'USD' }}
/>
<NumberField source="total" options={{ style: 'currency', currency: 'USD' }} />
<TextField source="status" />
<EditButton />
</Datagrid>
Expand All @@ -87,10 +82,7 @@ const VisitorEdit = ({ classes, ...props }) => (
<SegmentsInput />
<NullableBooleanInput source="has_newsletter" />
<DateField source="first_seen" style={{ width: 128, display: 'inline-block' }} />
<DateField
source="latest_purchase"
style={{ width: 128, display: 'inline-block' }}
/>
<DateField source="latest_purchase" style={{ width: 128, display: 'inline-block' }} />
<DateField source="last_seen" style={{ width: 128, display: 'inline-block' }} />
</FormTab>
</TabbedForm>
Expand Down
14 changes: 7 additions & 7 deletions packages/ra-ui-materialui/src/input/PasswordInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,29 @@ import TextInput from './TextInput';

class PasswordInput extends Component {
state = {
hidden: this.props.initiallyHidden,
visible: this.props.initiallyVisible,
};

toggleVisibility = () => {
this.setState(state => ({ hidden: !state.hidden }));
this.setState(state => ({ visible: !state.visible }));
};

render() {
const { translate, ...rest } = this.props;
const { hidden } = this.state;
const { visible } = this.state;

return (
<TextInput
{...rest}
type={hidden ? 'password' : 'text'}
type={visible ? 'text' : 'password'}
InputProps={{
endAdornment: (
<InputAdornment position="end">
<IconButton
aria-label={translate('ra.input.password.toggle_visibility')}
onClick={this.toggleVisibility}
>
{hidden ? <VisibilityOff /> : <Visibility />}
{visible ? <Visibility /> : <VisibilityOff />}
</IconButton>
</InputAdornment>
),
Expand All @@ -46,11 +46,11 @@ class PasswordInput extends Component {

PasswordInput.propTypes = {
translate: PropTypes.func.isRequired,
initiallyHidden: PropTypes.bool,
initiallyVisible: PropTypes.bool,
};

PasswordInput.defaultProps = {
initiallyHidden: true,
initiallyVisible: false,
};

export default compose(
Expand Down

0 comments on commit 6076f49

Please sign in to comment.