-
Notifications
You must be signed in to change notification settings - Fork 2.9k
docs(react-textarea): Update examples to use Field #27644
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
Merged
sopranopillow
merged 5 commits into
microsoft:master
from
sopranopillow:react-textarea-height
Apr 21, 2023
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0d3e556
Adding examples and updating to use Field
sopranopillow 2e93ec6
requested changeS
sopranopillow 508ab27
Merge branch 'master' of https://github.com/microsoft/fluentui into r…
sopranopillow 3830dc2
requested changes:
sopranopillow aeb303a
requested changes
sopranopillow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/react-components/react-textarea/stories/Textarea/TextareaAutoHeight.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import * as React from 'react'; | ||
| import { Field, Textarea, TextareaProps } from '@fluentui/react-components'; | ||
|
|
||
| export const AutoHeight = () => { | ||
| const textareaRef = React.useRef<HTMLTextAreaElement>(null); | ||
|
|
||
| const onChange: TextareaProps['onChange'] = (ev, data) => { | ||
| const textArea = textareaRef.current; | ||
|
|
||
| if (textArea) { | ||
| // We need to clear the height to be able to update the height correctly | ||
| textArea.style.height = ''; | ||
| textArea.style.height = textArea.scrollHeight + 'px'; | ||
| } | ||
|
sopranopillow marked this conversation as resolved.
Outdated
sopranopillow marked this conversation as resolved.
Outdated
|
||
| }; | ||
|
|
||
| return ( | ||
| <Field label="Textarea with auto height adjustment."> | ||
| <Textarea ref={textareaRef} onChange={onChange} /> | ||
| </Field> | ||
| ); | ||
| }; | ||
|
|
||
| AutoHeight.parameters = { | ||
| docs: { | ||
| description: { | ||
| story: | ||
| `To support auto height in a Textarea, we can keep track of the scroll height using refs to update the ` + | ||
| `Textarea's current height.`, | ||
| }, | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 6 additions & 22 deletions
28
packages/react-components/react-textarea/stories/Textarea/TextareaDefault.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,9 @@ | ||
| import * as React from 'react'; | ||
| import { makeStyles, tokens, useId, Label, Textarea } from '@fluentui/react-components'; | ||
| import { Field, Textarea } from '@fluentui/react-components'; | ||
| import type { TextareaProps } from '@fluentui/react-components'; | ||
|
|
||
| const useStyles = makeStyles({ | ||
| base: { | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| '& > label': { | ||
| marginBottom: tokens.spacingVerticalMNudge, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| export const Default = (props: Partial<TextareaProps>) => { | ||
| const textareaId = useId('textarea'); | ||
| const styles = useStyles(); | ||
|
|
||
| return ( | ||
| <div className={styles.base}> | ||
| <Label htmlFor={textareaId}>Default Textarea</Label> | ||
| <Textarea id={textareaId} {...props} /> | ||
| </div> | ||
| ); | ||
| }; | ||
| export const Default = (props: Partial<TextareaProps>) => ( | ||
| <Field label="Default Textarea."> | ||
| <Textarea {...props} /> | ||
| </Field> | ||
| ); |
28 changes: 6 additions & 22 deletions
28
packages/react-components/react-textarea/stories/Textarea/TextareaDisabled.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,8 @@ | ||
| import * as React from 'react'; | ||
| import { makeStyles, tokens, useId, Label, Textarea } from '@fluentui/react-components'; | ||
| import { Field, Textarea } from '@fluentui/react-components'; | ||
|
|
||
| const useStyles = makeStyles({ | ||
| base: { | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| '& > label': { | ||
| marginBottom: tokens.spacingVerticalMNudge, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| export const Disabled = () => { | ||
| const disabledId = useId('textarea-disabled'); | ||
| const styles = useStyles(); | ||
|
|
||
| return ( | ||
| <div className={styles.base}> | ||
| <Label htmlFor={disabledId}>Disabled Textarea.</Label> | ||
| <Textarea id={disabledId} disabled /> | ||
| </div> | ||
| ); | ||
| }; | ||
| export const Disabled = () => ( | ||
| <Field label="Disabled Textarea."> | ||
| <Textarea disabled /> | ||
| </Field> | ||
| ); |
27 changes: 6 additions & 21 deletions
27
packages/react-components/react-textarea/stories/Textarea/TextareaPlaceholder.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,8 @@ | ||
| import * as React from 'react'; | ||
| import { makeStyles, tokens, useId, Label, Textarea } from '@fluentui/react-components'; | ||
| import { Field, Textarea } from '@fluentui/react-components'; | ||
|
|
||
| const useStyles = makeStyles({ | ||
| base: { | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| '& > label': { | ||
| marginBottom: tokens.spacingVerticalMNudge, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| export const Placeholder = () => { | ||
| const styles = useStyles(); | ||
| const textareaId = useId('textarea'); | ||
| return ( | ||
| <div className={styles.base}> | ||
| <Label htmlFor={textareaId}>Textarea with placeholder.</Label> | ||
| <Textarea id={textareaId} placeholder="type here..." /> | ||
| </div> | ||
| ); | ||
| }; | ||
| export const Placeholder = () => ( | ||
| <Field label="Textarea with placeholder."> | ||
| <Textarea placeholder="type here..." /> | ||
| </Field> | ||
| ); |
52 changes: 13 additions & 39 deletions
52
packages/react-components/react-textarea/stories/Textarea/TextareaResize.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,60 +1,34 @@ | ||
| import * as React from 'react'; | ||
| import { makeStyles, shorthands, tokens, useId, Label, Textarea } from '@fluentui/react-components'; | ||
| import { Field, makeStyles, Textarea, tokens } from '@fluentui/react-components'; | ||
|
|
||
| const useStyles = makeStyles({ | ||
| base: { | ||
| '& > div': { | ||
| marginTop: tokens.spacingVerticalMNudge, | ||
| }, | ||
|
sopranopillow marked this conversation as resolved.
Outdated
|
||
| '& > div > div': { | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| ...shorthands.borderRadius(tokens.borderRadiusMedium), | ||
| ...shorthands.padding(tokens.spacingHorizontalMNudge), | ||
| }, | ||
| '& > div > label': { | ||
| marginBottom: tokens.spacingHorizontalXXS, | ||
| marginLeft: tokens.spacingHorizontalMNudge, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| export const Resize = () => { | ||
| const noneId = useId('textarea-none'); | ||
| const verticalId = useId('textarea-vertical'); | ||
| const horizontalId = useId('textarea-horizontal'); | ||
| const bothId = useId('textarea-both'); | ||
| const styles = useStyles(); | ||
|
|
||
| return ( | ||
| <div className={styles.base}> | ||
| <div> | ||
| <Label htmlFor={noneId}>Textarea with resize set to "none".</Label> | ||
| <div> | ||
| <Textarea id={noneId} resize="none" /> | ||
| </div> | ||
| </div> | ||
| <Field label='Textarea with resize set to "none".'> | ||
| <Textarea resize="none" /> | ||
| </Field> | ||
|
|
||
| <div> | ||
| <Label htmlFor={verticalId}>Textarea with resize set to "vertical".</Label> | ||
| <div> | ||
| <Textarea id={verticalId} resize="vertical" /> | ||
| </div> | ||
| </div> | ||
| <Field label='Textarea with resize set to "vertical".'> | ||
| <Textarea resize="vertical" /> | ||
| </Field> | ||
|
|
||
| <div> | ||
| <Label htmlFor={horizontalId}>Textarea with resize set to "horizontal".</Label> | ||
| <div> | ||
| <Textarea id={horizontalId} resize="horizontal" /> | ||
| </div> | ||
| </div> | ||
| <Field label='Textarea with resize set to "horizontal".'> | ||
| <Textarea resize="horizontal" /> | ||
| </Field> | ||
|
|
||
| <div> | ||
| <Label htmlFor={bothId}>Textarea with resize set to "both".</Label> | ||
| <div> | ||
| <Textarea id={bothId} resize="both" /> | ||
| </div> | ||
| </div> | ||
| <Field label='Textarea with resize set to "both".'> | ||
| <Textarea resize="both" /> | ||
| </Field> | ||
| </div> | ||
| ); | ||
| }; | ||
42 changes: 10 additions & 32 deletions
42
packages/react-components/react-textarea/stories/Textarea/TextareaSize.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,52 +1,30 @@ | ||
| import * as React from 'react'; | ||
| import { makeStyles, shorthands, tokens, useId, Label, Textarea } from '@fluentui/react-components'; | ||
| import { Field, makeStyles, Textarea, tokens } from '@fluentui/react-components'; | ||
|
|
||
| const useStyles = makeStyles({ | ||
| base: { | ||
| '& > div': { | ||
| marginTop: tokens.spacingVerticalMNudge, | ||
| }, | ||
|
sopranopillow marked this conversation as resolved.
Outdated
|
||
| '& > div > div': { | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| ...shorthands.borderRadius(tokens.borderRadiusMedium), | ||
| ...shorthands.padding(tokens.spacingHorizontalMNudge), | ||
| }, | ||
| '& > div > label': { | ||
| marginBottom: tokens.spacingHorizontalXXS, | ||
| marginLeft: tokens.spacingHorizontalMNudge, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| export const Size = () => { | ||
| const smallId = useId('textarea-small'); | ||
| const mediumId = useId('textarea-medium'); | ||
| const largeId = useId('textarea-large'); | ||
| const styles = useStyles(); | ||
|
|
||
| return ( | ||
| <div className={styles.base}> | ||
| <div> | ||
| <Label htmlFor={smallId}>Small Textarea.</Label> | ||
| <div> | ||
| <Textarea id={smallId} size="small" /> | ||
| </div> | ||
| </div> | ||
| <Field size="small" label="Small Textarea."> | ||
| <Textarea /> | ||
| </Field> | ||
|
|
||
| <div> | ||
| <Label htmlFor={mediumId}>Medium Textarea.</Label> | ||
| <div> | ||
| <Textarea id={mediumId} size="medium" /> | ||
| </div> | ||
| </div> | ||
| <Field size="medium" label="Medium Textarea."> | ||
| <Textarea /> | ||
| </Field> | ||
|
|
||
| <div> | ||
| <Label htmlFor={largeId}>Large Textarea.</Label> | ||
| <div> | ||
| <Textarea id={largeId} size="large" /> | ||
| </div> | ||
| </div> | ||
| <Field size="large" label="Large Textarea."> | ||
| <Textarea /> | ||
| </Field> | ||
| </div> | ||
| ); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.