|
| 1 | +import { Meta, Story, Canvas, ArgsTable, Description } from '@storybook/addon-docs' |
| 2 | + |
| 3 | +import { Stack } from '../stack' |
| 4 | +import { Text } from '../text' |
| 5 | +import { PasswordField } from './' |
| 6 | + |
| 7 | +import { selectWithNone } from '../utils/storybook-helper' |
| 8 | + |
| 9 | +<Meta |
| 10 | + title="Design system/PasswordField" |
| 11 | + component={PasswordField} |
| 12 | + parameters={{ |
| 13 | + badges: ['accessible'], |
| 14 | + }} |
| 15 | +/> |
| 16 | + |
| 17 | +# PasswordField |
| 18 | + |
| 19 | +A component used to accept password input from the user. |
| 20 | + |
| 21 | +export function preventDefault(event) { |
| 22 | + event.preventDefault() |
| 23 | +} |
| 24 | + |
| 25 | +export function InteractivePropsStory({ label, auxiliaryLabel, ...props }) { |
| 26 | + return ( |
| 27 | + <PasswordField |
| 28 | + {...props} |
| 29 | + label={label} |
| 30 | + auxiliaryLabel={ |
| 31 | + auxiliaryLabel ? ( |
| 32 | + <a href="#" onClick={preventDefault}> |
| 33 | + {auxiliaryLabel} |
| 34 | + </a> |
| 35 | + ) : undefined |
| 36 | + } |
| 37 | + /> |
| 38 | + ) |
| 39 | +} |
| 40 | + |
| 41 | +<Canvas> |
| 42 | + <Story |
| 43 | + name="Interactive props" |
| 44 | + parameters={{ |
| 45 | + chromatic: { disableSnapshot: false }, |
| 46 | + }} |
| 47 | + argTypes={{ |
| 48 | + label: { |
| 49 | + control: { type: 'text' }, |
| 50 | + defaultValue: 'Password', |
| 51 | + }, |
| 52 | + secondaryLabel: { |
| 53 | + control: { type: 'text' }, |
| 54 | + defaultValue: 'optional', |
| 55 | + }, |
| 56 | + auxiliaryLabel: { |
| 57 | + control: { type: 'text' }, |
| 58 | + defaultValue: 'Forgot your password?', |
| 59 | + }, |
| 60 | + hint: { |
| 61 | + control: { type: 'text' }, |
| 62 | + defaultValue: |
| 63 | + 'Must be at least 100 characters long, and it should include each letter of the alphabet', |
| 64 | + }, |
| 65 | + message: { |
| 66 | + control: { type: 'text' }, |
| 67 | + defaultValue: '', |
| 68 | + }, |
| 69 | + tone: { |
| 70 | + options: ['neutral', 'success', 'error', 'loading'], |
| 71 | + control: { type: 'inline-radio' }, |
| 72 | + defaultValue: 'neutral', |
| 73 | + }, |
| 74 | + variant: { |
| 75 | + options: ['default', 'bordered'], |
| 76 | + control: { type: 'inline-radio' }, |
| 77 | + defaultValue: 'default', |
| 78 | + }, |
| 79 | + placeholder: { |
| 80 | + control: { type: 'text' }, |
| 81 | + defaultValue: 'Type your password', |
| 82 | + }, |
| 83 | + maxWidth: selectWithNone(['xsmall', 'small', 'medium', 'large', 'xlarge'], 'small'), |
| 84 | + }} |
| 85 | + > |
| 86 | + {InteractivePropsStory.bind({})} |
| 87 | + </Story> |
| 88 | +</Canvas> |
| 89 | + |
| 90 | +<ArgsTable of={PasswordField} /> |
| 91 | + |
| 92 | +## Colors |
| 93 | + |
| 94 | +The following CSS custom properties are available so that the `PasswordField`'s border colors can be customized. |
| 95 | +Note that these variables are shared with other components such as `Textfield`, `SelectField`, and `TextArea`. |
| 96 | + |
| 97 | +``` |
| 98 | +--reactist-inputs-focus |
| 99 | +--reactist-inputs-idle |
| 100 | +``` |
| 101 | + |
| 102 | +<Canvas withToolbar> |
| 103 | + <Story |
| 104 | + name="Message tone" |
| 105 | + parameters={{ |
| 106 | + chromatic: { disableSnapshot: false }, |
| 107 | + }} |
| 108 | + > |
| 109 | + <Stack space="xxlarge" dividers="secondary"> |
| 110 | + <PasswordField |
| 111 | + label="Password confirmation" |
| 112 | + message="Comparing to original password…" |
| 113 | + tone="loading" |
| 114 | + disabled |
| 115 | + maxWidth="small" |
| 116 | + /> |
| 117 | + <PasswordField |
| 118 | + label="Password confirmation" |
| 119 | + message="It does not match the original password" |
| 120 | + tone="error" |
| 121 | + maxWidth="small" |
| 122 | + /> |
| 123 | + <PasswordField |
| 124 | + label="Password confirmation" |
| 125 | + message="Matches original password!" |
| 126 | + tone="success" |
| 127 | + maxWidth="small" |
| 128 | + /> |
| 129 | + <PasswordField |
| 130 | + label="Password confirmation" |
| 131 | + message="Message with neutral tone (used as description, but still prefer the hint prop for that)" |
| 132 | + hint="This is the primary description of the field, provided by the hint prop" |
| 133 | + tone="neutral" |
| 134 | + maxWidth="small" |
| 135 | + /> |
| 136 | + </Stack> |
| 137 | + </Story> |
| 138 | +</Canvas> |
| 139 | + |
| 140 | +<Canvas withToolbar> |
| 141 | + <Story name="Without label"> |
| 142 | + <Stack space="xlarge" dividers="secondary" maxWidth="small"> |
| 143 | + <Stack as="label" htmlFor="custom-textarea" space="small"> |
| 144 | + <Text size="subtitle">Custom label is up here</Text> |
| 145 | + <Text size="caption" tone="secondary" aria-hidden> |
| 146 | + <em>(click me to focus the textarea)</em> |
| 147 | + </Text> |
| 148 | + </Stack> |
| 149 | + <PasswordField |
| 150 | + label={null} |
| 151 | + id="custom-textarea" |
| 152 | + aria-describedby="custom-description" |
| 153 | + placeholder="Password field without a built-in label" |
| 154 | + /> |
| 155 | + <Stack space="small" id="custom-description"> |
| 156 | + <Text size="body">Custom description is down here</Text> |
| 157 | + <Text size="caption" tone="secondary" aria-hidden> |
| 158 | + <em>(inspect the input element accessibility properties if you are curious)</em> |
| 159 | + </Text> |
| 160 | + </Stack> |
| 161 | + </Stack> |
| 162 | + </Story> |
| 163 | +</Canvas> |
0 commit comments