@rolster/react-components 19.8.21 → 19.9.0
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/LICENSE +21 -21
- package/dist/cjs/index.cjs +177 -37
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/es/index.mjs +177 -37
- package/dist/es/index.mjs.map +1 -1
- package/dist/esm/components/atoms/AreaText/AreaText.d.ts +4 -2
- package/dist/esm/components/atoms/AreaText/AreaText.js +88 -17
- package/dist/esm/components/atoms/AreaText/AreaText.js.map +1 -1
- package/dist/esm/components/atoms/Input/Input.js +66 -14
- package/dist/esm/components/atoms/Input/Input.js.map +1 -1
- package/dist/esm/components/atoms/Skeleton/Skeleton.d.ts +5 -1
- package/dist/esm/components/atoms/Skeleton/Skeleton.js +6 -2
- package/dist/esm/components/atoms/Skeleton/Skeleton.js.map +1 -1
- package/dist/esm/components/atoms/SkeletonText/SkeletonText.d.ts +3 -1
- package/dist/esm/components/atoms/SkeletonText/SkeletonText.js +2 -2
- package/dist/esm/components/atoms/SkeletonText/SkeletonText.js.map +1 -1
- package/dist/esm/components/molecules/FieldArea/FieldArea.d.ts +1 -0
- package/dist/esm/components/molecules/FieldArea/FieldArea.js +17 -3
- package/dist/esm/components/molecules/FieldArea/FieldArea.js.map +1 -1
- package/package.json +3 -3
- package/readme.md +403 -2
package/readme.md
CHANGED
|
@@ -10,14 +10,415 @@ npm i @rolster/react-components
|
|
|
10
10
|
|
|
11
11
|
## Configuration
|
|
12
12
|
|
|
13
|
-
You must install the `@rolster/
|
|
13
|
+
You must install the `@rolster/types` package to define package data types, which are configured by adding them to the `files` property of the `tsconfig.json` file.
|
|
14
14
|
|
|
15
15
|
```json
|
|
16
16
|
{
|
|
17
|
-
"files": ["node_modules/@rolster/
|
|
17
|
+
"files": ["node_modules/@rolster/types/index.d.ts"]
|
|
18
18
|
}
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
+
`react` and `react-dom` are supplied by the host application. The `package.json` declares `react-dom` as a dependency, and `@types/react` and `@types/react-dom` as development dependencies; `react` is not declared in any of them, so the application is the one that installs it.
|
|
22
|
+
|
|
23
|
+
### Stylesheets
|
|
24
|
+
|
|
25
|
+
The components render classes only, they do not ship styles. Those classes are defined in `@rolster/styles-foundations`, which must be installed and imported by the application.
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
npm i @rolster/styles-foundations
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The package exposes the following entry points, each one available as Sass (`@use`) and as compiled CSS:
|
|
32
|
+
|
|
33
|
+
| Entry point | Content |
|
|
34
|
+
| ---------------------------------------------------- | --------------------------------------------------------------------- |
|
|
35
|
+
| `@rolster/styles-foundations` | Foundations and utilities: custom properties, typography, grid, fonts |
|
|
36
|
+
| `@rolster/styles-foundations/components` | Structure of every component, without a design system |
|
|
37
|
+
| `@rolster/styles-foundations/design-system-bordered` | Bordered design system |
|
|
38
|
+
| `@rolster/styles-foundations/design-system-filled` | Filled design system |
|
|
39
|
+
| `@rolster/styles-foundations/design-system-gradient` | Gradient design system |
|
|
40
|
+
|
|
41
|
+
```scss
|
|
42
|
+
@use '@rolster/styles-foundations';
|
|
43
|
+
@use '@rolster/styles-foundations/components';
|
|
44
|
+
@use '@rolster/styles-foundations/design-system-filled';
|
|
45
|
+
@use '@rolster/styles-foundations/design-system-bordered';
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Every design system is nested inside its own wrapper class (`.rls-design-system-bordered`, `.rls-design-system-filled`, `.rls-design-system-gradient`), so its rules only reach the elements below an element carrying that class. `setDesignSystem` writes that class on `document.body` and removes the remaining ones, which allows importing more than one design system and switching between them at runtime.
|
|
49
|
+
|
|
50
|
+
### Application
|
|
51
|
+
|
|
52
|
+
`RlsApplication` must wrap the application. It renders its `children` inside the `rls-app__body` element and mounts the snackbar, the confirmation dialog and the notification stack, so all of them are available anywhere in the tree. It publishes a context, read with `useRlsContext`, that exposes:
|
|
53
|
+
|
|
54
|
+
| Member | Description |
|
|
55
|
+
| --------------------- | ---------------------------------------------------------------------- |
|
|
56
|
+
| `confirmation` | Opens the confirmation dialog and resolves with a `ConfirmationResult` |
|
|
57
|
+
| `notify` | Pushes a notification on the stack |
|
|
58
|
+
| `snackbar` | Shows a snackbar |
|
|
59
|
+
| `setIsMobile` | Marks the application body as mobile |
|
|
60
|
+
| `setNavbarInApp` | Declares that a navbar is mounted, so the snackbar respects it |
|
|
61
|
+
| `setNavbarIsCondense` | Declares that the navbar is condensed |
|
|
62
|
+
|
|
63
|
+
Reading the context outside the wrapper throws an error.
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
import { RlsApplication, setDesignSystem } from '@rolster/react-components';
|
|
67
|
+
import { createRoot } from 'react-dom/client';
|
|
68
|
+
import { Dashboard } from './Dashboard';
|
|
69
|
+
|
|
70
|
+
import './styles.scss';
|
|
71
|
+
|
|
72
|
+
setDesignSystem('filled');
|
|
73
|
+
|
|
74
|
+
createRoot(document.getElementById('root')!).render(
|
|
75
|
+
<RlsApplication>
|
|
76
|
+
<Dashboard />
|
|
77
|
+
</RlsApplication>
|
|
78
|
+
);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Form controls
|
|
82
|
+
|
|
83
|
+
Field components are driven by `@rolster/react-forms`: the `formControl` prop takes a `ReactControl` created with `useInputControl` or `useFormControl`, and the field renders the error of the control through `RlsMessageFormError`. Those messages are translated with `@rolster/i18n` and can be extended with `setErrorsI18n`.
|
|
84
|
+
|
|
85
|
+
`RlsInput`, `RlsAreaText` and the fields built over them honour the `formatter` and `formatOn` options of the control. While the user types (or pastes) they apply the formatter before writing the value, keep the caret in place when the text length changes, revert characters the formatter rejects even when the control value does not change, and wait for the end of an IME composition before formatting. With `formatOn: 'blur'` the raw text is kept until the field loses focus and the control formats it.
|
|
86
|
+
|
|
87
|
+
```tsx
|
|
88
|
+
const name = useInputControl({
|
|
89
|
+
value: '',
|
|
90
|
+
formatter: (value: string) => value.toUpperCase()
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
<RlsFieldText formControl={name}>Nombre completo</RlsFieldText>;
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Components that display a list of options (`RlsFieldSelect`, `RlsFieldList`, `RlsFieldAutocomplete` and the `RlsChooser*` family) receive their `suggestions` as elements of `@rolster/components`, usually instances of `RolsterListElement` or `RolsterAutocompleteElement`, or of a subclass that overrides `title`, `description` and `compareTo`.
|
|
97
|
+
|
|
98
|
+
## Features
|
|
99
|
+
|
|
100
|
+
### Atoms
|
|
101
|
+
|
|
102
|
+
| Component | Description |
|
|
103
|
+
| --------------------- | ---------------------------------------------------------------------------------------- |
|
|
104
|
+
| `RlsAmount` | Currency value split into integer and decimal tabular text, with an optional symbol |
|
|
105
|
+
| `RlsAreaText` | `textarea` that grows between `minRows` and `maxRows` and syncs with a control |
|
|
106
|
+
| `RlsAvatar` | Container for an image, initials or icon, with contrasted, rounded and skeleton variants |
|
|
107
|
+
| `RlsBadge` | Inline badge, contrasted when requested |
|
|
108
|
+
| `RlsBreadcrumb` | Row of labels, each one actionable when it declares `onClick` |
|
|
109
|
+
| `RlsButton` | Button of type `ghost`, `flat` or `raised`, with icons and a spinner while `requesting` |
|
|
110
|
+
| `RlsButtonAction` | Icon button with optional badge and tooltip |
|
|
111
|
+
| `RlsButtonIcon` | Icon button without decoration, with skeleton state |
|
|
112
|
+
| `RlsButtonOption` | Icon button that behaves as one option of a single selection over a control |
|
|
113
|
+
| `RlsCheckBox` | Checkbox mark driven by the `checked` prop |
|
|
114
|
+
| `RlsCheckBoxControl` | `RlsCheckBox` bound to a `boolean` control |
|
|
115
|
+
| `RlsHoverSwap` | Renders `children` and swaps it for `content` while the pointer is over it |
|
|
116
|
+
| `RlsIcon` | Renders the glyph `rls-icon-{value}`, with skeleton state |
|
|
117
|
+
| `RlsImage` | `img` that shows a skeleton until the source finishes loading |
|
|
118
|
+
| `RlsInput` | Base `input` that syncs value, focus and disabled with a control |
|
|
119
|
+
| `RlsInputCounter` | Number input with decrement and increment buttons, clamped by `min`, `max` and `step` |
|
|
120
|
+
| `RlsInputDecimal` | Number input for `BigDecimal` values that overlays the formatted amount |
|
|
121
|
+
| `RlsInputMoney` | Number input that overlays the value formatted as currency |
|
|
122
|
+
| `RlsInputNumber` | Number input that overlays the current value |
|
|
123
|
+
| `RlsInputPassword` | Input whose type switches between `password` and `text` |
|
|
124
|
+
| `RlsInputPercentage` | Number input that overlays the value followed by `%` |
|
|
125
|
+
| `RlsInputSearch` | Text input with a search action button |
|
|
126
|
+
| `RlsInputText` | Text input that overlays the current value |
|
|
127
|
+
| `RlsLabel` | Text label |
|
|
128
|
+
| `RlsLed` | Indicator whose background is set from a hexadecimal color |
|
|
129
|
+
| `RlsMessageIcon` | Icon followed by a truncated message |
|
|
130
|
+
| `RlsPoster` | Highlighted block of content, contrasted when requested |
|
|
131
|
+
| `RlsProgressBar` | Progress bar by `percentage` or indeterminate |
|
|
132
|
+
| `RlsProgressCircular` | Circular progress indicator drawn in SVG |
|
|
133
|
+
| `RlsRadioButton` | Radio mark driven by the `checked` prop |
|
|
134
|
+
| `RlsSkeleton` | Placeholder block while content is loading |
|
|
135
|
+
| `RlsSkeletonText` | Renders `children`, or a skeleton while `active` |
|
|
136
|
+
| `RlsSpinner` | Loading spinner drawn in SVG |
|
|
137
|
+
| `RlsSwitch` | Switch driven by the `checked` prop, with capsule variant |
|
|
138
|
+
| `RlsSwitchControl` | `RlsSwitch` bound to a `boolean` control |
|
|
139
|
+
| `RlsTabularText` | Renders each character in its own span, so digits keep a fixed width |
|
|
140
|
+
|
|
141
|
+
```tsx
|
|
142
|
+
import { RlsButton, RlsIcon, RlsPoster } from '@rolster/react-components';
|
|
143
|
+
|
|
144
|
+
function Header({ requesting, onSave }: HeaderProps) {
|
|
145
|
+
return (
|
|
146
|
+
<div className="header">
|
|
147
|
+
<RlsPoster rlsTheme="info">
|
|
148
|
+
<RlsIcon value="person" />
|
|
149
|
+
</RlsPoster>
|
|
150
|
+
|
|
151
|
+
<RlsButton
|
|
152
|
+
type="raised"
|
|
153
|
+
rlsTheme="success"
|
|
154
|
+
prefixIcon="checkmark"
|
|
155
|
+
requesting={requesting}
|
|
156
|
+
onClick={onSave}
|
|
157
|
+
>
|
|
158
|
+
Save
|
|
159
|
+
</RlsButton>
|
|
160
|
+
</div>
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Molecules
|
|
166
|
+
|
|
167
|
+
| Component | Description |
|
|
168
|
+
| ------------------------- | ---------------------------------------------------------------------------------------- |
|
|
169
|
+
| `RlsAccordion` | Collapsible section with title and indicator, animated on the height of its content |
|
|
170
|
+
| `RlsAlert` | Message block with optional icon and bordered variant |
|
|
171
|
+
| `RlsBallot` | Avatar, title and subtitle row, with skeleton state |
|
|
172
|
+
| `RlsBody` | Body container of an application page |
|
|
173
|
+
| `RlsButtonProgress` | Action button surrounded by a circular progress while `progressing` |
|
|
174
|
+
| `RlsButtonStepper` | Pair of buttons that emit a down and an up action |
|
|
175
|
+
| `RlsButtonToggle` | Action button with a second button that opens the list of `options` |
|
|
176
|
+
| `RlsContent` | Content container of an application page |
|
|
177
|
+
| `RlsFieldArea` | Labelled field over `RlsAreaText`, with an optional counter and its error message |
|
|
178
|
+
| `RlsFieldDecimal` | Labelled field over `RlsInputDecimal` with its error message |
|
|
179
|
+
| `RlsFieldFile` | Labelled field that opens a file selector and shows the name of the chosen file |
|
|
180
|
+
| `RlsFieldListSuggestions` | Suggestion list rendered in a portal, with optional search input, action and empty state |
|
|
181
|
+
| `RlsFieldMoney` | Labelled field over `RlsInputMoney` with its error message |
|
|
182
|
+
| `RlsFieldNumber` | Labelled field over `RlsInputNumber` with its error message |
|
|
183
|
+
| `RlsFieldPassword` | Labelled field over `RlsInputPassword` with a button that reveals the value |
|
|
184
|
+
| `RlsFieldPercentage` | Labelled field over `RlsInputPercentage` with its error message |
|
|
185
|
+
| `RlsFieldReadonly` | Labelled field that displays a value in a read only input |
|
|
186
|
+
| `RlsFieldText` | Labelled field over `RlsInputText` with its error message |
|
|
187
|
+
| `RlsLabelCheckBox` | Checkbox and text that toggle a `boolean` control |
|
|
188
|
+
| `RlsLabelRadioButton` | Radio and text that assign their `value` to a control |
|
|
189
|
+
| `RlsLabelSwitch` | Switch and text that toggle a `boolean` control |
|
|
190
|
+
| `RlsMessageEmpty` | Empty state with icon, emoji or image, title and content |
|
|
191
|
+
| `RlsMessageFormError` | Renders the translated error of a control while it is wrong |
|
|
192
|
+
| `RlsNavbar` | Navigation bar of an application page, with backdrop |
|
|
193
|
+
| `RlsNavbarMenu` | List of navigation options with icon and label |
|
|
194
|
+
| `RlsPagination` | Paginator over a collection that emits a `PaginationEvent` on every page |
|
|
195
|
+
| `RlsPickerDay` | Grid of the days of a month, restricted by `minDate` and `maxDate` |
|
|
196
|
+
| `RlsPickerDayRange` | Grid of the days of a month that highlights the selected range |
|
|
197
|
+
| `RlsPickerMonth` | Grid of the months of a year |
|
|
198
|
+
| `RlsPickerSelectorTitle` | Header with month and year, and buttons for previous and next |
|
|
199
|
+
| `RlsPickerYear` | Grid of years with navigation by decade |
|
|
200
|
+
| `RlsSlider` | Value selector over a track, operated with pointer and keyboard |
|
|
201
|
+
| `RlsTabs` | Tab bar that assigns the value of the selected tab to a control |
|
|
202
|
+
| `RlsToolbar` | Title, subtitle and list of actions |
|
|
203
|
+
|
|
204
|
+
```tsx
|
|
205
|
+
import { RlsFieldText, RlsLabelSwitch } from '@rolster/react-components';
|
|
206
|
+
import { useInputControl } from '@rolster/react-forms';
|
|
207
|
+
import { email, required } from '@rolster/validators/helpers';
|
|
208
|
+
|
|
209
|
+
function Account() {
|
|
210
|
+
const emailControl = useInputControl<string>('', [required, email]);
|
|
211
|
+
const notifyControl = useInputControl(true);
|
|
212
|
+
|
|
213
|
+
return (
|
|
214
|
+
<div className="account">
|
|
215
|
+
<RlsFieldText formControl={emailControl} placeholder="name@rolster.com">
|
|
216
|
+
Email
|
|
217
|
+
</RlsFieldText>
|
|
218
|
+
|
|
219
|
+
<RlsLabelSwitch formControl={notifyControl}>
|
|
220
|
+
Receive notifications by email
|
|
221
|
+
</RlsLabelSwitch>
|
|
222
|
+
</div>
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### Organisms
|
|
228
|
+
|
|
229
|
+
| Component | Description |
|
|
230
|
+
| -------------------------------- | -------------------------------------------------------------------------- |
|
|
231
|
+
| `RlsBottomSheet` | Panel anchored to the bottom of the screen, with backdrop |
|
|
232
|
+
| `RlsCard` | Content card, with outline variant |
|
|
233
|
+
| `RlsChooserAutocomplete` | Custom trigger that opens an autocomplete list of suggestions |
|
|
234
|
+
| `RlsChooserAutocompleteTemplate` | `RlsChooserAutocomplete` with every element rendered by `render` |
|
|
235
|
+
| `RlsChooserList` | Custom trigger that opens a multiple selection list |
|
|
236
|
+
| `RlsChooserListTemplate` | `RlsChooserList` with every element rendered by `render` |
|
|
237
|
+
| `RlsChooserSelect` | Custom trigger that opens a single selection list |
|
|
238
|
+
| `RlsChooserSelectTemplate` | `RlsChooserSelect` with every element rendered by `render` |
|
|
239
|
+
| `RlsConfirmation` | Confirmation dialog with approve and reject actions |
|
|
240
|
+
| `RlsDatatable` | Table with toolbar, header, summary and footer, resizable by its content |
|
|
241
|
+
| `RlsDatatableHeader` | Header row of the table |
|
|
242
|
+
| `RlsDatatableTitle` | Title cell of the header, with control, actions and truncated variants |
|
|
243
|
+
| `RlsDatatableSubheader` | Subheader row of the table |
|
|
244
|
+
| `RlsDatatableRecord` | Record row, with error, info, success, warning and truncated states |
|
|
245
|
+
| `RlsDatatableTotals` | Totals row of the table |
|
|
246
|
+
| `RlsDatatableCell` | Record cell, with control, actions and truncated variants |
|
|
247
|
+
| `RlsDatatableData` | Cell rendered as a block, for rows outside the table element |
|
|
248
|
+
| `RlsDatatableFloating` | Floating actions displayed over a record |
|
|
249
|
+
| `RlsDropdown` | Floating panel positioned by a `DropdownController` |
|
|
250
|
+
| `RlsFieldAutocomplete` | Field that filters its suggestions with the typed pattern |
|
|
251
|
+
| `RlsFieldAutocompleteTemplate` | `RlsFieldAutocomplete` with every element rendered by `render` |
|
|
252
|
+
| `RlsFieldClock` | Field that opens `RlsModalClock` and shows the selected `Time` |
|
|
253
|
+
| `RlsFieldColor` | Field that opens the color picker and shows the selected color |
|
|
254
|
+
| `RlsFieldDate` | Field that opens `RlsModalDate` and shows the date with the given `format` |
|
|
255
|
+
| `RlsFieldDateRange` | Field that opens `RlsModalDateRange` and shows the selected `DateRange` |
|
|
256
|
+
| `RlsFieldList` | Multiple selection field that renders the selected values as chips |
|
|
257
|
+
| `RlsFieldListTemplate` | `RlsFieldList` with every element rendered by `render` |
|
|
258
|
+
| `RlsFieldSelect` | Single selection field over a list of suggestions |
|
|
259
|
+
| `RlsFieldSelectTemplate` | `RlsFieldSelect` with every element rendered by `render` |
|
|
260
|
+
| `RlsFormNavigation` | Navigation panel that slides over a form |
|
|
261
|
+
| `RlsImageChooser` | Avatar that opens the file selector and the image editor |
|
|
262
|
+
| `RlsImageEditor` | Image editor with zoom, crop by ratio and export to `ImageEditorValue` |
|
|
263
|
+
| `RlsModal` | Modal window with backdrop |
|
|
264
|
+
| `RlsModalClock` | Modal that hosts `RlsPickerClock` |
|
|
265
|
+
| `RlsModalDate` | Modal that hosts `RlsPickerDate` |
|
|
266
|
+
| `RlsModalDateRange` | Modal that hosts `RlsPickerDateRange` |
|
|
267
|
+
| `RlsModalSheet` | Modal displayed as a sheet, with backdrop |
|
|
268
|
+
| `RlsPickerClock` | Analog clock to select hour, minute and zone |
|
|
269
|
+
| `RlsPickerColor` | Color picker with saturation canvas, hue, alpha and hexadecimal input |
|
|
270
|
+
| `RlsPickerDate` | Calendar with day, month and year views |
|
|
271
|
+
| `RlsPickerDateRange` | Calendar that selects a range of dates |
|
|
272
|
+
| `RlsSnackbar` | Snackbar with icon, title and content |
|
|
273
|
+
|
|
274
|
+
```tsx
|
|
275
|
+
import { RolsterListElement } from '@rolster/components';
|
|
276
|
+
import { RlsFieldSelect } from '@rolster/react-components';
|
|
277
|
+
import { useFormControl } from '@rolster/react-forms';
|
|
278
|
+
|
|
279
|
+
class PersonElement extends RolsterListElement<Person> {
|
|
280
|
+
public override get title(): string {
|
|
281
|
+
return this.value.name;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function Assignment({ persons }: { persons: Person[] }) {
|
|
286
|
+
const personControl = useFormControl<Person>();
|
|
287
|
+
|
|
288
|
+
const suggestions = persons.map((person) => new PersonElement(person));
|
|
289
|
+
|
|
290
|
+
return (
|
|
291
|
+
<RlsFieldSelect
|
|
292
|
+
formControl={personControl}
|
|
293
|
+
suggestions={suggestions}
|
|
294
|
+
placeholder="Select a person"
|
|
295
|
+
>
|
|
296
|
+
Assigned person
|
|
297
|
+
</RlsFieldSelect>
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
### Hooks
|
|
303
|
+
|
|
304
|
+
| Hook | Description |
|
|
305
|
+
| ---------------------------------------------------- | ------------------------------------------------------------------------------------- |
|
|
306
|
+
| `useRlsContext(): RlsState` | Reads the context of `RlsApplication`; throws when the wrapper is missing |
|
|
307
|
+
| `useConfirmation(): ConfirmationService` | Creates the `confirmation` function and the `RlsConfirmation` node that renders it |
|
|
308
|
+
| `useNotifications(): NotificationsService` | Creates the `notify` function and the `RlsNotifications` node with the stack |
|
|
309
|
+
| `useSnackbar(): SnackbarService` | Creates the `snackbar` function and the `RlsSnackbar` node that renders it |
|
|
310
|
+
| `useFieldAutocomplete(props)` | State of an autocomplete field: coincidences, pattern, references and event handlers |
|
|
311
|
+
| `useFieldList(props)` | State of a multiple selection field: selected elements, references and event handlers |
|
|
312
|
+
| `useFieldSelect(props)` | State of a single selection field: value, references and event handlers |
|
|
313
|
+
| `useListController(props)` | Base of the previous ones: visibility, keyboard navigation and writing to the control |
|
|
314
|
+
| `useDatatable(table?): DatatableController` | Observes the body of a table and reports whether it is scrollable |
|
|
315
|
+
| `useDesingSystemController(primary?, secondary?)` | Applies a design system and toggles between two of them |
|
|
316
|
+
| `useDropdownController(effect?): DropdownController` | Opens a `RlsDropdown` at a position or from a mouse event |
|
|
317
|
+
| `usePortalController(): PortalController` | Visibility of modals, sheets and navigation panels |
|
|
318
|
+
| `useTabsController(options): TabsController` | Creates the control of a tab bar and the `Tabs` node bound to it |
|
|
319
|
+
| `useImageEditorController(options)` | Opens the file selector and the image editor, and returns the node that renders them |
|
|
320
|
+
| `useFormSingleSelectionController(props)` | `checked` state and selection of a value over a control |
|
|
321
|
+
| `useFormToggleController(props)` | `checked` state and toggle of a `boolean` control |
|
|
322
|
+
| `useResize({ refElement, onResize })` | Reports the dimensions of an element when it changes size |
|
|
323
|
+
| `useRelocationOnComponent({ container, element })` | Allows dragging an element inside its container |
|
|
324
|
+
| `useEventCallback(callback)` | Returns a stable function that always calls the last received callback |
|
|
325
|
+
|
|
326
|
+
```tsx
|
|
327
|
+
import { RlsButton, useRlsContext } from '@rolster/react-components';
|
|
328
|
+
|
|
329
|
+
function DeleteAction({ person }: { person: Person }) {
|
|
330
|
+
const { confirmation, snackbar } = useRlsContext();
|
|
331
|
+
|
|
332
|
+
const onDelete = async () => {
|
|
333
|
+
const result = await confirmation({
|
|
334
|
+
title: 'Delete person',
|
|
335
|
+
content: <p>{person.name} will be removed from the system.</p>,
|
|
336
|
+
approved: { label: 'Delete', rlsTheme: 'danger' },
|
|
337
|
+
reject: { label: 'Cancel' }
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
result.when({
|
|
341
|
+
approved: () => {
|
|
342
|
+
snackbar({ icon: 'checkmark', title: 'Person deleted' });
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
return (
|
|
348
|
+
<RlsButton type="flat" rlsTheme="danger" onClick={onDelete}>
|
|
349
|
+
Delete
|
|
350
|
+
</RlsButton>
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
### Theme and design system
|
|
356
|
+
|
|
357
|
+
The application theme is written on the `app-theme` attribute of `document.body`, and the colors of a theme are written as custom properties on that same element.
|
|
358
|
+
|
|
359
|
+
| Function | Description |
|
|
360
|
+
| ---------------------------------------- | ---------------------------------------------------------------------------- |
|
|
361
|
+
| `getAppTheme(): RlsAppTheme` | Current theme, `light` when nothing has been set |
|
|
362
|
+
| `setAppTheme(theme)` | Writes `light` or `dark` on the application body |
|
|
363
|
+
| `toggleAppTheme(): RlsAppTheme` | Switches between `light` and `dark`, and returns the applied theme |
|
|
364
|
+
| `setDesignSystem(designSystem?)` | Writes the class of the design system on the body and removes the other ones |
|
|
365
|
+
| `generateThemePalette(color, theme?)` | Builds a `ThemePalette` of eleven shades from a hexadecimal color |
|
|
366
|
+
| `setThemeColor(color, theme?)` | Writes the properties of `generateThemePalette` on the application body |
|
|
367
|
+
| `setErrorsI18n(dictionary)` | Merges a dictionary into the validation messages of `RlsMessageFormError` |
|
|
368
|
+
| `getRemSize(): number` | Font size of the document root in pixels, `16` when it cannot be read |
|
|
369
|
+
| `renderClassStatus(base, status?, add?)` | Builds the class list of a component from a status object |
|
|
370
|
+
| `rangeFormatTemplate(dateRange)` | Formats a `DateRange` as `{dd}/{mx}/{yy} - {dd}/{mx}/{yy}` |
|
|
371
|
+
| `calculateImgDimension(image, size)` | Dimensions of an image reduced to a maximum size, keeping its proportion |
|
|
372
|
+
|
|
373
|
+
Conversion between hexadecimal, RGB, HSV and HSL colors:
|
|
374
|
+
|
|
375
|
+
| Function | Description |
|
|
376
|
+
| ---------------------------------------------------------------------- | ------------------------------------------------------------- |
|
|
377
|
+
| `hexToRgb`, `hexToHsv`, `hexToHsl` | Convert a hexadecimal color; return `null` when it is invalid |
|
|
378
|
+
| `rgbToHex`, `rgbToHsv`, `rgbToHsl`, `hsvToRgb`, `hsvToHex`, `hslToHex` | Convert between the color models |
|
|
379
|
+
| `hexIsValid`, `normalizeHex` | Validate a hexadecimal color and expand it to `#RRGGBB` |
|
|
380
|
+
|
|
381
|
+
The constants `RlsContext`, the React context consumed by `useRlsContext`, and `DEFAULT_COLOR`, the base color `#1780e0` of the palette, are also exported.
|
|
382
|
+
|
|
383
|
+
```ts
|
|
384
|
+
import {
|
|
385
|
+
setDesignSystem,
|
|
386
|
+
setThemeColor,
|
|
387
|
+
toggleAppTheme
|
|
388
|
+
} from '@rolster/react-components';
|
|
389
|
+
|
|
390
|
+
setDesignSystem('gradient');
|
|
391
|
+
setThemeColor('#1780e0', 'primary');
|
|
392
|
+
|
|
393
|
+
toggleAppTheme(); // 'dark'
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
### Types
|
|
397
|
+
|
|
398
|
+
| Type | Description |
|
|
399
|
+
| -------------------------------- | ------------------------------------------------------------------------------- |
|
|
400
|
+
| `RlsTheme` | Color theme of a component, applied with the `rlsTheme` prop |
|
|
401
|
+
| `RlsAppTheme` | Application theme, `light` or `dark` |
|
|
402
|
+
| `RlsDesignSystem` | Design system, `bordered`, `filled` or `gradient` |
|
|
403
|
+
| `RlsButtonType` | Button style, `ghost`, `flat` or `raised` |
|
|
404
|
+
| `PropsWithClassName` | Props with an optional `className` |
|
|
405
|
+
| `PropsWithRlsTheme` | Props with an optional `rlsTheme` |
|
|
406
|
+
| `RlsComponent` | Base props of a component: `children`, `className`, `identifier` and `rlsTheme` |
|
|
407
|
+
| `InputProps<T>` | Props of an input: value, control, state and events |
|
|
408
|
+
| `FieldProps<T>` | `InputProps` plus `action`, `groupModeEnabled` and `msgErrorDisabled` |
|
|
409
|
+
| `RolsterReactInputControl<T>` | Control of an `input`, with or without an undefined value |
|
|
410
|
+
| `RolsterReactAreaTextControl<T>` | Control of a `textarea`, with or without an undefined value |
|
|
411
|
+
| `Confirmation` | Function that opens the dialog and resolves with a `ConfirmationResult` |
|
|
412
|
+
| `ConfirmationResult` | Result of the dialog, resolved as `approved` or `reject` |
|
|
413
|
+
| `SnackbarConfig` | Configuration of a snackbar: `icon`, `title`, `content` and `rlsTheme` |
|
|
414
|
+
| `NotificationsConfig` | Configuration of a notification, a `SnackbarConfig` plus `duration` |
|
|
415
|
+
| `PaginationEvent<T>` | Event of `RlsPagination`: page, limits and suggestions of the page |
|
|
416
|
+
| `Tab<T>` | Tab of `RlsTabs`: label, value and disabled state |
|
|
417
|
+
| `NavbarMenuOption` | Option of `RlsNavbarMenu`: identifier, icon and label |
|
|
418
|
+
| `ImageEditorValue` | Result of the image editor: `base64` and `blob` |
|
|
419
|
+
| `ThemePalette` | Palette generated for a theme: shades, custom properties and CSS |
|
|
420
|
+
| `HSV`, `RGB`, `HSL` | Color models used by the conversion functions |
|
|
421
|
+
|
|
21
422
|
## Contributing
|
|
22
423
|
|
|
23
424
|
- Daniel Andrés Castillo Pedroza :rocket:
|