Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into docs/trap-focus
Browse files Browse the repository at this point in the history
  • Loading branch information
michaldudak committed Mar 25, 2022
2 parents 147769b + 13fe3f9 commit be579bb
Show file tree
Hide file tree
Showing 169 changed files with 2,524 additions and 399 deletions.
162 changes: 162 additions & 0 deletions docs/data/base/components/input/InputAdornments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import Box from '@mui/material/Box';
import ButtonUnstyled from '@mui/base/ButtonUnstyled';
import InputUnstyled, { inputUnstyledClasses } from '@mui/base/InputUnstyled';
import Visibility from '@mui/icons-material/Visibility';
import VisibilityOff from '@mui/icons-material/VisibilityOff';
import { styled } from '@mui/system';

const blue = {
100: '#DAECFF',
200: '#80BFFF',
400: '#3399FF',
600: '#0072E5',
};

const grey = {
50: '#F3F6F9',
100: '#E7EBF0',
200: '#E0E3E7',
300: '#CDD2D7',
400: '#B2BAC2',
500: '#A0AAB4',
600: '#6F7E8C',
700: '#3E5060',
800: '#2D3843',
900: '#1A2027',
};

const StyledInputRoot = styled('div')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
display: flex;
font-weight: 500;
border: 1px solid ${theme.palette.mode === 'dark' ? grey[800] : grey[300]};
border-radius: 8px;
background: ${theme.palette.mode === 'dark' ? grey[900] : grey[50]};
align-items: center;
justify-content: center;
&.${inputUnstyledClasses.focused} {
outline: 3px solid ${theme.palette.mode === 'dark' ? blue[600] : blue[100]};
}
&:hover {
background: ${theme.palette.mode === 'dark' ? '' : grey[100]};
border-color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]};
}
`,
);

const StyledInputElement = styled('input')(
({ theme }) => `
font-size: 0.875rem;
font-family: inherit;
font-weight: 400;
line-height: 1.5;
flex-grow: 1;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
background: inherit;
border: none;
border-radius: inherit;
padding: 12px 12px;
outline: 0;
`,
);

const IconButton = styled(ButtonUnstyled)`
display: inline-flex;
align-items: center;
justify-content: center;
border: none;
background: inherit;
cursor: pointer;
`;

const InputAdornment = styled('div')`
margin: 8px;
display: inline-flex;
align-items: center;
justify-content: center;
`;

const CustomInput = React.forwardRef(function CustomInput(props, ref) {
const { components, ...other } = props;
return (
<InputUnstyled
components={{
Root: StyledInputRoot,
Input: StyledInputElement,
...components,
}}
{...other}
ref={ref}
/>
);
});

CustomInput.propTypes = {
/**
* The components used for each slot inside the InputBase.
* Either a string to use a HTML element or a component.
* @default {}
*/
components: PropTypes.shape({
Input: PropTypes.elementType,
Root: PropTypes.elementType,
Textarea: PropTypes.elementType,
}),
};

export default function InputAdornments() {
const [values, setValues] = React.useState({
amount: '',
password: '',
weight: '',
weightRange: '',
showPassword: false,
});

const handleChange = (prop) => (event) => {
setValues({ ...values, [prop]: event.target.value });
};

const handleClickShowPassword = () => {
setValues({
...values,
showPassword: !values.showPassword,
});
};

const handleMouseDownPassword = (event) => {
event.preventDefault();
};

return (
<Box sx={{ display: 'flex', '& > * + *': { ml: 1 } }}>
<CustomInput
id="outlined-start-adornment"
startAdornment={<InputAdornment>kg</InputAdornment>}
/>
<CustomInput
id="outlined-adornment-password"
type={values.showPassword ? 'text' : 'password'}
value={values.password}
onChange={handleChange('password')}
endAdornment={
<InputAdornment>
<IconButton
aria-label="toggle password visibility"
onClick={handleClickShowPassword}
onMouseDown={handleMouseDownPassword}
edge="end"
>
{values.showPassword ? <VisibilityOff /> : <Visibility />}
</IconButton>
</InputAdornment>
}
/>
</Box>
);
}
163 changes: 163 additions & 0 deletions docs/data/base/components/input/InputAdornments.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import ButtonUnstyled from '@mui/base/ButtonUnstyled';
import InputUnstyled, {
InputUnstyledProps,
inputUnstyledClasses,
} from '@mui/base/InputUnstyled';
import Visibility from '@mui/icons-material/Visibility';
import VisibilityOff from '@mui/icons-material/VisibilityOff';
import { styled } from '@mui/system';

const blue = {
100: '#DAECFF',
200: '#80BFFF',
400: '#3399FF',
600: '#0072E5',
};

const grey = {
50: '#F3F6F9',
100: '#E7EBF0',
200: '#E0E3E7',
300: '#CDD2D7',
400: '#B2BAC2',
500: '#A0AAB4',
600: '#6F7E8C',
700: '#3E5060',
800: '#2D3843',
900: '#1A2027',
};

const StyledInputRoot = styled('div')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
display: flex;
font-weight: 500;
border: 1px solid ${theme.palette.mode === 'dark' ? grey[800] : grey[300]};
border-radius: 8px;
background: ${theme.palette.mode === 'dark' ? grey[900] : grey[50]};
align-items: center;
justify-content: center;
&.${inputUnstyledClasses.focused} {
outline: 3px solid ${theme.palette.mode === 'dark' ? blue[600] : blue[100]};
}
&:hover {
background: ${theme.palette.mode === 'dark' ? '' : grey[100]};
border-color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]};
}
`,
);

const StyledInputElement = styled('input')(
({ theme }) => `
font-size: 0.875rem;
font-family: inherit;
font-weight: 400;
line-height: 1.5;
flex-grow: 1;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
background: inherit;
border: none;
border-radius: inherit;
padding: 12px 12px;
outline: 0;
`,
);

const IconButton = styled(ButtonUnstyled)`
display: inline-flex;
align-items: center;
justify-content: center;
border: none;
background: inherit;
cursor: pointer;
`;

const InputAdornment = styled('div')`
margin: 8px;
display: inline-flex;
align-items: center;
justify-content: center;
`;

const CustomInput = React.forwardRef(function CustomInput(
props: InputUnstyledProps,
ref: React.ForwardedRef<HTMLDivElement>,
) {
const { components, ...other } = props;
return (
<InputUnstyled
components={{
Root: StyledInputRoot,
Input: StyledInputElement,
...components,
}}
{...other}
ref={ref}
/>
);
});

interface State {
amount: string;
password: string;
weight: string;
weightRange: string;
showPassword: boolean;
}

export default function InputAdornments() {
const [values, setValues] = React.useState<State>({
amount: '',
password: '',
weight: '',
weightRange: '',
showPassword: false,
});

const handleChange =
(prop: keyof State) => (event: React.ChangeEvent<HTMLInputElement>) => {
setValues({ ...values, [prop]: event.target.value });
};

const handleClickShowPassword = () => {
setValues({
...values,
showPassword: !values.showPassword,
});
};

const handleMouseDownPassword = (event: React.MouseEvent<HTMLButtonElement>) => {
event.preventDefault();
};

return (
<Box sx={{ display: 'flex', '& > * + *': { ml: 1 } }}>
<CustomInput
id="outlined-start-adornment"
startAdornment={<InputAdornment>kg</InputAdornment>}
/>
<CustomInput
id="outlined-adornment-password"
type={values.showPassword ? 'text' : 'password'}
value={values.password}
onChange={handleChange('password')}
endAdornment={
<InputAdornment>
<IconButton
aria-label="toggle password visibility"
onClick={handleClickShowPassword}
onMouseDown={handleMouseDownPassword}
edge="end"
>
{values.showPassword ? <VisibilityOff /> : <Visibility />}
</IconButton>
</InputAdornment>
}
/>
</Box>
);
}
Loading

0 comments on commit be579bb

Please sign in to comment.