@redis-ui/components 43.0.2 → 43.2.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.
- package/dist/HighlightedIcon/HighlightedIcon.cjs +26 -0
- package/dist/HighlightedIcon/HighlightedIcon.d.ts +3 -0
- package/dist/HighlightedIcon/HighlightedIcon.js +26 -0
- package/dist/HighlightedIcon/HighlightedIcon.style.cjs +49 -0
- package/dist/HighlightedIcon/HighlightedIcon.style.d.ts +5 -0
- package/dist/HighlightedIcon/HighlightedIcon.style.js +47 -0
- package/dist/HighlightedIcon/HighlightedIcon.types.d.ts +8 -0
- package/dist/HighlightedIcon/index.d.ts +3 -0
- package/dist/Stepper/Stepper.cjs +14 -5
- package/dist/Stepper/Stepper.d.ts +2 -0
- package/dist/Stepper/Stepper.js +14 -5
- package/dist/Stepper/Stepper.utils.cjs +12 -0
- package/dist/Stepper/Stepper.utils.d.ts +2 -0
- package/dist/Stepper/Stepper.utils.js +12 -0
- package/dist/Stepper/components/Compose/Compose.d.ts +1 -0
- package/dist/Stepper/components/Step/Step.cjs +2 -0
- package/dist/Stepper/components/Step/Step.d.ts +1 -0
- package/dist/Stepper/components/Step/Step.js +2 -0
- package/dist/Stepper/components/Step/components/Compose/Compose.cjs +2 -9
- package/dist/Stepper/components/Step/components/Compose/Compose.js +2 -9
- package/dist/Stepper/components/Step/components/Separator/Separator.cjs +15 -0
- package/dist/Stepper/components/Step/components/Separator/Separator.d.ts +3 -0
- package/dist/Stepper/components/Step/components/Separator/Separator.js +15 -0
- package/dist/Stepper/components/Step/components/Separator/Separator.style.cjs +24 -0
- package/dist/Stepper/components/Step/components/Separator/Separator.style.d.ts +1 -0
- package/dist/Stepper/components/Step/components/Separator/Separator.style.js +22 -0
- package/dist/Stepper/components/Step/components/Separator/Separator.types.d.ts +5 -0
- package/dist/index.cjs +4 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +74 -70
- package/package.json +2 -2
- package/skills/redis-ui-components/SKILL.md +0 -2
- package/skills/redis-ui-components/references/ActionIconButton.md +96 -0
- package/skills/redis-ui-components/references/AppBar.md +161 -0
- package/skills/redis-ui-components/references/AppSelectionMenu.md +184 -0
- package/skills/redis-ui-components/references/AutoCompleteSelect.md +193 -0
- package/skills/redis-ui-components/references/Badge.md +77 -0
- package/skills/redis-ui-components/references/Banner.md +563 -0
- package/skills/redis-ui-components/references/BoxSelectionGroup.md +487 -0
- package/skills/redis-ui-components/references/Breadcrumbs.md +214 -0
- package/skills/redis-ui-components/references/ButtonGroup.md +126 -0
- package/skills/redis-ui-components/references/Card.md +56 -0
- package/skills/redis-ui-components/references/Checkbox.md +171 -0
- package/skills/redis-ui-components/references/Chip.md +154 -0
- package/skills/redis-ui-components/references/ChipList.md +307 -0
- package/skills/redis-ui-components/references/CopyToClipboardButton.md +47 -0
- package/skills/redis-ui-components/references/CountryFlag.md +57 -0
- package/skills/redis-ui-components/references/Drawer.md +298 -0
- package/skills/redis-ui-components/references/Filters.md +162 -0
- package/skills/redis-ui-components/references/FormField.md +678 -0
- package/skills/redis-ui-components/references/IconButton.md +63 -0
- package/skills/redis-ui-components/references/Input.md +295 -0
- package/skills/redis-ui-components/references/KeyValueList.md +501 -0
- package/skills/redis-ui-components/references/Label.md +238 -0
- package/skills/redis-ui-components/references/Link.md +402 -0
- package/skills/redis-ui-components/references/Loader.md +100 -0
- package/skills/redis-ui-components/references/Menu.md +988 -0
- package/skills/redis-ui-components/references/MidBar.md +358 -0
- package/skills/redis-ui-components/references/Modal.md +525 -0
- package/skills/redis-ui-components/references/MoreInfoIcon.md +119 -0
- package/skills/redis-ui-components/references/MultiSelect.md +558 -0
- package/skills/redis-ui-components/references/NumericInput.md +322 -0
- package/skills/redis-ui-components/references/Overflow.md +127 -0
- package/skills/redis-ui-components/references/Pagination.md +151 -0
- package/skills/redis-ui-components/references/PasswordInput.md +262 -0
- package/skills/redis-ui-components/references/Popover.md +868 -0
- package/skills/redis-ui-components/references/ProfileIcon.md +65 -0
- package/skills/redis-ui-components/references/ProgressBar.md +103 -0
- package/skills/redis-ui-components/references/QuantityCounter.md +555 -0
- package/skills/redis-ui-components/references/RadioGroup.md +265 -0
- package/skills/redis-ui-components/references/ScreenReaderAnnounce.md +147 -0
- package/skills/redis-ui-components/references/SearchBar.md +242 -0
- package/skills/redis-ui-components/references/SearchInput.md +213 -0
- package/skills/redis-ui-components/references/Section.md +349 -0
- package/skills/redis-ui-components/references/SideBar.md +468 -0
- package/skills/redis-ui-components/references/Slider.md +398 -0
- package/skills/redis-ui-components/references/Stepper.md +288 -0
- package/skills/redis-ui-components/references/Switch.md +193 -0
- package/skills/redis-ui-components/references/Tabs.md +383 -0
- package/skills/redis-ui-components/references/TextArea.md +139 -0
- package/skills/redis-ui-components/references/TextButton.md +217 -0
- package/skills/redis-ui-components/references/Toast.md +399 -0
- package/skills/redis-ui-components/references/ToggleButton.md +163 -0
- package/skills/redis-ui-components/references/Tooltip.md +636 -0
- package/skills/redis-ui-components/references/Typography.md +323 -0
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
# NumericInput
|
|
2
|
+
|
|
3
|
+
A numeric input with status indicators, constraint validation, reset/loading add-ons, and a low-level compose API for custom read-only rendering.
|
|
4
|
+
|
|
5
|
+
## Import
|
|
6
|
+
```tsx
|
|
7
|
+
import { NumericInput } from '@redislabsdev/redis-ui-components';
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Props
|
|
11
|
+
| Prop | Type | Default | Description |
|
|
12
|
+
|------|------|---------|-------------|
|
|
13
|
+
| id | `string` | `auto-generated` | Shared id used by `FormField` and read-only rendering. Custom ids should start with a letter. |
|
|
14
|
+
| variant | `'outline' \| 'underline'` | `'outline'` | Visual variant of the input shell. |
|
|
15
|
+
| error | `ReactElement \| string` | - | Error content. Enables error status and tooltip content. |
|
|
16
|
+
| valid | `boolean` | `false` | Enables success status. |
|
|
17
|
+
| readOnly | `boolean` | `false` | Switches the input to read-only rendering. |
|
|
18
|
+
| value | `number \| null` | - | Controlled numeric value. |
|
|
19
|
+
| defaultValue | `number \| null` | - | Initial value for uncontrolled usage. |
|
|
20
|
+
| onChange | `(newValue: number \| null) => void` | - | Called when the parsed numeric value changes. |
|
|
21
|
+
| min | `number` | - | Minimum numeric constraint. |
|
|
22
|
+
| max | `number` | - | Maximum numeric constraint. |
|
|
23
|
+
| step | `number` | `1` | Step size used for Up/Down actions. |
|
|
24
|
+
| required | `boolean` | `false` | Requires a non-empty value when auto-validating. |
|
|
25
|
+
| maxDecimals | `number` | - | Maximum fractional digits used by the validator. |
|
|
26
|
+
| autoValidate | `boolean` | `false` | Snaps typed values to constraints automatically. |
|
|
27
|
+
| validate | `(params: { value: number \| null; min: number; max: number; required: boolean; maxDecimals: number; }) => number \| null` | built-in validator | Custom constraint validation callback. |
|
|
28
|
+
| calcStepActionValue | `(params: { value: number \| null; action: 'increment' \| 'decrement'; step: number; }) => number \| null` | built-in step calculator | Custom step calculation callback. |
|
|
29
|
+
| autoSize | `boolean` | `false` | Makes the input width follow its content. |
|
|
30
|
+
| loading | `boolean` | `false` | Shows the loading indicator. |
|
|
31
|
+
| allowReset | `boolean` | `false` | Shows the reset button when a value is present. |
|
|
32
|
+
| native input props | `Omit<InputHTMLAttributes<HTMLInputElement>, 'children' \| 'defaultValue' \| 'value' \| 'onChange' \| 'min' \| 'max' \| 'type' \| 'step' \| 'required'>` | - | All remaining native `<input>` attributes, such as `placeholder`, `disabled`, `name`, `className`, `style`, `autoComplete`, and ARIA props. |
|
|
33
|
+
|
|
34
|
+
The component also fixes the underlying input to `type="text"` and forwards the remaining native input attributes to the input tag.
|
|
35
|
+
|
|
36
|
+
## Sub-components
|
|
37
|
+
|
|
38
|
+
- `NumericInput.Compose` - Low-level compose wrapper for the input shell, value provider, and custom read-only rendering.
|
|
39
|
+
- `NumericInput.Tag` - The actual input element. Supports `autoSize` and the remaining native input props.
|
|
40
|
+
- `NumericInput.StatusIndicator` - Renders the success or error indicator for the current field status.
|
|
41
|
+
- `NumericInput.LoadingIndicator` - Renders the loading indicator when `loading` is `true`.
|
|
42
|
+
- `NumericInput.ResetButton` - Renders the reset action when `allowReset` is enabled and the field has a value.
|
|
43
|
+
- `NumericInput.ReadonlyValue` - Default read-only renderer used by `NumericInput.Compose`.
|
|
44
|
+
|
|
45
|
+
## Examples
|
|
46
|
+
|
|
47
|
+
### Playground
|
|
48
|
+
```tsx
|
|
49
|
+
import { NumericInput } from '@redislabsdev/redis-ui-components';
|
|
50
|
+
|
|
51
|
+
<NumericInput placeholder="NumericInput" id="custom-id" disabled={false} />;
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Status
|
|
55
|
+
> Adding `valid` enables success status.
|
|
56
|
+
>
|
|
57
|
+
> Adding text to `error` enables error status. Hover the error indicator to see the tooltip.
|
|
58
|
+
>
|
|
59
|
+
> Error status overrides valid status.
|
|
60
|
+
```tsx
|
|
61
|
+
import { NumericInput } from '@redislabsdev/redis-ui-components';
|
|
62
|
+
|
|
63
|
+
<>
|
|
64
|
+
Valid status
|
|
65
|
+
<NumericInput placeholder="Numeric Input" valid />
|
|
66
|
+
Error status
|
|
67
|
+
<NumericInput placeholder="Numeric Input" error="Error message" />
|
|
68
|
+
</>
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Loading
|
|
72
|
+
> Adding `loading` enables the loading indicator.
|
|
73
|
+
>
|
|
74
|
+
> It can be combined with other indicators and states.
|
|
75
|
+
```tsx
|
|
76
|
+
import { NumericInput } from '@redislabsdev/redis-ui-components';
|
|
77
|
+
|
|
78
|
+
<>
|
|
79
|
+
Loading indicator
|
|
80
|
+
<NumericInput placeholder="Numeric Input" loading />
|
|
81
|
+
With other elements
|
|
82
|
+
<NumericInput placeholder="Numeric Input" defaultValue={123.1} valid allowReset loading />
|
|
83
|
+
</>
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### ResetButton
|
|
87
|
+
> NumericInput allows users to clear the value. Set `allowReset` to show the reset button.
|
|
88
|
+
```tsx
|
|
89
|
+
import { NumericInput } from '@redislabsdev/redis-ui-components';
|
|
90
|
+
|
|
91
|
+
<NumericInput placeholder="Numeric Input" defaultValue={123.1} allowReset />;
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### DisabledAndReadonly
|
|
95
|
+
> Adding `disabled` or `readOnly` switches the component to disabled or read-only states.
|
|
96
|
+
>
|
|
97
|
+
> In read-only mode only the value is visible. Other indicators are ignored.
|
|
98
|
+
>
|
|
99
|
+
> `readOnly` overrides `disabled`.
|
|
100
|
+
```tsx
|
|
101
|
+
import { NumericInput } from '@redislabsdev/redis-ui-components';
|
|
102
|
+
|
|
103
|
+
<>
|
|
104
|
+
Disabled
|
|
105
|
+
<NumericInput disabled />
|
|
106
|
+
Disabled with value
|
|
107
|
+
<NumericInput disabled defaultValue={123.1} />
|
|
108
|
+
Disabled with indicators
|
|
109
|
+
<NumericInput disabled defaultValue={123.1} error="Error message" allowReset />
|
|
110
|
+
Read only
|
|
111
|
+
<NumericInput value={123.1} readOnly />
|
|
112
|
+
</>
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### WithLabel
|
|
116
|
+
> NumericInput does not render its own label or other external decoration elements.
|
|
117
|
+
>
|
|
118
|
+
> Use `FormField` as a wrapper for that purpose. If a custom id is provided, `FormField` uses it; otherwise the label is connected to the generated id.
|
|
119
|
+
>
|
|
120
|
+
> Custom ids must start with a letter to work correctly.
|
|
121
|
+
>
|
|
122
|
+
> `FormField` also inherits the field status and other states.
|
|
123
|
+
```tsx
|
|
124
|
+
import { FormField, NumericInput } from '@redislabsdev/redis-ui-components';
|
|
125
|
+
|
|
126
|
+
<>
|
|
127
|
+
<FormField label="FormField Label with custom id">
|
|
128
|
+
<NumericInput placeholder="Numeric Input" id="custom-id" />
|
|
129
|
+
</FormField>
|
|
130
|
+
<FormField
|
|
131
|
+
label="FormField Label with auto-generated id"
|
|
132
|
+
additionalText="FormField additional text"
|
|
133
|
+
>
|
|
134
|
+
<NumericInput placeholder="Numeric Input" />
|
|
135
|
+
</FormField>
|
|
136
|
+
<FormField
|
|
137
|
+
label="FormField Label with read-only mode"
|
|
138
|
+
additionalText="FormField additional text"
|
|
139
|
+
>
|
|
140
|
+
<NumericInput value={123.1} readOnly />
|
|
141
|
+
</FormField>
|
|
142
|
+
</>
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Variants
|
|
146
|
+
```tsx
|
|
147
|
+
import { FormField, NumericInput } from '@redislabsdev/redis-ui-components';
|
|
148
|
+
|
|
149
|
+
<>
|
|
150
|
+
<FormField label="Outline (default)" additionalText="outline">
|
|
151
|
+
<NumericInput placeholder="Numeric Input" />
|
|
152
|
+
</FormField>
|
|
153
|
+
<FormField label="Underline" additionalText="underline">
|
|
154
|
+
<NumericInput placeholder="Numeric Input" variant="underline" />
|
|
155
|
+
</FormField>
|
|
156
|
+
</>
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### AutoSize
|
|
160
|
+
> Regular text inputs ignore `width: auto`.
|
|
161
|
+
>
|
|
162
|
+
> Add `autoSize` to let NumericInput grow to its content.
|
|
163
|
+
```tsx
|
|
164
|
+
import { NumericInput } from '@redislabsdev/redis-ui-components';
|
|
165
|
+
|
|
166
|
+
<>
|
|
167
|
+
Type text in the input boxes to see how it auto-sizes
|
|
168
|
+
<NumericInput autoSize placeholder="placeholder" />
|
|
169
|
+
NumericInput without placeholder:
|
|
170
|
+
<NumericInput autoSize defaultValue={123.1} />
|
|
171
|
+
</>
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Validations
|
|
175
|
+
> NumericInput supports the `min`, `max`, `step`, `required`, and `maxDecimals` constraints.
|
|
176
|
+
>
|
|
177
|
+
> Constraints are applied while typing and on blur when `autoValidate` is enabled, and always on step actions.
|
|
178
|
+
>
|
|
179
|
+
> `validate` can override the default constraint validator.
|
|
180
|
+
>
|
|
181
|
+
> `calcStepActionValue` can override the step calculation logic.
|
|
182
|
+
```tsx
|
|
183
|
+
import { useState } from 'react';
|
|
184
|
+
import { FormField, NumericInput, Switch } from '@redislabsdev/redis-ui-components';
|
|
185
|
+
|
|
186
|
+
function Render() {
|
|
187
|
+
const [props, setProps] = useState<{
|
|
188
|
+
min?: number;
|
|
189
|
+
max?: number;
|
|
190
|
+
step?: number;
|
|
191
|
+
required: boolean;
|
|
192
|
+
}>({ min: -99, max: 99, step: 10, required: false });
|
|
193
|
+
const [val1, setVal1] = useState<number | null>(null);
|
|
194
|
+
const [val2, setVal2] = useState<number | null>(null);
|
|
195
|
+
const [val3, setVal3] = useState<number | null>(null);
|
|
196
|
+
const [val4, setVal4] = useState<number | null>(null);
|
|
197
|
+
|
|
198
|
+
return (
|
|
199
|
+
<>
|
|
200
|
+
<strong>
|
|
201
|
+
Edit constraints, type a number, press Up/Down for step actions, and blur the input to see
|
|
202
|
+
how each constraint behaves.
|
|
203
|
+
</strong>
|
|
204
|
+
<div>
|
|
205
|
+
<strong>Constraints</strong>
|
|
206
|
+
<div>
|
|
207
|
+
<FormField label="min">
|
|
208
|
+
<NumericInput
|
|
209
|
+
value={props.min}
|
|
210
|
+
onChange={(min) => setProps((state) => ({ ...state, min: min ?? undefined }))}
|
|
211
|
+
/>
|
|
212
|
+
</FormField>
|
|
213
|
+
<FormField label="max">
|
|
214
|
+
<NumericInput
|
|
215
|
+
value={props.max}
|
|
216
|
+
onChange={(max) => setProps((state) => ({ ...state, max: max ?? undefined }))}
|
|
217
|
+
/>
|
|
218
|
+
</FormField>
|
|
219
|
+
<FormField label="step">
|
|
220
|
+
<NumericInput
|
|
221
|
+
value={props.step}
|
|
222
|
+
autoValidate
|
|
223
|
+
onChange={(step) => setProps((state) => ({ ...state, step: step ?? undefined }))}
|
|
224
|
+
/>
|
|
225
|
+
</FormField>
|
|
226
|
+
<FormField label="required">
|
|
227
|
+
<Switch
|
|
228
|
+
checked={props.required}
|
|
229
|
+
onCheckedChange={() => setProps((state) => ({ ...state, required: !state.required }))}
|
|
230
|
+
/>
|
|
231
|
+
</FormField>
|
|
232
|
+
</div>
|
|
233
|
+
</div>
|
|
234
|
+
<FormField
|
|
235
|
+
label={`Regular (value: ${val1})`}
|
|
236
|
+
additionalText="errors should be detected in custom way (step always validates min-max constraints)"
|
|
237
|
+
required={props.required}
|
|
238
|
+
>
|
|
239
|
+
<NumericInput {...props} value={val1} onChange={setVal1} />
|
|
240
|
+
</FormField>
|
|
241
|
+
<FormField
|
|
242
|
+
label={`Auto Validated (value: ${val2})`}
|
|
243
|
+
additionalText="constraints are validating inside and outside we have valid value"
|
|
244
|
+
required={props.required}
|
|
245
|
+
>
|
|
246
|
+
<NumericInput {...props} value={val2} onChange={setVal2} autoValidate />
|
|
247
|
+
</FormField>
|
|
248
|
+
<FormField
|
|
249
|
+
label={`Custom Step Calculation (value: ${val3})`}
|
|
250
|
+
additionalText="step value is calculated as a simple addition of the step size to the current value"
|
|
251
|
+
required={props.required}
|
|
252
|
+
>
|
|
253
|
+
<NumericInput
|
|
254
|
+
{...props}
|
|
255
|
+
value={val3}
|
|
256
|
+
onChange={setVal3}
|
|
257
|
+
calcStepActionValue={(params) =>
|
|
258
|
+
(params.value ?? (params.action === 'increment' ? props.min : props.max) ?? 0) +
|
|
259
|
+
(params.action === 'increment' ? params.step : -params.step)
|
|
260
|
+
}
|
|
261
|
+
/>
|
|
262
|
+
</FormField>
|
|
263
|
+
<FormField
|
|
264
|
+
label={`Custom Validation (value: ${val4})`}
|
|
265
|
+
additionalText="makes the value a multiple of the step size (no other constraints applied)"
|
|
266
|
+
required={props.required}
|
|
267
|
+
>
|
|
268
|
+
<NumericInput
|
|
269
|
+
{...props}
|
|
270
|
+
value={val4}
|
|
271
|
+
onChange={setVal4}
|
|
272
|
+
autoValidate
|
|
273
|
+
validate={(params) =>
|
|
274
|
+
params.value && Math.round(params.value / (props.step || 1)) * (props.step || 1)
|
|
275
|
+
}
|
|
276
|
+
/>
|
|
277
|
+
</FormField>
|
|
278
|
+
</>
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### ComposeReadOnly
|
|
284
|
+
```tsx
|
|
285
|
+
import {
|
|
286
|
+
InputReadonlyRenderProps,
|
|
287
|
+
NumericInput
|
|
288
|
+
} from '@redislabsdev/redis-ui-components';
|
|
289
|
+
|
|
290
|
+
<NumericInput.Compose
|
|
291
|
+
readOnly
|
|
292
|
+
defaultValue={123.1}
|
|
293
|
+
readonlyRender={({ value, ...restProps }: InputReadonlyRenderProps) => (
|
|
294
|
+
<NumericInput.ReadonlyValue {...restProps} style={{ color: 'red' }}>
|
|
295
|
+
read-only:💚💛{' '}
|
|
296
|
+
<span
|
|
297
|
+
style={{
|
|
298
|
+
fontSize: '16px',
|
|
299
|
+
border: '1px dashed red',
|
|
300
|
+
color: 'blue',
|
|
301
|
+
borderRadius: 6,
|
|
302
|
+
padding: 3
|
|
303
|
+
}}
|
|
304
|
+
>
|
|
305
|
+
{value?.toUpperCase()}
|
|
306
|
+
</span>{' '}
|
|
307
|
+
💙💗
|
|
308
|
+
</NumericInput.ReadonlyValue>
|
|
309
|
+
)}
|
|
310
|
+
>
|
|
311
|
+
<NumericInput.Tag />
|
|
312
|
+
</NumericInput.Compose>
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
## Notes
|
|
316
|
+
- `NumericInput` uses `type="text"` internally and the tag drives numeric keyboard behavior.
|
|
317
|
+
- `allowReset` is off by default; the reset button only appears when the field has a value.
|
|
318
|
+
- `readOnly` hides other indicators and overrides `disabled`.
|
|
319
|
+
- `autoSize` is required if you want the input width to follow its content.
|
|
320
|
+
- Use `FormField` when you need an external label, required marker, or inherited field status.
|
|
321
|
+
- `NumericInput.Compose` is the entry point for custom read-only rendering and lower-level composition.
|
|
322
|
+
- The built-in validator snaps values to the configured constraints when `autoValidate` is enabled.
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# Overflow
|
|
2
|
+
|
|
3
|
+
Horizontal auto-collapsing item list that hides overflowing children and can render an extra summary item for hidden content.
|
|
4
|
+
|
|
5
|
+
## Import
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
import { Overflow } from '@redislabsdev/redis-ui-components';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Props
|
|
12
|
+
|
|
13
|
+
| Prop | Type | Default | Description |
|
|
14
|
+
|------|------|---------|-------------|
|
|
15
|
+
| children | `React.ReactNode` | required | Items to measure and collapse when they do not fit in the container |
|
|
16
|
+
| renderExtra | `(visibleCount: number) => React.ReactNode` | - | Renders the extra item that summarizes hidden content |
|
|
17
|
+
| estimatedItemsPerRow | `number` | `5` | Initial estimate used to calculate how many items to render before measurement completes |
|
|
18
|
+
| maxRows | `number` | `1` | Maximum number of rows to display before collapsing items |
|
|
19
|
+
| minItems | `number` | `0` | Minimum number of items to keep visible |
|
|
20
|
+
| expectedGap | `number` | - | Expected gap between items when the component cannot infer it from styles |
|
|
21
|
+
| style | `React.CSSProperties` | - | Inline styles applied to the overflow container |
|
|
22
|
+
| className | `string` | - | Class name applied to the overflow container |
|
|
23
|
+
|
|
24
|
+
## Examples
|
|
25
|
+
|
|
26
|
+
### Playground
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
import { Overflow } from '@redislabsdev/redis-ui-components';
|
|
30
|
+
|
|
31
|
+
const items = Array.from({ length: 10 }, (_, index) => `Item ${index + 1}`);
|
|
32
|
+
|
|
33
|
+
<Overflow
|
|
34
|
+
renderExtra={(visibleCount) => <span>+{items.length - visibleCount}</span>}
|
|
35
|
+
style={{ gap: 10 }}
|
|
36
|
+
>
|
|
37
|
+
{items.map((item) => (
|
|
38
|
+
<span key={item} style={{ overflow: 'hidden' }}>
|
|
39
|
+
{item}
|
|
40
|
+
</span>
|
|
41
|
+
))}
|
|
42
|
+
</Overflow>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### ExactItemCount
|
|
46
|
+
|
|
47
|
+
> Setting `maxRows` to 0 shows `minItems` count.
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
import { Overflow } from '@redislabsdev/redis-ui-components';
|
|
51
|
+
|
|
52
|
+
const items = Array.from({ length: 20 }, (_, index) => `Item ${index + 1}`);
|
|
53
|
+
|
|
54
|
+
<Overflow
|
|
55
|
+
renderExtra={(visibleCount) => <span>+{items.length - visibleCount}</span>}
|
|
56
|
+
style={{ gap: 10 }}
|
|
57
|
+
maxRows={0}
|
|
58
|
+
minItems={3}
|
|
59
|
+
>
|
|
60
|
+
{items.map((item) => (
|
|
61
|
+
<span key={item} style={{ overflow: 'hidden' }}>
|
|
62
|
+
{item}
|
|
63
|
+
</span>
|
|
64
|
+
))}
|
|
65
|
+
</Overflow>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### SingleRow
|
|
69
|
+
|
|
70
|
+
> Setting `maxRows` to 1 (default) enforces `Overflow` to be single line.
|
|
71
|
+
|
|
72
|
+
```tsx
|
|
73
|
+
import { Overflow } from '@redislabsdev/redis-ui-components';
|
|
74
|
+
|
|
75
|
+
const items = Array.from({ length: 20 }, (_, index) => `Item ${index + 1}`);
|
|
76
|
+
|
|
77
|
+
<Overflow renderExtra={(visibleCount) => <span>+{items.length - visibleCount}</span>} style={{ gap: 10 }}>
|
|
78
|
+
{items.map((item) => (
|
|
79
|
+
<span key={item} style={{ overflow: 'hidden' }}>
|
|
80
|
+
{item}
|
|
81
|
+
</span>
|
|
82
|
+
))}
|
|
83
|
+
</Overflow>
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### WithoutExtra
|
|
87
|
+
|
|
88
|
+
> If `renderExtra` prop is not defined, then extra item is not rendered and ignored in calculations.
|
|
89
|
+
|
|
90
|
+
```tsx
|
|
91
|
+
import { Overflow } from '@redislabsdev/redis-ui-components';
|
|
92
|
+
|
|
93
|
+
const items = Array.from({ length: 20 }, (_, index) => `Item ${index + 1}`);
|
|
94
|
+
|
|
95
|
+
<Overflow style={{ gap: 10 }}>
|
|
96
|
+
{items.map((item) => (
|
|
97
|
+
<span key={item} style={{ overflow: 'hidden' }}>
|
|
98
|
+
{item}
|
|
99
|
+
</span>
|
|
100
|
+
))}
|
|
101
|
+
</Overflow>
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### MultiRow
|
|
105
|
+
|
|
106
|
+
> Setting `maxRows` to number larger than 1 allows `Overflow` to show items in multiple line up to the number.
|
|
107
|
+
|
|
108
|
+
```tsx
|
|
109
|
+
import { Overflow } from '@redislabsdev/redis-ui-components';
|
|
110
|
+
|
|
111
|
+
const items = Array.from({ length: 100 }, (_, index) => `Item ${index + 1}`);
|
|
112
|
+
|
|
113
|
+
<Overflow renderExtra={(visibleCount) => <span>+{items.length - visibleCount}</span>} style={{ gap: 10 }} maxRows={3}>
|
|
114
|
+
{items.map((item) => (
|
|
115
|
+
<span key={item} style={{ overflow: 'hidden' }}>
|
|
116
|
+
{item}
|
|
117
|
+
</span>
|
|
118
|
+
))}
|
|
119
|
+
</Overflow>
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Notes
|
|
123
|
+
|
|
124
|
+
- `Overflow` measures its children and hides those that do not fit in the available width.
|
|
125
|
+
- `renderExtra` is optional; when omitted, no extra summary item is rendered.
|
|
126
|
+
- `maxRows` controls whether the component behaves as a single-row or multi-row overflow list.
|
|
127
|
+
- Children must be React elements with unique keys.
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# Pagination
|
|
2
|
+
|
|
3
|
+
Compound pagination primitives for rendering page navigation, page selection, page-size selection, and derived status labels. The repo exercises this API through the table pagination docs; there is no standalone `Pagination` story folder.
|
|
4
|
+
|
|
5
|
+
## Import
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
import { Pagination } from '@redislabsdev/redis-ui-components';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Props
|
|
12
|
+
|
|
13
|
+
### `Pagination.Compose`
|
|
14
|
+
|
|
15
|
+
| Prop | Type | Default | Description |
|
|
16
|
+
|------|------|---------|-------------|
|
|
17
|
+
| children | `React.ReactNode` | - | Pagination content rendered inside the context provider |
|
|
18
|
+
| pageIndex | `number` | clamped to `0..pageCount - 1` | Current page index |
|
|
19
|
+
| pageSize | `number` | minimum `1` | Current page size |
|
|
20
|
+
| pageCount | `number` | minimum `0` | Total number of pages |
|
|
21
|
+
| totalItemCount | `number` | - | Total item count for derived labels |
|
|
22
|
+
| visibleItemCount | `number` | - | Visible item count for derived labels |
|
|
23
|
+
| getCanGoNextPage | `() => boolean` | `() => pageIndex < pageCount - 1` | Overrides whether the next-page action is enabled |
|
|
24
|
+
| getCanGoPrevPage | `() => boolean` | `() => pageIndex > 0` | Overrides whether the previous-page action is enabled |
|
|
25
|
+
| getCanSelectPage | `() => boolean` | `() => pageCount > 1` | Overrides whether page selection is enabled |
|
|
26
|
+
| getCanSelectPageSize | `() => boolean` | `() => !!(totalItemCount !== 0 && onPageSizeChange)` | Overrides whether page-size selection is enabled |
|
|
27
|
+
| onPageSizeChange | `(count: number) => void` | - | Called when page size changes |
|
|
28
|
+
| onPageChange | `(page: number) => void` | required | Called when page changes |
|
|
29
|
+
| onNextPage | `() => void` | `() => onPageChange(pageIndex + 1)` | Overrides the next-page action |
|
|
30
|
+
| onFirstPage | `() => void` | `() => onPageChange(0)` | Overrides the first-page action |
|
|
31
|
+
| onPrevPage | `() => void` | `() => onPageChange(pageIndex - 1)` | Overrides the previous-page action |
|
|
32
|
+
| onLastPage | `() => void` | `() => onPageChange(pageCount - 1)` | Overrides the last-page action |
|
|
33
|
+
|
|
34
|
+
### `Pagination.InfoLabel`
|
|
35
|
+
|
|
36
|
+
| Prop | Type | Default | Description |
|
|
37
|
+
|------|------|---------|-------------|
|
|
38
|
+
| renderer | `(params: PaginationState) => ReactNode` | required | Renders derived pagination text from the current pagination state |
|
|
39
|
+
| other `Typography.Body` props | `ChildFree<ComponentProps<typeof Typography.Body>>` | - | Passed through to the underlying `Typography.Body` |
|
|
40
|
+
|
|
41
|
+
### `Pagination.NavigationButton`
|
|
42
|
+
|
|
43
|
+
| Prop | Type | Default | Description |
|
|
44
|
+
|------|------|---------|-------------|
|
|
45
|
+
| navType | `'prev' \| 'next' \| 'first' \| 'last'` | required | Chooses which navigation action and icon to render |
|
|
46
|
+
| other `IconButton` props | `Partial<IconButtonProps>` | - | Passed through to the underlying `IconButton` |
|
|
47
|
+
|
|
48
|
+
### `Pagination.PageSelect`
|
|
49
|
+
|
|
50
|
+
| Prop | Type | Default | Description |
|
|
51
|
+
|------|------|---------|-------------|
|
|
52
|
+
| other `Select` props | `Omit<SelectProps, 'value' \| 'onChange' \| 'disabled' \| 'options'>` | - | Passed through to the underlying `Select` |
|
|
53
|
+
|
|
54
|
+
### `Pagination.PageSelect.Label`
|
|
55
|
+
|
|
56
|
+
| Prop | Type | Default | Description |
|
|
57
|
+
|------|------|---------|-------------|
|
|
58
|
+
| other `Typography.Body` props | `ComponentProps<typeof Typography.Body>` | - | Passed through to the label typography |
|
|
59
|
+
|
|
60
|
+
### `Pagination.PageSizeSelect`
|
|
61
|
+
|
|
62
|
+
| Prop | Type | Default | Description |
|
|
63
|
+
|------|------|---------|-------------|
|
|
64
|
+
| pageSizes | `number[]` | `[10, 25, 50, 100]` | Page sizes shown in the selector |
|
|
65
|
+
| other `Select` props | `Omit<SelectProps, 'value' \| 'onChange' \| 'disabled' \| 'options'>` | - | Passed through to the underlying `Select` |
|
|
66
|
+
|
|
67
|
+
### `Pagination.PageSizeSelect.Label`
|
|
68
|
+
|
|
69
|
+
| Prop | Type | Default | Description |
|
|
70
|
+
|------|------|---------|-------------|
|
|
71
|
+
| other `Typography.Body` props | `ComponentProps<typeof Typography.Body>` | - | Passed through to the label typography |
|
|
72
|
+
|
|
73
|
+
## Sub-components
|
|
74
|
+
|
|
75
|
+
- `Pagination.Compose` - Provides `PaginationContext` and default navigation/validation handlers.
|
|
76
|
+
- `Pagination.Bar` - Layout container for the pagination row.
|
|
77
|
+
- `Pagination.Group` - Flex wrapper for grouping pagination controls.
|
|
78
|
+
- `Pagination.Split` - Spacer primitive that pushes adjacent groups apart.
|
|
79
|
+
- `Pagination.InfoLabel` - Renders derived pagination state text.
|
|
80
|
+
- `Pagination.NavigationButton` - Renders first, previous, next, and last navigation buttons.
|
|
81
|
+
- `Pagination.PageSelect` - Select control for choosing a page.
|
|
82
|
+
- `Pagination.PageSelect.Label` - Label paired with the page selector id.
|
|
83
|
+
- `Pagination.PageSizeSelect` - Select control for choosing the page size.
|
|
84
|
+
- `Pagination.PageSizeSelect.Label` - Label paired with the page-size selector id.
|
|
85
|
+
|
|
86
|
+
## Examples
|
|
87
|
+
|
|
88
|
+
### Table Composition
|
|
89
|
+
|
|
90
|
+
> There is no standalone `Pagination` story folder. The only story-backed usage lives in the table pagination docs, where `Table` layers additional grouping wrappers around these pagination primitives.
|
|
91
|
+
> The `PageSizeGroup`, `PageNavGroup`, and `PageSelectGroup` wrappers in that example belong to the table docs, not the standalone `Pagination` export.
|
|
92
|
+
|
|
93
|
+
```tsx
|
|
94
|
+
import { Table } from '@redislabsdev/redis-ui-table';
|
|
95
|
+
import { PaginationInfoLabelProps } from '@redislabsdev/redis-ui-components';
|
|
96
|
+
import { columns, tableData } from './TableStory.data';
|
|
97
|
+
|
|
98
|
+
const renderRowCount: PaginationInfoLabelProps['renderer'] = ({ visibleItemCount, totalItemCount }) =>
|
|
99
|
+
`Showing ${visibleItemCount} out of ${totalItemCount} rows`;
|
|
100
|
+
|
|
101
|
+
const renderPageCount: PaginationInfoLabelProps['renderer'] = ({ pageIndex, pageCount }) =>
|
|
102
|
+
`${pageIndex + 1} of ${pageCount}`;
|
|
103
|
+
|
|
104
|
+
const renderTotalPageCount: PaginationInfoLabelProps['renderer'] = ({ pageCount }) => `of ${pageCount}`;
|
|
105
|
+
|
|
106
|
+
<Table.Compose
|
|
107
|
+
data={tableData}
|
|
108
|
+
columns={columns}
|
|
109
|
+
pluginsData={[Table.usePaginationPlugin({ paginationEnabled: true })]}
|
|
110
|
+
>
|
|
111
|
+
<Table.Pagination.Compose>
|
|
112
|
+
<Table.Pagination.Bar>
|
|
113
|
+
<Table.Pagination.InfoLabel renderer={renderRowCount} ellipsis tooltipOnEllipsis />
|
|
114
|
+
<Table.Pagination.Split />
|
|
115
|
+
<Table.Pagination.PageSizeGroup>
|
|
116
|
+
<Table.Pagination.PageSizeSelect.Label>
|
|
117
|
+
Items per page:
|
|
118
|
+
</Table.Pagination.PageSizeSelect.Label>
|
|
119
|
+
<Table.Pagination.PageSizeSelect />
|
|
120
|
+
</Table.Pagination.PageSizeGroup>
|
|
121
|
+
<Table.Pagination.PageNavGroup>
|
|
122
|
+
<div>
|
|
123
|
+
<Table.Pagination.NavigationButton navType="first" />
|
|
124
|
+
<Table.Pagination.NavigationButton navType="prev" />
|
|
125
|
+
</div>
|
|
126
|
+
<Table.Pagination.InfoLabel ellipsis tooltipOnEllipsis renderer={renderPageCount} />
|
|
127
|
+
<div>
|
|
128
|
+
<Table.Pagination.NavigationButton navType="next" />
|
|
129
|
+
<Table.Pagination.NavigationButton navType="last" />
|
|
130
|
+
</div>
|
|
131
|
+
</Table.Pagination.PageNavGroup>
|
|
132
|
+
<Table.Pagination.PageSelectGroup>
|
|
133
|
+
<Table.Pagination.PageSelect.Label>Page</Table.Pagination.PageSelect.Label>
|
|
134
|
+
<Table.Pagination.PageSelect />
|
|
135
|
+
<Table.Pagination.InfoLabel
|
|
136
|
+
ellipsis
|
|
137
|
+
tooltipOnEllipsis
|
|
138
|
+
renderer={renderTotalPageCount}
|
|
139
|
+
/>
|
|
140
|
+
</Table.Pagination.PageSelectGroup>
|
|
141
|
+
</Table.Pagination.Bar>
|
|
142
|
+
</Table.Pagination.Compose>
|
|
143
|
+
</Table.Compose>
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Notes
|
|
147
|
+
|
|
148
|
+
- Pagination is handled internally when the pagination prop is not provided.
|
|
149
|
+
- Pagination state can be controlled externally using the pagination prop.
|
|
150
|
+
- For manual pagination, `manualPagination` must be `true` and `totalRowCount` must be provided.
|
|
151
|
+
- Pagination can be used in empty tables.
|