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

[Textarea][Joy] Add Textarea component #33975

Merged
merged 21 commits into from
Aug 24, 2022
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
88 changes: 88 additions & 0 deletions docs/data/joy/components/textarea/ExampleTextareaComment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import * as React from 'react';
import Box from '@mui/joy/Box';
import Button from '@mui/joy/Button';
import FormLabel from '@mui/joy/FormLabel';
import Textarea from '@mui/joy/Textarea';
import IconButton from '@mui/joy/IconButton';
import Menu from '@mui/joy/Menu';
import MenuItem from '@mui/joy/MenuItem';
import ListItemDecorator from '@mui/joy/ListItemDecorator';
import FormatBold from '@mui/icons-material/FormatBold';
import FormatItalic from '@mui/icons-material/FormatItalic';
import KeyboardArrowDown from '@mui/icons-material/KeyboardArrowDown';
import Check from '@mui/icons-material/Check';

export default function TextareaValidator() {
const [italic, setItalic] = React.useState(false);
const [fontWeight, setFontWeight] = React.useState('normal');
const [anchorEl, setAnchorEl] = React.useState(null);
return (
<Box sx={{ p: 2 }}>
<FormLabel>Your comment</FormLabel>
<Textarea
placeholder="Type something here…"
minRows={3}
endDecorator={
<Box
sx={{
display: 'flex',
gap: 'var(--Textarea-paddingBlock)',
pt: 'var(--Textarea-paddingBlock)',
borderTop: '1px solid',
borderColor: 'divider',
flex: 'auto',
}}
>
<IconButton
variant="plain"
color="neutral"
onClick={(event) => setAnchorEl(event.currentTarget)}
>
<FormatBold />
<KeyboardArrowDown fontSize="md" />
</IconButton>
<Menu
anchorEl={anchorEl}
open={Boolean(anchorEl)}
onClose={() => setAnchorEl(null)}
size="sm"
placement="bottom-start"
sx={{ '--List-decorator-size': '24px' }}
>
{['200', 'normal', 'bold'].map((weight) => (
<MenuItem
key={weight}
selected={fontWeight === weight}
onClick={() => {
setFontWeight(weight);
setAnchorEl(null);
}}
sx={{ fontWeight: weight }}
>
<ListItemDecorator>
{fontWeight === weight && <Check fontSize="sm" />}
</ListItemDecorator>
{weight === '200' ? 'lighter' : weight}
</MenuItem>
))}
</Menu>
<IconButton
variant={italic ? 'soft' : 'plain'}
color={italic ? 'primary' : 'neutral'}
aria-pressed={italic}
onClick={() => setItalic((bool) => !bool)}
>
<FormatItalic />
</IconButton>
<Button sx={{ ml: 'auto' }}>Send</Button>
</Box>
}
sx={{
minWidth: 300,
fontWeight,
fontStyle: italic ? 'italic' : 'initial',
}}
/>
</Box>
);
}
42 changes: 42 additions & 0 deletions docs/data/joy/components/textarea/TextareaColors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import * as React from 'react';
import Box from '@mui/joy/Box';
import Textarea from '@mui/joy/Textarea';

export default function TextareaColors() {
return (
<Box
sx={{
py: 2,
display: 'grid',
gap: 2,
alignItems: 'center',
flexWrap: 'wrap',
}}
>
<Textarea
label="Primary"
placeholder="Type in here…"
variant="outlined"
color="primary"
/>
<Textarea
label="Neutral"
placeholder="Type in here…"
variant="outlined"
color="neutral"
/>
<Textarea
label="Danger"
placeholder="Type in here…"
variant="outlined"
color="danger"
/>
<Textarea
label="Warning"
placeholder="Type in here…"
variant="outlined"
color="warning"
/>
</Box>
);
}
38 changes: 38 additions & 0 deletions docs/data/joy/components/textarea/TextareaDecorators.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import * as React from 'react';
import Box from '@mui/joy/Box';
import IconButton from '@mui/joy/IconButton';
import Textarea from '@mui/joy/Textarea';
import Typography from '@mui/joy/Typography';

export default function TextareaDecorators() {
const [text, setText] = React.useState('');
const addEmoji = (emoji) => () => setText(`${text}${emoji}`);
return (
<Textarea
placeholder="Type in here…"
value={text}
onChange={(event) => setText(event.target.value)}
minRows={2}
maxRows={4}
startDecorator={
<Box sx={{ display: 'flex', gap: 0.5 }}>
<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 }}
/>
);
}
33 changes: 33 additions & 0 deletions docs/data/joy/components/textarea/TextareaFormProps.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 Textarea from '@mui/joy/Textarea';

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

export default function TextareaValidator() {
return (
<Box sx={{ p: 2 }}>
<Textarea
placeholder="Type in here…"
defaultValue="Try to put the text more than 4 lines."
minRows={2}
maxRows={4}
/>
</Box>
);
}
13 changes: 13 additions & 0 deletions docs/data/joy/components/textarea/TextareaSizes.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 Textarea from '@mui/joy/Textarea';

export default function TextareaSizes() {
return (
<Box sx={{ display: 'flex', gap: 2, alignItems: 'center', flexWrap: 'wrap' }}>
<Textarea size="sm" label="Size" placeholder="Small" />
<Textarea size="md" label="Size" placeholder="Medium" />
<Textarea size="lg" label="Size" placeholder="Large" />
</Box>
);
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import * as React from 'react';
import JoyUsageDemo from 'docs/src/modules/components/JoyUsageDemo';
import Box from '@mui/joy/Box';
import TextField from '@mui/joy/TextField';
import Textarea from '@mui/joy/Textarea';

export default function TextFieldUsage() {
export default function TextareaUsage() {
return (
<JoyUsageDemo
componentName="TextField"
componentName="Textarea"
data={[
{
propName: 'variant',
Expand All @@ -20,27 +19,23 @@ export default function TextFieldUsage() {
options: ['sm', 'md', 'lg'],
defaultValue: 'md',
},
{
propName: 'label',
knob: 'input',
defaultValue: 'Label',
},
{
propName: 'placeholder',
knob: 'input',
defaultValue: 'placeholder',
defaultValue: 'Type something…',
},
{
propName: 'disabled',
knob: 'switch',
defaultValue: false,
},
{
propName: 'minRows',
defaultValue: 2,
codeBlockDisplay: true,
},
]}
renderDemo={(props) => (
<Box>
<TextField {...props} />
</Box>
)}
renderDemo={(props) => <Textarea {...props} />}
/>
);
}
15 changes: 15 additions & 0 deletions docs/data/joy/components/textarea/TextareaValidation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as React from 'react';
import Box from '@mui/joy/Box';
import Textarea from '@mui/joy/Textarea';

export default function TextareaValidator() {
return (
<Box sx={{ p: 2 }}>
<Textarea
placeholder="Type in here…"
error
defaultValue="Oh no!, something is definitely wrong."
/>
</Box>
);
}
22 changes: 22 additions & 0 deletions docs/data/joy/components/textarea/TextareaVariants.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 Textarea from '@mui/joy/Textarea';

export default function TextareaVariants() {
return (
<Box
sx={{
py: 2,
display: 'grid',
gap: 2,
alignItems: 'center',
flexWrap: 'wrap',
}}
>
<Textarea label="Solid" placeholder="Type in here…" variant="solid" />
<Textarea label="Soft" placeholder="Type in here…" variant="soft" />
<Textarea label="Outlined" placeholder="Type in here…" variant="outlined" />
<Textarea label="Plain" placeholder="Type in here…" variant="plain" />
</Box>
);
}
Loading