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

[Joy][docs] Add documentation for Input component #35482

Merged
merged 22 commits into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from 14 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
11 changes: 11 additions & 0 deletions docs/data/joy/components/input/BasicInput.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as React from 'react';
import Box from '@mui/joy/Box';
import Input from '@mui/joy/Input';

export default function BasicInput() {
return (
<Box sx={{ width: '100%' }}>
<Input placeholder="Type in here…" />
</Box>
);
}
11 changes: 11 additions & 0 deletions docs/data/joy/components/input/BasicInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as React from 'react';
import Box from '@mui/joy/Box';
import Input from '@mui/joy/Input';

export default function BasicInput() {
return (
<Box sx={{ width: '100%' }}>
<Input placeholder="Type in here…" />
</Box>
);
}
1 change: 1 addition & 0 deletions docs/data/joy/components/input/BasicInput.tsx.preview
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<Input placeholder="Type in here…" />
22 changes: 22 additions & 0 deletions docs/data/joy/components/input/InputColors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as React from 'react';
import Box from '@mui/joy/Box';
import Input from '@mui/joy/Input';

export default function InputColors() {
return (
<Box
sx={{
py: 2,
display: 'grid',
gap: 2,
alignItems: 'center',
flexWrap: 'wrap',
}}
>
<Input placeholder="Type in here…" variant="outlined" color="primary" />
<Input placeholder="Type in here…" variant="outlined" color="neutral" />
<Input placeholder="Type in here…" variant="outlined" color="danger" />
<Input placeholder="Type in here…" variant="outlined" color="warning" />
</Box>
);
}
22 changes: 22 additions & 0 deletions docs/data/joy/components/input/InputColors.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as React from 'react';
import Box from '@mui/joy/Box';
import Input from '@mui/joy/Input';

export default function InputColors() {
return (
<Box
sx={{
py: 2,
display: 'grid',
gap: 2,
alignItems: 'center',
flexWrap: 'wrap',
}}
>
<Input placeholder="Type in here…" variant="outlined" color="primary" />
<Input placeholder="Type in here…" variant="outlined" color="neutral" />
<Input placeholder="Type in here…" variant="outlined" color="danger" />
<Input placeholder="Type in here…" variant="outlined" color="warning" />
</Box>
);
}
4 changes: 4 additions & 0 deletions docs/data/joy/components/input/InputColors.tsx.preview
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<Input placeholder="Type in here…" variant="outlined" color="primary" />
<Input placeholder="Type in here…" variant="outlined" color="neutral" />
<Input placeholder="Type in here…" variant="outlined" color="danger" />
<Input placeholder="Type in here…" variant="outlined" color="warning" />
36 changes: 36 additions & 0 deletions docs/data/joy/components/input/InputDecorators.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as React from 'react';
import Box from '@mui/joy/Box';
import IconButton from '@mui/joy/IconButton';
import Input from '@mui/joy/Input';
import Typography from '@mui/joy/Typography';

export default function InputDecorators() {
const [text, setText] = React.useState('');
const addEmoji = (emoji) => () => setText(`${text}${emoji}`);
return (
<Input
placeholder="Type in here…"
value={text}
onChange={(event) => setText(event.target.value)}
startDecorator={
<Box sx={{ display: 'flex', gap: 2 }}>
<IconButton variant="outlined" color="neutral" onClick={addEmoji('👍')}>
👍
</IconButton>
<IconButton variant="outlined" color="neutral" onClick={addEmoji('🏖')}>
🏖
</IconButton>
<IconButton variant="outlined" color="neutral" onClick={addEmoji('😍')}>
😍
</IconButton>
</Box>
}
endDecorator={
<Typography level="body3" sx={{ ml: 'auto' }}>
{text.length} character(s)
</Typography>
}
sx={{ minWidth: 300 }}
/>
);
}
36 changes: 36 additions & 0 deletions docs/data/joy/components/input/InputDecorators.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as React from 'react';
import Box from '@mui/joy/Box';
import IconButton from '@mui/joy/IconButton';
import Input from '@mui/joy/Input';
import Typography from '@mui/joy/Typography';

export default function InputDecorators() {
const [text, setText] = React.useState('');
const addEmoji = (emoji: string) => () => setText(`${text}${emoji}`);
return (
<Input
placeholder="Type in here…"
value={text}
onChange={(event) => setText(event.target.value)}
startDecorator={
<Box sx={{ display: 'flex', gap: 2 }}>
<IconButton variant="outlined" color="neutral" onClick={addEmoji('👍')}>
👍
</IconButton>
<IconButton variant="outlined" color="neutral" onClick={addEmoji('🏖')}>
🏖
</IconButton>
<IconButton variant="outlined" color="neutral" onClick={addEmoji('😍')}>
😍
</IconButton>
</Box>
}
endDecorator={
<Typography level="body3" sx={{ ml: 'auto' }}>
{text.length} character(s)
</Typography>
}
sx={{ minWidth: 300 }}
/>
);
}
15 changes: 15 additions & 0 deletions docs/data/joy/components/input/InputField.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as React from 'react';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import FormHelperText from '@mui/joy/FormHelperText';
import Input from '@mui/joy/Input';

export default function InputField() {
return (
<FormControl>
<FormLabel>Label</FormLabel>
<Input placeholder="Placeholder" />
<FormHelperText>This is a helper text.</FormHelperText>
</FormControl>
);
}
15 changes: 15 additions & 0 deletions docs/data/joy/components/input/InputField.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as React from 'react';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import FormHelperText from '@mui/joy/FormHelperText';
import Input from '@mui/joy/Input';

export default function InputField() {
return (
<FormControl>
<FormLabel>Label</FormLabel>
<Input placeholder="Placeholder" />
<FormHelperText>This is a helper text.</FormHelperText>
</FormControl>
);
}
5 changes: 5 additions & 0 deletions docs/data/joy/components/input/InputField.tsx.preview
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<FormControl>
<FormLabel>Label</FormLabel>
<Input placeholder="Placeholder" />
<FormHelperText>This is a helper text.</FormHelperText>
</FormControl>
33 changes: 33 additions & 0 deletions docs/data/joy/components/input/InputFormProps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as React from 'react';
import Box from '@mui/joy/Box';
import Button from '@mui/joy/Button';
import Input from '@mui/joy/Input';

export default function InputFormProps() {
return (
<Box
sx={{
py: 2,
display: 'flex',
flexDirection: 'column',
gap: 2,
alignItems: 'center',
flexWrap: 'wrap',
}}
>
<form
onSubmit={(event) => {
event.preventDefault();
}}
>
<Input
placeholder="Try to submit with no text!"
required
sx={{ mb: 1, fontSize: 'var(--joy-fontSize-sm)' }}
/>
<Input placeholder="It is disabled" disabled sx={{ mb: 1 }} />
<Button type="submit">Submit</Button>
</form>
</Box>
);
}
33 changes: 33 additions & 0 deletions docs/data/joy/components/input/InputFormProps.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as React from 'react';
import Box from '@mui/joy/Box';
import Button from '@mui/joy/Button';
import Input from '@mui/joy/Input';

export default function InputFormProps() {
return (
<Box
sx={{
py: 2,
display: 'flex',
flexDirection: 'column',
gap: 2,
alignItems: 'center',
flexWrap: 'wrap',
}}
>
<form
onSubmit={(event) => {
event.preventDefault();
}}
>
<Input
placeholder="Try to submit with no text!"
required
sx={{ mb: 1, fontSize: 'var(--joy-fontSize-sm)' }}
/>
<Input placeholder="It is disabled" disabled sx={{ mb: 1 }} />
<Button type="submit">Submit</Button>
</form>
</Box>
);
}
13 changes: 13 additions & 0 deletions docs/data/joy/components/input/InputFormProps.tsx.preview
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<form
onSubmit={(event) => {
event.preventDefault();
}}
>
<Input
placeholder="Try to submit with no text!"
required
sx={{ mb: 1, fontSize: 'var(--joy-fontSize-sm)' }}
/>
<Input placeholder="It is disabled" disabled sx={{ mb: 1 }} />
<Button type="submit">Submit</Button>
</form>
13 changes: 13 additions & 0 deletions docs/data/joy/components/input/InputSizes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as React from 'react';
import Box from '@mui/joy/Box';
import Input from '@mui/joy/Input';

export default function InputSizes() {
return (
<Box sx={{ display: 'flex', gap: 2, alignItems: 'center', flexWrap: 'wrap' }}>
<Input size="sm" placeholder="Small" />
<Input size="md" placeholder="Medium" />
<Input size="lg" placeholder="Large" />
</Box>
);
}
13 changes: 13 additions & 0 deletions docs/data/joy/components/input/InputSizes.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as React from 'react';
import Box from '@mui/joy/Box';
import Input from '@mui/joy/Input';

export default function InputSizes() {
return (
<Box sx={{ display: 'flex', gap: 2, alignItems: 'center', flexWrap: 'wrap' }}>
<Input size="sm" placeholder="Small" />
<Input size="md" placeholder="Medium" />
<Input size="lg" placeholder="Large" />
</Box>
);
}
3 changes: 3 additions & 0 deletions docs/data/joy/components/input/InputSizes.tsx.preview
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Input size="sm" placeholder="Small" />
<Input size="md" placeholder="Medium" />
<Input size="lg" placeholder="Large" />
70 changes: 70 additions & 0 deletions docs/data/joy/components/input/InputSubscription.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import * as React from 'react';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import FormHelperText from '@mui/joy/FormHelperText';
import Input from '@mui/joy/Input';
import Button from '@mui/joy/Button';

export default function InputSubscription() {
const [form, setForm] = React.useState({
email: '',
status: 'initial',
});

const handleSubmit = () => {
setForm((current) => ({ ...current, status: 'loading' }));
try {
// Replace timeout with real backend operation
setTimeout(() => {
setForm({ email: '', status: 'sent' });
}, 1500);
} catch (error) {
setForm((current) => ({ ...current, status: 'failure' }));
}
};

return (
<FormControl>
<FormLabel
sx={(theme) => ({
'--FormLabel-color': theme.vars.palette.primary[400],
})}
>
MUI Newsletter
</FormLabel>
<Input
sx={{ pt: 0.5, pb: 0.5 }}
placeholder="mail@mui.com"
type="email"
value={form.email}
onChange={(event) =>
setForm({ email: event.target.value, status: 'initial' })
}
error={form.status === 'failure'}
endDecorator={
<Button
variant="solid"
color="primary"
sx={{ ml: 1, height: '45px' }}
disabled={form.email.length === 0 || form.status === 'failure'}
loading={form.status === 'loading'}
onClick={handleSubmit}
>
Subscribe
</Button>
}
/>
{form.status === 'failure' && (
<FormHelperText sx={(theme) => ({ color: theme.vars.palette.danger[400] })}>
Oops! something went wrong, please try again later.
</FormHelperText>
)}

{form.status === 'sent' && (
<FormHelperText sx={(theme) => ({ color: theme.vars.palette.primary[400] })}>
You are all set!
</FormHelperText>
)}
</FormControl>
);
}
8 changes: 8 additions & 0 deletions docs/data/joy/components/input/InputSubscription.preview
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Input
placeholder="mail@mui.com"
endDecorator={
<Button variant="solid" color="primary" sx={{ ml: 1 }}>
Subscribe
</Button>
}
/>
Loading