@fluentui/react-input 0.0.0-nightlyca6ef2bc8e20220105.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/CHANGELOG.json +1044 -0
  2. package/CHANGELOG.md +429 -0
  3. package/LICENSE +15 -0
  4. package/README.md +5 -0
  5. package/Spec-styling.md +125 -0
  6. package/Spec-variants.md +99 -0
  7. package/Spec.md +262 -0
  8. package/dist/react-input.d.ts +123 -0
  9. package/lib/Input.d.ts +1 -0
  10. package/lib/Input.js +2 -0
  11. package/lib/Input.js.map +1 -0
  12. package/lib/components/Input/Input.d.ts +8 -0
  13. package/lib/components/Input/Input.js +17 -0
  14. package/lib/components/Input/Input.js.map +1 -0
  15. package/lib/components/Input/Input.types.d.ts +84 -0
  16. package/lib/components/Input/Input.types.js +2 -0
  17. package/lib/components/Input/Input.types.js.map +1 -0
  18. package/lib/components/Input/index.d.ts +5 -0
  19. package/lib/components/Input/index.js +6 -0
  20. package/lib/components/Input/index.js.map +1 -0
  21. package/lib/components/Input/renderInput.d.ts +5 -0
  22. package/lib/components/Input/renderInput.js +18 -0
  23. package/lib/components/Input/renderInput.js.map +1 -0
  24. package/lib/components/Input/useInput.d.ts +12 -0
  25. package/lib/components/Input/useInput.js +64 -0
  26. package/lib/components/Input/useInput.js.map +1 -0
  27. package/lib/components/Input/useInputStyles.d.ts +6 -0
  28. package/lib/components/Input/useInputStyles.js +296 -0
  29. package/lib/components/Input/useInputStyles.js.map +1 -0
  30. package/lib/index.d.ts +1 -0
  31. package/lib/index.js +2 -0
  32. package/lib/index.js.map +1 -0
  33. package/lib/tsdoc-metadata.json +11 -0
  34. package/lib-commonjs/Input.d.ts +1 -0
  35. package/lib-commonjs/Input.js +10 -0
  36. package/lib-commonjs/Input.js.map +1 -0
  37. package/lib-commonjs/components/Input/Input.d.ts +8 -0
  38. package/lib-commonjs/components/Input/Input.js +28 -0
  39. package/lib-commonjs/components/Input/Input.js.map +1 -0
  40. package/lib-commonjs/components/Input/Input.types.d.ts +84 -0
  41. package/lib-commonjs/components/Input/Input.types.js +6 -0
  42. package/lib-commonjs/components/Input/Input.types.js.map +1 -0
  43. package/lib-commonjs/components/Input/index.d.ts +5 -0
  44. package/lib-commonjs/components/Input/index.js +18 -0
  45. package/lib-commonjs/components/Input/index.js.map +1 -0
  46. package/lib-commonjs/components/Input/renderInput.d.ts +5 -0
  47. package/lib-commonjs/components/Input/renderInput.js +29 -0
  48. package/lib-commonjs/components/Input/renderInput.js.map +1 -0
  49. package/lib-commonjs/components/Input/useInput.d.ts +12 -0
  50. package/lib-commonjs/components/Input/useInput.js +74 -0
  51. package/lib-commonjs/components/Input/useInput.js.map +1 -0
  52. package/lib-commonjs/components/Input/useInputStyles.d.ts +6 -0
  53. package/lib-commonjs/components/Input/useInputStyles.js +306 -0
  54. package/lib-commonjs/components/Input/useInputStyles.js.map +1 -0
  55. package/lib-commonjs/index.d.ts +1 -0
  56. package/lib-commonjs/index.js +10 -0
  57. package/lib-commonjs/index.js.map +1 -0
  58. package/package.json +65 -0
@@ -0,0 +1,99 @@
1
+ # Input Variants
2
+
3
+ Input has many variants and additional features. We don't plan to implement any of these immediately, but adding notes here for future reference.
4
+
5
+ ## Bookends
6
+
7
+ "Bookends" (the naming comes from the design spec) are bits of text on the left or right outside of the field, surrounded by a border or background color.
8
+
9
+ Initially, bookends were planned to be included in the main component (as `bookendBefore`/`bookendAfter` slots) but we decided they're not essential and should be split out to simplify the DOM structure and defer some of the related open questions until later.
10
+
11
+ If/when a partner needs this feature, it will likely go in some kind of wrapper component.
12
+
13
+ Visual variants for the bookends are as follows (note that specific colors are just examples based on the default theme):
14
+
15
+ - `filled` (default): bookends have a gray background, black text, and no border
16
+ - `brand`: bookends have a brand color (such as blue or purple) background, white text, and no border
17
+ - `transparent`: bookends have a transparent background, black text, and only a thin inside border to distinguish them from the field
18
+
19
+ ## Multi-line (`textarea`)
20
+
21
+ This will tentatively be a separate component, likely sharing some internals with the basic `Input` using hooks (scheduling TBD).
22
+
23
+ | Prop/concept | v8 | v0 | Proposal |
24
+ | ------------------ | ---------------------------- | --- | -------------------------------------------------------- |
25
+ | resizable | `resizable?: boolean` | | via native props |
26
+ | auto-adjust height | `autoAdjustHeight?: boolean` | | TBD (common request but has nasty implementation issues) |
27
+
28
+ Similar to both v8 and v0, passing other `textarea` native props as top-level component props will be supported.
29
+
30
+ ### Possibility: `useTextInput`
31
+
32
+ We might want to make a hook and some types to share props and behavior between `Input` and the potential future `TextArea` (which would depend on `react-input` but with some different props and behaviors).
33
+
34
+ ```ts
35
+ type TextInputSlots<
36
+ TInput extends HTMLInputElement | HTMLTextAreaElement,
37
+ TInputAttributes = TInput extends HTMLInputElement
38
+ ? React.InputHTMLAttributes<TInput>
39
+ : React.TextAreaHTMLAttributes<TInput>
40
+ > = {
41
+ root: ObjectShorthandProps<React.HTMLAttributes<HTMLElement>, HTMLElement>;
42
+ input: ObjectShorthandProps<TInputAttributes, TInput>;
43
+ };
44
+ ```
45
+
46
+ ## Validation
47
+
48
+ Validation features and error messages will not be built into the new `Input`. Possible approaches:
49
+
50
+ - Hooks and/or a `Field` component to provide visual consistency and proper accessibility behavior across different types of inputs.
51
+ - A `Form` component for more complex scenarios involving validation across multiple fields.
52
+
53
+ ### In v8
54
+
55
+ ```ts
56
+ // relevant props only
57
+ interface ITextFieldProps {
58
+ // static error message
59
+ errorMessage?: string | JSX.Element;
60
+ // called to determine whether input is valid and show error if not
61
+ // (on all changes by default; modified by validateOnFocusIn/Out)
62
+ onGetErrorMessage?: (value: string) => string | JSX.Element | PromiseLike<string | JSX.Element> | undefined;
63
+ // whether to validate when focus moves into input (NOT on change)
64
+ validateOnFocusIn?: boolean;
65
+ // whether to validate when focus moves out of input (NOT on change)
66
+ validateOnFocusOut?: boolean;
67
+ // whether to validate when input is initially rendered
68
+ validiateOnLoad?: boolean;
69
+ // wait to validate until user stops typing by this ms
70
+ deferredValidationTime?: number;
71
+ // called after validation completes
72
+ onNotifyValidationResult?: (errorMessage: string | JSX.Element, value: string | undefined) => void;
73
+ // ...
74
+ }
75
+ ```
76
+
77
+ ### In v0
78
+
79
+ TBD
80
+
81
+ ## Password
82
+
83
+ v8 supports a password field with a custom reveal password button:
84
+
85
+ ```tsx
86
+ <TextField type="password" canRevealPassword revealPasswordAriaLabel="Show password" />
87
+ ```
88
+
89
+ v0 does not appear to have a similar feature.
90
+
91
+ TBD if/how we want to handle this in converged.
92
+
93
+ ## Masking
94
+
95
+ "Masking" refers to a text input with some pre-specified format that gets filled in as the user types, like `(___) ___-____`.
96
+
97
+ In v8 it's handled by `MaskedTextField`.
98
+
99
+ Masking is tricky to implement properly and bad for accessibility, so we don't plan to implement it in converged unless there's a compelling product requirement. At that point we'll also evaluate whether there are any suitable 3rd-party libraries which could handle it.
package/Spec.md ADDED
@@ -0,0 +1,262 @@
1
+ # @fluentui/react-input Spec
2
+
3
+ **Epic issue** - [Input Convergence](https://github.com/microsoft/fluentui/issues/18131)
4
+
5
+ ## Background
6
+
7
+ `Input` in its most basic form is a text input field abstracting `<input type="text" />`.
8
+
9
+ It can also be used to render other text-based input types, such as `password` or `email`, but **is not intended for non-text input types** such as `checkbox` (those are handled in separate components).
10
+
11
+ In some libraries, the equivalent component also abstracts a `textarea` (multi-line text input) and may have features such as a label and start/end slots built in.
12
+
13
+ ## Prior Art
14
+
15
+ ### In other frameworks
16
+
17
+ | Framework | `<input type="text">` | `<textarea>` | Notes |
18
+ | -------------------------------- | ----------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------- |
19
+ | Ant Design | [`Input`](https://ant.design/components/input/) | `Input.TextArea` | No label. Has both inner and outer prefix/suffix. |
20
+ | AtlasKit | [`Textfield`](https://atlassian.design/components/textfield) | [`Textarea`](https://atlassian.design/components/textarea) | No label |
21
+ | Carbon | [`TextInput`](https://www.carbondesignsystem.com/components/text-input/usage/) | `TextArea` | Has label prop |
22
+ | Evergreen | [`TextInput`](https://evergreen.segment.com/components/text-input) | [`Textarea`](https://evergreen.segment.com/components/textarea) | `TextInputField` and `TextareaField` wrappers provide label etc |
23
+ | Lightning | [`input`](https://www.lightningdesignsystem.com/components/input/) | [`textarea`](https://www.lightningdesignsystem.com/components/textarea/) | Not a React library |
24
+ | Material UI React | [`Input`](https://material-ui.com/components/text-fields/) | built in to `TextField` | `TextField` is a rollup of functionality: label, appearances, start/end slots, lots of variants |
25
+ | `@fluentui/react` (v8) | [`TextField`](https://developer.microsoft.com/en-us/fluentui#/controls/web/textfield) | built in to `TextField` | Has label prop |
26
+ | `@fluentui/react-northstar` (v0) | [`Input`](https://fluentsite.z22.web.core.windows.net/0.57.0/components/input/definition) | [`TextArea`](https://fluentsite.z22.web.core.windows.net/0.57.0/components/text-area/definition) | Has label prop |
27
+
28
+ ### Comparison of v8 and v0
29
+
30
+ Please see the [migration guide](#migration-guide) section.
31
+
32
+ ## Sample Code
33
+
34
+ See [Structure section](#structure) for the output HTML.
35
+
36
+ ```tsx
37
+ <Label htmlFor="input1">Label</Label> // note that the label is not built in
38
+ <Input
39
+ className="rootClass"
40
+ input={{ className: 'inputClass' }}
41
+ id="input1"
42
+ value="something"
43
+ onChange={(ev, data) => console.log(data.value)}
44
+ contentBefore={<SearchIcon />}
45
+ contentAfter={<ClearIcon />}
46
+ />
47
+ ```
48
+
49
+ ## Variants
50
+
51
+ ### Visual variants
52
+
53
+ Visual variants are as follows:
54
+
55
+ - `outline` (default): the field has a full outline, with a slightly darker underline on the bottom
56
+ - `underline`: the field has an underline on the bottom only
57
+ - `filledDarker`: the field has a gray background and no underline/outline
58
+ - `filledLighter`: the field has a white background and no underline/outline (for use on top of gray/colored backgrounds)
59
+
60
+ See the design spec for details on each of these. (Note that the actual colors used will follow the theme; white/gray are just examples from the default theme.)
61
+
62
+ ### Behavior variants
63
+
64
+ In the future we may implement behavior variants, such as a password field with reveal button, but that will be spec'd if/when we need it. See [Spec-variants.md](./Spec-variants.md) for more details.
65
+
66
+ ## API
67
+
68
+ In this component, `input` is the primary slot. See notes under [Structure](#structure).
69
+
70
+ ### Main props
71
+
72
+ All native HTML `<input>` props are supported. Since the `input` slot is primary (more on that later), top-level native props except `className` and `style` will go to the input.
73
+
74
+ The top-level `ref` prop also points to the `<input>`. This can be used for things like getting the current value or manipulating focus or selection (instead of explicitly exposing an imperative API).
75
+
76
+ For the full current props, see the types file:
77
+ https://github.com/microsoft/fluentui/blob/master/packages/react-input/src/components/Input/Input.types.ts
78
+
79
+ ```ts
80
+ // Simplified version of the props (including only summaries of custom props)
81
+ type SimplifiedInputProps = {
82
+ /** Toggle inline display instead of block */
83
+ inline?: boolean;
84
+
85
+ /** Controls the colors and borders of the field (default `outline`) */
86
+ appearance?: 'outline' | 'underline' | 'filledDarker' | 'filledLighter';
87
+
88
+ /** Size of the input (default `medium`) */
89
+ size?: 'small' | 'medium' | 'large';
90
+
91
+ /** Default value (uncontrolled) */
92
+ defaultValue?: string;
93
+
94
+ /** Controlled value */
95
+ value?: string;
96
+
97
+ /** Called when the user changes the value */
98
+ onChange?: (ev: React.FormEvent<HTMLInputElement>, data: { value: string }) => void;
99
+
100
+ /** Allowed values for the native `type` prop */
101
+ type?: 'text' | '...'; // this is an enumeration of all text-like values
102
+ };
103
+ ```
104
+
105
+ Notes on native prop conflicts/overrides:
106
+
107
+ - `size` [overlaps with a native prop](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/size) which sets the width of the field in "number of characters." This isn't ideal, but we're going with it since the native prop isn't very useful in practice, and it was hard to find another reasonable/consistent name for the visual size prop. It's also consistent with the approach used by most other libraries which have a prop for setting the visual size. (If anyone needs the native functionality, we could add an `htmlSize` prop in the future.)
108
+ - `value` and `defaultValue` are defined in `InputHTMLAttributes` (from `@types/react`) as `string | ReadonlyArray<string> | number` since the same props interface is used for all input element types. To reflect actual usage, we override the types to only accept strings.
109
+ - `onChange` is overridden per the [RFC on event handler arguments](https://github.com/microsoft/fluentui/blob/master/rfcs/convergence/event-handlers-arguments.md).
110
+ - `type` is defined in `@types/react` as `string`, but for `Input`, I'm restricting it to a list of only the text-like values [listed on MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input#input_types). Making this explicit should help avoid people thinking that Input can handle all the same behaviors as a native `<input>`.
111
+
112
+ ### Slots
113
+
114
+ Note that the field **does not** include a label, required indicator, description, or error message.
115
+
116
+ An overview of the slots is as follows. For the current slot types and full docs, see the types file:
117
+ https://github.com/microsoft/fluentui/blob/master/packages/react-input/src/components/Input/Input.types.ts
118
+
119
+ - `root` (`span`): Wrapper which visually appears to be the input (needed to position `contentBefore` and `contentAfter` relative to the actual `input`)
120
+ - `input` (`input`, primary slot): The actual text input element
121
+ - `contentBefore` (`span`): Element before the input text, within the input border (most often used for icons)
122
+ - `contentAfter` (`span`): Element after the input text, within the input border (most often used for icons)
123
+
124
+ ## Structure
125
+
126
+ In this component, `input` is the primary slot. Per the [native element props/primary slot RFC](https://github.com/microsoft/fluentui/blob/master/rfcs/convergence/native-element-props.md), this means that most top-level props will go to `input`, but the top-level `className` and `style` will go to the actual root element.
127
+
128
+ ```tsx
129
+ // Out of top-level native props, only `className` and `style` go here
130
+ <slots.root {...slotProps.root}>
131
+ <slots.contentBefore {...slotProps.contentBefore} />
132
+ {/* Primary slot. Top-level native props except `className` and `style` go here. */}
133
+ <slots.input {...slotProps.input} />
134
+ <slots.contentAfter {...slotProps.contentAfter} />
135
+ </slots.root>
136
+ ```
137
+
138
+ Notes on the HTML rendering:
139
+
140
+ - Using `span` rather than `div` prevents nesting errors if the Input is rendered inline within a `<p>`.
141
+ - The root is visually styled as the input (with borders etc) and the `contentBefore`, `contentAfter`, and actual `input` elements are positioned inside it.
142
+
143
+ This example usage:
144
+
145
+ ```tsx
146
+ <Input
147
+ className="rootClass"
148
+ style={{ background: 'red' }}
149
+ input={{ className: 'inputClass', style: { background: 'blue' } }}
150
+ id="input1"
151
+ value="something"
152
+ onChange={(ev, data) => console.log(data.value)}
153
+ contentBefore={<SearchIcon />}
154
+ contentAfter={<ClearIcon />}
155
+ />
156
+ ```
157
+
158
+ Gives this HTML:
159
+
160
+ ```html
161
+ <span className="rootClass" style="background: red">
162
+ <span><!-- contentBefore here --></span>
163
+ <!-- input: type="text" is applied automatically -->
164
+ <input
165
+ type="text"
166
+ className="inputClass"
167
+ style="background: blue"
168
+ id="input1"
169
+ value="something"
170
+ onChange="(function)"
171
+ />
172
+ <span><!-- contentAfter here --></span>
173
+ </span>
174
+ ```
175
+
176
+ ## Behaviors
177
+
178
+ Most of the behavior is inherited from the native `<input>` element, and all we add is styling.
179
+
180
+ The component has the following interactive states:
181
+
182
+ - Rest
183
+ - Hover: change stroke color
184
+ - Pressed: apply focus border style as animation
185
+ - Focused: currently indicated by a thick brand color stroke on the bottom border only (regardless of whether focus was by keyboard or mouse)
186
+
187
+ Keyboard, cursor, touch, and screen reader interaction will be handled automatically by the internal `<input>`.
188
+
189
+ ## Accessibility
190
+
191
+ - Most interaction and screen reader behavior will be handled automatically by the internal `<input type="text">`.
192
+ - The `<input>` is visible and shows the placeholder or value text.
193
+ - The component doesn't provide a built-in label, so it's important for the user to pass in appropriate attributes such as `id` (associated with a label using `htmlFor`), `aria-label`, or `aria-labelledby`.
194
+ - No features in the initial implementation require manipulation of focus, tab order, or key handling.
195
+ - Visual states for focus and hover will be applied to `root` rather than the `<input>` itself (which is rendered without a border and only used to show the text), because the `contentBefore` and `contentAfter` slots need to visually appear to be within the input.
196
+
197
+ ## Migration
198
+
199
+ > **NOTE**: Props related to multiline, reveal password, validation, and masking are not yet supported and likely to be handled in separate components. See [Spec-variants.md](./Spec-variants.md) for more details.
200
+
201
+ ### Props
202
+
203
+ | Prop/concept | v8 | v0 | Proposal |
204
+ | ---------------------------- | ----------------------------------------------------- | ----------------------------------------------------------- | --------------------------------------- |
205
+ | imperative API | `componentRef` | n/a | n/a |
206
+ | supported native props | `React.AllHTMLAttributes` (input or textarea) | `SupportedIntrinsicInputProps` (see below) | `React.InputHTMLAttributes` |
207
+ | setting native props on root | | ? | `root` slot (mostly, see below) |
208
+ | root element access | `elementRef` | ? | `ref` on `root` slot |
209
+ | primary element access | not possible | `ref` | top-level `ref` |
210
+ | multiline mode | `multiline?: boolean` | separate component (`TextArea`) | separate component |
211
+ | underlined | `underlined?: boolean` | | `appearance` |
212
+ | borderless | `borderless?: boolean` | | not supported? |
213
+ | fluid (full width) | default behavior | `fluid?: boolean` | default behavior |
214
+ | inline | n/a (use styling) | `inline?: boolean` | `inline?: boolean` |
215
+ | label | `label?: string`, `onRenderLabel` | `label?: ShorthandValue<InputLabelProps>`, | handled by Field |
216
+ | label position | n/a (use styling) | `labelPosition?: 'above' \| 'inline' \| 'inside'` | handled by Field |
217
+ | description | `description?: string`, `onRenderDescription` | use FormField | handled by Field |
218
+ | error message | see [Spec-variants.md](./Spec-variants.md#validation) | use FormField | handled by Field |
219
+ | content outside before field | `prefix?: string`, `onRenderPrefix` | n/a | TBD (deferred) |
220
+ | content outside after field | `suffix?: string`, `onRenderSuffix` | n/a | TBD (deferred) |
221
+ | icon at start of field | n/a | `icon?: ShorthandValue<BoxProps>` + `iconPosition: 'start'` | `contentBefore` slot |
222
+ | icon at end of field | `iconProps?: IIconProps` | `icon?: ShorthandValue<BoxProps>` + `iconPosition: 'end'` | `contentAfter` slot |
223
+ | value | `value?: string` | `value?: string \| number` | `value?: string` |
224
+ | defaultValue | `defaultValue?: string` | `defaultValue?: string \| string[]` | `defaultValue?: string` |
225
+ | onChange | `(ev, value) => void` | `(ev, data: { ...props, value }) => void` | `(ev, data: { value: string }) => void` |
226
+ | container className | `className?: string` | | top-level `className` |
227
+ | input className | `inputClassName?: string` | `input.className?: ` | |
228
+ | aria label | `ariaLabel?: string` | `'aria-label'?: string` | `'aria-label'?: string` |
229
+ | clearable | n/a | `clearable?: boolean` | TBD (deferred) |
230
+ | theme | `theme?: ITheme` | | handled by context |
231
+ | style overrides | `styles?: IStyleFunctionOrObject<...>` | `styles?: ComponentSlotStyles<...>` | className, slot classNames |
232
+ | accessibility | individual props | `Accessibility<InputBehaviorProps>` (see below) | individual props? |
233
+
234
+ ```ts
235
+ // packages/fluentui/react-northstar/src/utils/htmlPropsUtils.tsx
236
+ type SupportedIntrinsicInputProps = {
237
+ [K in HtmlInputProps]?: K extends keyof JSX.IntrinsicElements['input'] ? JSX.IntrinsicElements['input'][K] : any;
238
+ };
239
+ // HtmlInputProps: a subset of React and HTML native props
240
+
241
+ // packages/fluentui/react-northstar/src/components/Box/Box.tsx
242
+ interface BoxProps extends UIComponentProps<BoxProps>, ContentComponentProps, ChildrenComponentProps {
243
+ /** Accessibility behavior if overridden by the user. */
244
+ accessibility?: Accessibility<never>;
245
+ }
246
+
247
+ // packages/fluentui/accessibility/src/behaviors/Input/inputBehavior.ts
248
+ type InputBehaviorProps = { disabled?: boolean; required?: boolean; error?: boolean };
249
+ ```
250
+
251
+ Native props following standard behavior in both libraries + converged:
252
+
253
+ - `disabled?: boolean`
254
+ - `readOnly?: boolean`
255
+ - `autoComplete?: string`
256
+ - and most other native props not specified
257
+
258
+ ### Imperative API
259
+
260
+ In v8 there's an explicit imperative API, which is accessed via `componentRef` following the [`ITextField` interface](https://github.com/microsoft/fluentui/blob/master/packages/react/src/components/TextField/TextField.types.ts#L9). The methods are used for getting the value and manipulating focus and selection.
261
+
262
+ In v0 (and in converged), all these things can be done by calling methods on the `<input>` element itself, exposed via the top-level `ref`.
@@ -0,0 +1,123 @@
1
+ import type { ComponentProps } from '@fluentui/react-utilities';
2
+ import type { ComponentState } from '@fluentui/react-utilities';
3
+ import type { ForwardRefComponent } from '@fluentui/react-utilities';
4
+ import type { IntrinsicShorthandProps } from '@fluentui/react-utilities';
5
+ import * as React_2 from 'react';
6
+
7
+ /**
8
+ * The Input component allows people to enter and edit text.
9
+ *
10
+ * ⚠️ **This component is still in alpha (unstable) status. APIs may change before the final release.**
11
+ */
12
+ export declare const Input: ForwardRefComponent<InputProps>;
13
+
14
+ export declare const inputClassName = "fui-Input";
15
+
16
+ /**
17
+ * Data passed to the `onChange` callback when a user changes the input's value.
18
+ */
19
+ export declare type InputOnChangeData = {
20
+ /** Updated input value from the user */
21
+ value: string;
22
+ };
23
+
24
+ export declare type InputProps = Omit<ComponentProps<InputSlots, 'input'>, 'children' | 'defaultValue' | 'onChange' | 'size' | 'type' | 'value'> & {
25
+ /** Input can't have children. */
26
+ children?: never;
27
+ /**
28
+ * Size of the input (changes the font size and spacing).
29
+ * @default 'medium'
30
+ */
31
+ size?: 'small' | 'medium' | 'large';
32
+ /**
33
+ * If true, the input will have inline display, allowing it be used within text content.
34
+ * If false (the default), the input will have block display.
35
+ */
36
+ inline?: boolean;
37
+ /**
38
+ * Controls the colors and borders of the input.
39
+ * @default 'outline'
40
+ */
41
+ appearance?: 'outline' | 'underline' | 'filledDarker' | 'filledLighter';
42
+ /**
43
+ * Default value of the input. Provide this if the input should be an uncontrolled component
44
+ * which tracks its current state internally; otherwise, use `value`.
45
+ *
46
+ * (This prop is mutually exclusive with `value`.)
47
+ */
48
+ defaultValue?: string;
49
+ /**
50
+ * Current value of the input. Provide this if the input is a controlled component where you
51
+ * are maintaining its current state; otherwise, use `defaultValue`.
52
+ *
53
+ * (This prop is mutually exclusive with `defaultValue`.)
54
+ */
55
+ value?: string;
56
+ /**
57
+ * Called when the user changes the input's value.
58
+ */
59
+ onChange?: (ev: React_2.FormEvent<HTMLInputElement>, data: InputOnChangeData) => void;
60
+ /**
61
+ * An input can have different text-based [types](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input#input_types)
62
+ * based on the type of value the user will enter.
63
+ *
64
+ * Note that no custom styling is currently applied for alternative types, and some types may
65
+ * activate browser-default styling which does not match the Fluent design language.
66
+ *
67
+ * (For non-text-based types such as `button` or `checkbox`, use the appropriate component or an
68
+ * `<input>` element instead.)
69
+ * @default 'text'
70
+ */
71
+ type?: 'text' | 'email' | 'password' | 'search' | 'tel' | 'url' | 'date' | 'datetime-local' | 'month' | 'number' | 'time' | 'week';
72
+ };
73
+
74
+ export declare type InputSlots = {
75
+ /**
76
+ * Wrapper element which visually appears to be the input and is used for borders, focus styling, etc.
77
+ * (A wrapper is needed to properly position `contentBefore` and `contentAfter` relative to `input`.)
78
+ *
79
+ * The root slot receives the `className` and `style` specified directly on the `<Input>`.
80
+ * All other top-level native props will be applied to the primary slot, `input`.
81
+ */
82
+ root: IntrinsicShorthandProps<'span'>;
83
+ /**
84
+ * The actual `<input>` element. `type="text"` will be automatically applied unless overridden.
85
+ *
86
+ * This is the "primary" slot, so native props specified directly on the `<Input>` will go here
87
+ * (except `className` and `style`, which go to the `root` slot). The top-level `ref` will
88
+ * also go here.
89
+ */
90
+ input: IntrinsicShorthandProps<'input'>;
91
+ /** Element before the input text, within the input border */
92
+ contentBefore?: IntrinsicShorthandProps<'span'>;
93
+ /** Element after the input text, within the input border */
94
+ contentAfter?: IntrinsicShorthandProps<'span'>;
95
+ };
96
+
97
+ /**
98
+ * State used in rendering Input.
99
+ */
100
+ export declare type InputState = Required<Pick<InputProps, 'appearance' | 'inline' | 'size'>> & ComponentState<InputSlots>;
101
+
102
+ /**
103
+ * Render the final JSX of Input
104
+ */
105
+ export declare const renderInput: (state: InputState) => JSX.Element;
106
+
107
+ /**
108
+ * Create the state required to render Input.
109
+ *
110
+ * The returned state can be modified with hooks such as useInputStyles,
111
+ * before being passed to renderInput.
112
+ *
113
+ * @param props - props from this instance of Input
114
+ * @param ref - reference to `<input>` element of Input
115
+ */
116
+ export declare const useInput: (props: InputProps, ref: React_2.Ref<HTMLInputElement>) => InputState;
117
+
118
+ /**
119
+ * Apply styling to the Input slots based on the state
120
+ */
121
+ export declare const useInputStyles: (state: InputState) => InputState;
122
+
123
+ export { }
package/lib/Input.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './components/Input/index';
package/lib/Input.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './components/Input/index';
2
+ //# sourceMappingURL=Input.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Input.js","sourceRoot":"","sources":["../src/Input.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { InputProps } from './Input.types';
2
+ import type { ForwardRefComponent } from '@fluentui/react-utilities';
3
+ /**
4
+ * The Input component allows people to enter and edit text.
5
+ *
6
+ * ⚠️ **This component is still in alpha (unstable) status. APIs may change before the final release.**
7
+ */
8
+ export declare const Input: ForwardRefComponent<InputProps>;
@@ -0,0 +1,17 @@
1
+ import * as React from 'react';
2
+ import { useInput } from './useInput';
3
+ import { renderInput } from './renderInput';
4
+ import { useInputStyles } from './useInputStyles';
5
+ /**
6
+ * The Input component allows people to enter and edit text.
7
+ *
8
+ * ⚠️ **This component is still in alpha (unstable) status. APIs may change before the final release.**
9
+ */
10
+
11
+ export const Input = /*#__PURE__*/React.forwardRef((props, ref) => {
12
+ const state = useInput(props, ref);
13
+ useInputStyles(state);
14
+ return renderInput(state);
15
+ });
16
+ Input.displayName = 'Input';
17
+ //# sourceMappingURL=Input.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/Input/Input.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,QAAT,QAAyB,YAAzB;AACA,SAAS,WAAT,QAA4B,eAA5B;AACA,SAAS,cAAT,QAA+B,kBAA/B;AAIA;;;;AAIG;;AACH,OAAO,MAAM,KAAK,gBAAoC,KAAK,CAAC,UAAN,CAAiB,CAAC,KAAD,EAAQ,GAAR,KAAe;AACpF,QAAM,KAAK,GAAG,QAAQ,CAAC,KAAD,EAAQ,GAAR,CAAtB;AAEA,EAAA,cAAc,CAAC,KAAD,CAAd;AACA,SAAO,WAAW,CAAC,KAAD,CAAlB;AACD,CALqD,CAA/C;AAOP,KAAK,CAAC,WAAN,GAAoB,OAApB","sourceRoot":""}
@@ -0,0 +1,84 @@
1
+ import * as React from 'react';
2
+ import type { ComponentProps, ComponentState, IntrinsicShorthandProps } from '@fluentui/react-utilities';
3
+ export declare type InputSlots = {
4
+ /**
5
+ * Wrapper element which visually appears to be the input and is used for borders, focus styling, etc.
6
+ * (A wrapper is needed to properly position `contentBefore` and `contentAfter` relative to `input`.)
7
+ *
8
+ * The root slot receives the `className` and `style` specified directly on the `<Input>`.
9
+ * All other top-level native props will be applied to the primary slot, `input`.
10
+ */
11
+ root: IntrinsicShorthandProps<'span'>;
12
+ /**
13
+ * The actual `<input>` element. `type="text"` will be automatically applied unless overridden.
14
+ *
15
+ * This is the "primary" slot, so native props specified directly on the `<Input>` will go here
16
+ * (except `className` and `style`, which go to the `root` slot). The top-level `ref` will
17
+ * also go here.
18
+ */
19
+ input: IntrinsicShorthandProps<'input'>;
20
+ /** Element before the input text, within the input border */
21
+ contentBefore?: IntrinsicShorthandProps<'span'>;
22
+ /** Element after the input text, within the input border */
23
+ contentAfter?: IntrinsicShorthandProps<'span'>;
24
+ };
25
+ export declare type InputProps = Omit<ComponentProps<InputSlots, 'input'>, 'children' | 'defaultValue' | 'onChange' | 'size' | 'type' | 'value'> & {
26
+ /** Input can't have children. */
27
+ children?: never;
28
+ /**
29
+ * Size of the input (changes the font size and spacing).
30
+ * @default 'medium'
31
+ */
32
+ size?: 'small' | 'medium' | 'large';
33
+ /**
34
+ * If true, the input will have inline display, allowing it be used within text content.
35
+ * If false (the default), the input will have block display.
36
+ */
37
+ inline?: boolean;
38
+ /**
39
+ * Controls the colors and borders of the input.
40
+ * @default 'outline'
41
+ */
42
+ appearance?: 'outline' | 'underline' | 'filledDarker' | 'filledLighter';
43
+ /**
44
+ * Default value of the input. Provide this if the input should be an uncontrolled component
45
+ * which tracks its current state internally; otherwise, use `value`.
46
+ *
47
+ * (This prop is mutually exclusive with `value`.)
48
+ */
49
+ defaultValue?: string;
50
+ /**
51
+ * Current value of the input. Provide this if the input is a controlled component where you
52
+ * are maintaining its current state; otherwise, use `defaultValue`.
53
+ *
54
+ * (This prop is mutually exclusive with `defaultValue`.)
55
+ */
56
+ value?: string;
57
+ /**
58
+ * Called when the user changes the input's value.
59
+ */
60
+ onChange?: (ev: React.FormEvent<HTMLInputElement>, data: InputOnChangeData) => void;
61
+ /**
62
+ * An input can have different text-based [types](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input#input_types)
63
+ * based on the type of value the user will enter.
64
+ *
65
+ * Note that no custom styling is currently applied for alternative types, and some types may
66
+ * activate browser-default styling which does not match the Fluent design language.
67
+ *
68
+ * (For non-text-based types such as `button` or `checkbox`, use the appropriate component or an
69
+ * `<input>` element instead.)
70
+ * @default 'text'
71
+ */
72
+ type?: 'text' | 'email' | 'password' | 'search' | 'tel' | 'url' | 'date' | 'datetime-local' | 'month' | 'number' | 'time' | 'week';
73
+ };
74
+ /**
75
+ * State used in rendering Input.
76
+ */
77
+ export declare type InputState = Required<Pick<InputProps, 'appearance' | 'inline' | 'size'>> & ComponentState<InputSlots>;
78
+ /**
79
+ * Data passed to the `onChange` callback when a user changes the input's value.
80
+ */
81
+ export declare type InputOnChangeData = {
82
+ /** Updated input value from the user */
83
+ value: string;
84
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Input.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Input.types.js","sourceRoot":"","sources":["../../../src/components/Input/Input.types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ export * from './Input';
2
+ export * from './Input.types';
3
+ export * from './renderInput';
4
+ export * from './useInput';
5
+ export * from './useInputStyles';
@@ -0,0 +1,6 @@
1
+ export * from './Input';
2
+ export * from './Input.types';
3
+ export * from './renderInput';
4
+ export * from './useInput';
5
+ export * from './useInputStyles';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/Input/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { InputState } from './Input.types';
2
+ /**
3
+ * Render the final JSX of Input
4
+ */
5
+ export declare const renderInput: (state: InputState) => JSX.Element;