@vitus-labs/elements 1.2.2 → 1.2.3-alpha.3
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 +1 -1
- package/README.md +279 -66
- package/lib/analysis/index.js.html +18 -18
- package/lib/analysis/vitus-labs-elements.native.js.html +18 -18
- package/lib/index.d.ts +832 -849
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +1290 -1160
- package/lib/index.js.map +1 -1
- package/lib/vitus-labs-elements.native.js +1176 -1060
- package/lib/vitus-labs-elements.native.js.map +1 -1
- package/package.json +23 -23
- package/lib/types/Element/component.d.ts +0 -4
- package/lib/types/Element/component.d.ts.map +0 -1
- package/lib/types/Element/constants.d.ts +0 -51
- package/lib/types/Element/constants.d.ts.map +0 -1
- package/lib/types/Element/index.d.ts +0 -7
- package/lib/types/Element/index.d.ts.map +0 -1
- package/lib/types/Element/types.d.ts +0 -423
- package/lib/types/Element/types.d.ts.map +0 -1
- package/lib/types/Element/utils.d.ts +0 -5
- package/lib/types/Element/utils.d.ts.map +0 -1
- package/lib/types/Element/withEqualSizeBeforeAfter.d.ts +0 -8
- package/lib/types/Element/withEqualSizeBeforeAfter.d.ts.map +0 -1
- package/lib/types/List/component.d.ts +0 -23
- package/lib/types/List/component.d.ts.map +0 -1
- package/lib/types/List/index.d.ts +0 -7
- package/lib/types/List/index.d.ts.map +0 -1
- package/lib/types/List/withActiveState.d.ts +0 -11
- package/lib/types/List/withActiveState.d.ts.map +0 -1
- package/lib/types/Overlay/component.d.ts +0 -52
- package/lib/types/Overlay/component.d.ts.map +0 -1
- package/lib/types/Overlay/context.d.ts +0 -12
- package/lib/types/Overlay/context.d.ts.map +0 -1
- package/lib/types/Overlay/index.d.ts +0 -7
- package/lib/types/Overlay/index.d.ts.map +0 -1
- package/lib/types/Overlay/useOverlay.d.ts +0 -109
- package/lib/types/Overlay/useOverlay.d.ts.map +0 -1
- package/lib/types/Portal/component.d.ts +0 -20
- package/lib/types/Portal/component.d.ts.map +0 -1
- package/lib/types/Portal/index.d.ts +0 -5
- package/lib/types/Portal/index.d.ts.map +0 -1
- package/lib/types/Text/component.d.ts +0 -30
- package/lib/types/Text/component.d.ts.map +0 -1
- package/lib/types/Text/index.d.ts +0 -5
- package/lib/types/Text/index.d.ts.map +0 -1
- package/lib/types/Text/styled.d.ts +0 -3
- package/lib/types/Text/styled.d.ts.map +0 -1
- package/lib/types/Util/component.d.ts +0 -19
- package/lib/types/Util/component.d.ts.map +0 -1
- package/lib/types/Util/index.d.ts +0 -5
- package/lib/types/Util/index.d.ts.map +0 -1
- package/lib/types/constants.d.ts +0 -2
- package/lib/types/constants.d.ts.map +0 -1
- package/lib/types/helpers/Content/component.d.ts +0 -5
- package/lib/types/helpers/Content/component.d.ts.map +0 -1
- package/lib/types/helpers/Content/index.d.ts +0 -3
- package/lib/types/helpers/Content/index.d.ts.map +0 -1
- package/lib/types/helpers/Content/styled.d.ts +0 -3
- package/lib/types/helpers/Content/styled.d.ts.map +0 -1
- package/lib/types/helpers/Content/types.d.ts +0 -31
- package/lib/types/helpers/Content/types.d.ts.map +0 -1
- package/lib/types/helpers/Iterator/component.d.ts +0 -10
- package/lib/types/helpers/Iterator/component.d.ts.map +0 -1
- package/lib/types/helpers/Iterator/index.d.ts +0 -5
- package/lib/types/helpers/Iterator/index.d.ts.map +0 -1
- package/lib/types/helpers/Iterator/types.d.ts +0 -60
- package/lib/types/helpers/Iterator/types.d.ts.map +0 -1
- package/lib/types/helpers/Wrapper/component.d.ts +0 -5
- package/lib/types/helpers/Wrapper/component.d.ts.map +0 -1
- package/lib/types/helpers/Wrapper/constants.d.ts +0 -6
- package/lib/types/helpers/Wrapper/constants.d.ts.map +0 -1
- package/lib/types/helpers/Wrapper/index.d.ts +0 -3
- package/lib/types/helpers/Wrapper/index.d.ts.map +0 -1
- package/lib/types/helpers/Wrapper/styled.d.ts +0 -3
- package/lib/types/helpers/Wrapper/styled.d.ts.map +0 -1
- package/lib/types/helpers/Wrapper/types.d.ts +0 -42
- package/lib/types/helpers/Wrapper/types.d.ts.map +0 -1
- package/lib/types/helpers/Wrapper/utils.d.ts +0 -4
- package/lib/types/helpers/Wrapper/utils.d.ts.map +0 -1
- package/lib/types/helpers/index.d.ts +0 -4
- package/lib/types/helpers/index.d.ts.map +0 -1
- package/lib/types/index.d.ts +0 -18
- package/lib/types/index.d.ts.map +0 -1
- package/lib/types/types.d.ts +0 -51
- package/lib/types/types.d.ts.map +0 -1
- package/lib/types/utils.d.ts +0 -2
- package/lib/types/utils.d.ts.map +0 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,100 +1,313 @@
|
|
|
1
|
-
|
|
2
|
-
<a href="https://vitus-labs.com/docs/ui-system/elements">
|
|
3
|
-
<img src="https://github.com/vitus-labs/ui-system/blob/master/packages/elements/logo.png" alt="Elements" height="150" />
|
|
4
|
-
</a>
|
|
5
|
-
</div>
|
|
1
|
+
# @vitus-labs/elements
|
|
6
2
|
|
|
7
|
-
|
|
3
|
+
Layout primitives for React with responsive props.
|
|
8
4
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
and again. Elements are a package of patterns that should cover very
|
|
12
|
-
common and frequent use-cases, so you don't have to repeat yourself
|
|
13
|
-
again and again.
|
|
5
|
+
[](https://www.npmjs.com/package/@vitus-labs/elements)
|
|
6
|
+
[](https://github.com/vitus-labs/ui-system/blob/main/LICENSE)
|
|
14
7
|
|
|
15
|
-
|
|
8
|
+
Five composable components for building buttons, cards, lists, dropdowns, tooltips, and modals. Every layout prop is responsive — pass a single value, a mobile-first array, or a breakpoint object.
|
|
16
9
|
|
|
17
|
-
##
|
|
10
|
+
## Features
|
|
18
11
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
12
|
+
- **Element** — three-section flex layout (beforeContent / content / afterContent)
|
|
13
|
+
- **Text** — semantic text rendering with auto paragraph wrapping
|
|
14
|
+
- **List** — data-driven rendering with positional metadata (first, last, odd, even)
|
|
15
|
+
- **Overlay** — portal-based positioning for dropdowns, tooltips, and modals with auto-flip
|
|
16
|
+
- **Portal** — React Portal wrapper for DOM appending
|
|
17
|
+
- **Util** — non-rendering utility for injecting className and style
|
|
18
|
+
- **Responsive everything** — single value, array, or breakpoint object on every layout prop
|
|
19
|
+
- **Selection state** — `withActiveState` HOC for single/multi item selection on List
|
|
24
20
|
|
|
25
|
-
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install @vitus-labs/elements @vitus-labs/core @vitus-labs/unistyle styled-components
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Components
|
|
26
28
|
|
|
27
29
|
### Element
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
This might help add some additional elements like loading icon to button, input
|
|
31
|
-
element symbol, or validation element. Which leads to repeatable patterns.
|
|
32
|
-
All these things and much more can be covered by this component.
|
|
31
|
+
The core layout primitive. Renders a three-section flex container with optional beforeContent and afterContent slots around the main content.
|
|
33
32
|
|
|
34
|
-
|
|
33
|
+
```tsx
|
|
34
|
+
import { Element } from '@vitus-labs/elements'
|
|
35
|
+
|
|
36
|
+
// Simple button with icon before and chevron after
|
|
37
|
+
<Element
|
|
38
|
+
tag="button"
|
|
39
|
+
beforeContent={<Icon name="star" />}
|
|
40
|
+
afterContent={<Icon name="chevron-right" />}
|
|
41
|
+
direction="inline"
|
|
42
|
+
alignX="center"
|
|
43
|
+
alignY="center"
|
|
44
|
+
gap={8}
|
|
45
|
+
>
|
|
46
|
+
Click me
|
|
47
|
+
</Element>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
When only content is present (no beforeContent/afterContent), Element optimizes by skipping the inner wrapper layer.
|
|
51
|
+
|
|
52
|
+
**Content props** (rendered in priority order: children > content > label):
|
|
53
|
+
|
|
54
|
+
| Prop | Type | Description |
|
|
55
|
+
| ---- | ---- | ----------- |
|
|
56
|
+
| children | `ReactNode` | Standard React children |
|
|
57
|
+
| content | `ReactNode` | Alternative to children |
|
|
58
|
+
| label | `ReactNode` | Alternative to children/content |
|
|
59
|
+
| beforeContent | `ReactNode` | Content rendered before the main slot |
|
|
60
|
+
| afterContent | `ReactNode` | Content rendered after the main slot |
|
|
61
|
+
|
|
62
|
+
**Layout props** (all responsive):
|
|
63
|
+
|
|
64
|
+
| Prop | Type | Default | Description |
|
|
65
|
+
| ---- | ---- | ------- | ----------- |
|
|
66
|
+
| tag | `HTMLTags` | `'div'` | HTML element tag |
|
|
67
|
+
| block | `boolean` | — | `flex` vs `inline-flex` |
|
|
68
|
+
| direction | `Direction` | `'inline'` | `'inline'` \| `'rows'` \| `'reverseInline'` \| `'reverseRows'` |
|
|
69
|
+
| alignX | `AlignX` | `'left'` | Horizontal alignment |
|
|
70
|
+
| alignY | `AlignY` | `'center'` | Vertical alignment |
|
|
71
|
+
| gap | `number` | — | Gap between content sections |
|
|
72
|
+
| equalCols | `boolean` | — | Equal width/height for before/after |
|
|
73
|
+
|
|
74
|
+
Each section (content, beforeContent, afterContent) has its own direction, alignX, and alignY props prefixed with the section name:
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
<Element
|
|
78
|
+
contentDirection="rows"
|
|
79
|
+
contentAlignX="center"
|
|
80
|
+
beforeContentAlignY="top"
|
|
81
|
+
afterContentDirection="inline"
|
|
82
|
+
/>
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
**CSS extension props:**
|
|
35
86
|
|
|
36
|
-
|
|
37
|
-
|
|
87
|
+
| Prop | Description |
|
|
88
|
+
| ---- | ----------- |
|
|
89
|
+
| css | Extend root wrapper styling |
|
|
90
|
+
| contentCss | Extend content wrapper styling |
|
|
91
|
+
| beforeContentCss | Extend beforeContent wrapper styling |
|
|
92
|
+
| afterContentCss | Extend afterContent wrapper styling |
|
|
93
|
+
|
|
94
|
+
CSS props accept strings, template literals, `css` tagged templates, or callbacks.
|
|
38
95
|
|
|
39
96
|
### Text
|
|
40
97
|
|
|
41
|
-
|
|
98
|
+
Semantic text component with optional paragraph auto-wrapping.
|
|
99
|
+
|
|
100
|
+
```tsx
|
|
101
|
+
import { Text } from '@vitus-labs/elements'
|
|
102
|
+
|
|
103
|
+
<Text tag="h1">Heading</Text>
|
|
104
|
+
<Text paragraph>This renders as a p tag.</Text>
|
|
105
|
+
<Text tag="strong" label="Bold text" />
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
| Prop | Type | Description |
|
|
109
|
+
| ---- | ---- | ----------- |
|
|
110
|
+
| tag | `HTMLTextTags` | `'h1'`–`'h6'`, `'p'`, `'span'`, `'strong'`, `'em'`, etc. |
|
|
111
|
+
| paragraph | `boolean` | Shorthand for `tag="p"` |
|
|
112
|
+
| children / label | `ReactNode` | Text content |
|
|
113
|
+
| css | `ExtendCss` | Extend styling |
|
|
114
|
+
|
|
115
|
+
### List
|
|
116
|
+
|
|
117
|
+
Data-driven list renderer with Iterator pattern.
|
|
118
|
+
|
|
119
|
+
```tsx
|
|
120
|
+
import { List, Element } from '@vitus-labs/elements'
|
|
121
|
+
|
|
122
|
+
// Simple string data
|
|
123
|
+
<List
|
|
124
|
+
component={Element}
|
|
125
|
+
data={['Apple', 'Banana', 'Cherry']}
|
|
126
|
+
valueName="label"
|
|
127
|
+
/>
|
|
128
|
+
|
|
129
|
+
// Object data with positional metadata
|
|
130
|
+
<List
|
|
131
|
+
component={ListItem}
|
|
132
|
+
data={[{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }]}
|
|
133
|
+
itemKey="id"
|
|
134
|
+
itemProps={(item, { first, last, odd, even, index }) => ({
|
|
135
|
+
highlighted: first,
|
|
136
|
+
separator: !last,
|
|
137
|
+
})}
|
|
138
|
+
/>
|
|
139
|
+
|
|
140
|
+
// With root Element wrapper
|
|
141
|
+
<List
|
|
142
|
+
rootElement
|
|
143
|
+
direction="rows"
|
|
144
|
+
gap={8}
|
|
145
|
+
component={Card}
|
|
146
|
+
data={items}
|
|
147
|
+
/>
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
| Prop | Type | Description |
|
|
151
|
+
| ---- | ---- | ----------- |
|
|
152
|
+
| data | `Array` | Array of strings, numbers, or objects |
|
|
153
|
+
| component | `ComponentType` | Component to render for each item |
|
|
154
|
+
| valueName | `string` | Prop name for scalar values (default: `'children'`) |
|
|
155
|
+
| itemKey | `string \| function` | Key extraction for list items |
|
|
156
|
+
| itemProps | `object \| function` | Extra props injected into each item |
|
|
157
|
+
| wrapComponent | `ComponentType` | Wrapper around each item |
|
|
158
|
+
| rootElement | `boolean` | Wrap list in an Element (enables direction, gap, etc.) |
|
|
159
|
+
|
|
160
|
+
**Positional metadata** passed to `itemProps` callback:
|
|
161
|
+
|
|
162
|
+
`index`, `first`, `last`, `odd`, `even`, `position` (1-based)
|
|
163
|
+
|
|
164
|
+
### withActiveState
|
|
165
|
+
|
|
166
|
+
HOC that adds selection state management to List.
|
|
167
|
+
|
|
168
|
+
```tsx
|
|
169
|
+
import { List, withActiveState } from '@vitus-labs/elements'
|
|
170
|
+
|
|
171
|
+
const SelectableList = withActiveState(List)
|
|
172
|
+
|
|
173
|
+
<SelectableList
|
|
174
|
+
type="single"
|
|
175
|
+
component={ListItem}
|
|
176
|
+
data={items}
|
|
177
|
+
activeItems="item-1"
|
|
178
|
+
/>
|
|
179
|
+
|
|
180
|
+
<SelectableList
|
|
181
|
+
type="multi"
|
|
182
|
+
component={ListItem}
|
|
183
|
+
data={items}
|
|
184
|
+
activeItems={['item-1', 'item-3']}
|
|
185
|
+
activeItemRequired
|
|
186
|
+
/>
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Each item receives: `active`, `handleItemActive`, `setItemActive`, `unsetItemActive`, `toggleItemActive`.
|
|
42
190
|
|
|
43
191
|
### Overlay
|
|
44
192
|
|
|
45
|
-
|
|
46
|
-
tooltips, popovers, etc. It's quite configurable so you can align elements
|
|
47
|
-
the way you like without any extra effort.
|
|
193
|
+
Portal-based overlay with intelligent positioning and event management.
|
|
48
194
|
|
|
49
|
-
|
|
195
|
+
```tsx
|
|
196
|
+
import { Overlay } from '@vitus-labs/elements'
|
|
50
197
|
|
|
51
|
-
|
|
198
|
+
// Dropdown
|
|
199
|
+
<Overlay
|
|
200
|
+
openOn="click"
|
|
201
|
+
closeOn="clickOutsideContent"
|
|
202
|
+
align="bottom"
|
|
203
|
+
alignX="left"
|
|
204
|
+
trigger={<Button label="Open menu" />}
|
|
205
|
+
>
|
|
206
|
+
<DropdownMenu />
|
|
207
|
+
</Overlay>
|
|
52
208
|
|
|
53
|
-
|
|
209
|
+
// Tooltip
|
|
210
|
+
<Overlay
|
|
211
|
+
openOn="hover"
|
|
212
|
+
closeOn="hover"
|
|
213
|
+
align="top"
|
|
214
|
+
alignX="center"
|
|
215
|
+
offsetY={8}
|
|
216
|
+
trigger={<span>Hover me</span>}
|
|
217
|
+
>
|
|
218
|
+
<Tooltip>Helpful text</Tooltip>
|
|
219
|
+
</Overlay>
|
|
220
|
+
```
|
|
54
221
|
|
|
55
|
-
|
|
222
|
+
| Prop | Type | Default | Description |
|
|
223
|
+
| ---- | ---- | ------- | ----------- |
|
|
224
|
+
| trigger | `ReactNode \| function` | — | The triggering element |
|
|
225
|
+
| children | `ReactNode \| function` | — | Overlay content |
|
|
226
|
+
| openOn | `'click' \| 'hover' \| 'manual'` | `'click'` | How to open |
|
|
227
|
+
| closeOn | `'click' \| 'clickOnTrigger' \| 'clickOutsideContent' \| 'hover' \| 'manual'` | `'click'` | How to close |
|
|
228
|
+
| type | `'dropdown' \| 'tooltip' \| 'popover' \| 'modal' \| 'custom'` | — | Positioning preset |
|
|
229
|
+
| align | `'top' \| 'bottom' \| 'left' \| 'right'` | — | Primary alignment relative to trigger |
|
|
230
|
+
| alignX | `'left' \| 'center' \| 'right'` | — | Horizontal alignment |
|
|
231
|
+
| alignY | `'top' \| 'center' \| 'bottom'` | — | Vertical alignment |
|
|
232
|
+
| offsetX / offsetY | `number` | `0` | Margin from trigger |
|
|
233
|
+
| closeOnEsc | `boolean` | `true` | Close on Escape key |
|
|
234
|
+
| disabled | `boolean` | `false` | Disable open/close |
|
|
235
|
+
| onOpen / onClose | `() => void` | — | Lifecycle callbacks |
|
|
56
236
|
|
|
57
|
-
|
|
58
|
-
# with yarn
|
|
59
|
-
yarn add @vitus-labs/elements @vitus-labs/core
|
|
237
|
+
Overlay auto-flips when content hits the viewport edge. Positioning is throttled for performance.
|
|
60
238
|
|
|
61
|
-
|
|
62
|
-
|
|
239
|
+
When trigger or children are render functions, they receive callbacks:
|
|
240
|
+
|
|
241
|
+
```tsx
|
|
242
|
+
<Overlay
|
|
243
|
+
openOn="manual"
|
|
244
|
+
trigger={({ showContent, active, ref }) => (
|
|
245
|
+
<button ref={ref} onClick={showContent}>
|
|
246
|
+
{active ? 'Close' : 'Open'}
|
|
247
|
+
</button>
|
|
248
|
+
)}
|
|
249
|
+
>
|
|
250
|
+
{({ hideContent, align, ref }) => (
|
|
251
|
+
<div ref={ref}>
|
|
252
|
+
<button onClick={hideContent}>Close</button>
|
|
253
|
+
</div>
|
|
254
|
+
)}
|
|
255
|
+
</Overlay>
|
|
63
256
|
```
|
|
64
257
|
|
|
65
|
-
|
|
258
|
+
### Portal
|
|
66
259
|
|
|
67
|
-
|
|
260
|
+
React Portal wrapper for appending content to a specific DOM location.
|
|
68
261
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
| react | >= 16.7 |
|
|
72
|
-
| @vitus-labs/core | same version |
|
|
262
|
+
```tsx
|
|
263
|
+
import { Portal } from '@vitus-labs/elements'
|
|
73
264
|
|
|
74
|
-
|
|
265
|
+
<Portal>
|
|
266
|
+
<div>Rendered at document.body</div>
|
|
267
|
+
</Portal>
|
|
75
268
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
import Loading from './any-react-component'
|
|
80
|
-
|
|
81
|
-
const Element = () => (
|
|
82
|
-
<Element
|
|
83
|
-
tag="button"
|
|
84
|
-
label="This is a label"
|
|
85
|
-
contentAlignX="left"
|
|
86
|
-
contentAlignY="center"
|
|
87
|
-
beforeContent={Loading}
|
|
88
|
-
/>
|
|
89
|
-
)
|
|
269
|
+
<Portal DOMLocation={document.getElementById('modal-root')}>
|
|
270
|
+
<div>Rendered at #modal-root</div>
|
|
271
|
+
</Portal>
|
|
90
272
|
```
|
|
91
273
|
|
|
92
|
-
|
|
93
|
-
import React from 'react'
|
|
94
|
-
import { List, Element } from '@vitus-labs/elements'
|
|
274
|
+
### Util
|
|
95
275
|
|
|
96
|
-
|
|
97
|
-
|
|
276
|
+
Non-rendering utility that injects className and style into its child.
|
|
277
|
+
|
|
278
|
+
```tsx
|
|
279
|
+
import { Util } from '@vitus-labs/elements'
|
|
280
|
+
|
|
281
|
+
<Util className="custom-class" style={{ color: 'red' }}>
|
|
282
|
+
<div>Receives className and style props</div>
|
|
283
|
+
</Util>
|
|
98
284
|
```
|
|
99
285
|
|
|
100
|
-
|
|
286
|
+
## Responsive Values
|
|
287
|
+
|
|
288
|
+
Every layout prop (direction, alignX, alignY, gap, block, equalCols) supports three formats:
|
|
289
|
+
|
|
290
|
+
```tsx
|
|
291
|
+
// Single value — all breakpoints
|
|
292
|
+
<Element direction="inline" />
|
|
293
|
+
|
|
294
|
+
// Array — mobile-first, maps to breakpoints by position
|
|
295
|
+
<Element direction={['rows', 'inline']} />
|
|
296
|
+
|
|
297
|
+
// Object — explicit breakpoints
|
|
298
|
+
<Element direction={{ xs: 'rows', md: 'inline', lg: 'inline' }} />
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
## Peer Dependencies
|
|
302
|
+
|
|
303
|
+
| Package | Version |
|
|
304
|
+
| ------- | ------- |
|
|
305
|
+
| react | >= 19 |
|
|
306
|
+
| react-dom | >= 19 |
|
|
307
|
+
| @vitus-labs/core | * |
|
|
308
|
+
| @vitus-labs/unistyle | * |
|
|
309
|
+
| styled-components | >= 6 |
|
|
310
|
+
|
|
311
|
+
## License
|
|
312
|
+
|
|
313
|
+
MIT
|