@granularjs/ui 0.1.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/README.md +116 -0
- package/dist/fonts/Arimo-400.ttf +0 -0
- package/dist/fonts/Arimo-500.ttf +1449 -0
- package/dist/fonts/Arimo-600.ttf +1449 -0
- package/dist/fonts/Arimo-700.ttf +0 -0
- package/dist/fonts/Inter-400.woff2 +0 -0
- package/dist/fonts/Inter-500.woff2 +0 -0
- package/dist/fonts/Inter-600.woff2 +0 -0
- package/dist/fonts/Inter-700.woff2 +0 -0
- package/dist/fonts/Poppins-400.ttf +0 -0
- package/dist/fonts/Poppins-500.ttf +0 -0
- package/dist/fonts/Poppins-600.ttf +0 -0
- package/dist/fonts/Poppins-700.ttf +0 -0
- package/dist/granular-ui.min.js +3605 -0
- package/dist/granular-ui.min.js.map +7 -0
- package/package.json +55 -0
- package/src/components/Accordion.js +25 -0
- package/src/components/ActionIcon.js +20 -0
- package/src/components/Affix.js +11 -0
- package/src/components/Alert.js +33 -0
- package/src/components/Anchor.js +8 -0
- package/src/components/AppBar.js +14 -0
- package/src/components/Avatar.js +13 -0
- package/src/components/AvatarGroup.js +8 -0
- package/src/components/Badge.js +22 -0
- package/src/components/BadgeGroup.js +8 -0
- package/src/components/Blockquote.js +8 -0
- package/src/components/BottomBar.js +43 -0
- package/src/components/Breadcrumbs.js +19 -0
- package/src/components/Burger.js +13 -0
- package/src/components/Button.js +37 -0
- package/src/components/Calendar.js +109 -0
- package/src/components/Card.js +40 -0
- package/src/components/Center.js +8 -0
- package/src/components/Checkbox.js +46 -0
- package/src/components/CheckboxGroup.js +8 -0
- package/src/components/Chip.js +35 -0
- package/src/components/Code.js +8 -0
- package/src/components/Col.js +8 -0
- package/src/components/Collapse.js +8 -0
- package/src/components/Container.js +19 -0
- package/src/components/CopyButton.js +30 -0
- package/src/components/DateInput.js +123 -0
- package/src/components/DatePicker.js +7 -0
- package/src/components/Divider.js +22 -0
- package/src/components/Drawer.js +32 -0
- package/src/components/EventCalendar.js +972 -0
- package/src/components/Fieldset.js +12 -0
- package/src/components/Flex.js +25 -0
- package/src/components/Grid.js +8 -0
- package/src/components/GridTable.js +99 -0
- package/src/components/Group.js +29 -0
- package/src/components/HoverCard.js +24 -0
- package/src/components/Icon.js +19 -0
- package/src/components/Image.js +8 -0
- package/src/components/Indicator.js +21 -0
- package/src/components/Kbd.js +8 -0
- package/src/components/List.js +77 -0
- package/src/components/Loading.js +29 -0
- package/src/components/LoadingOverlay.js +9 -0
- package/src/components/Menu.js +129 -0
- package/src/components/Modal.js +61 -0
- package/src/components/MultiSelect.js +153 -0
- package/src/components/NavLink.js +72 -0
- package/src/components/Notification.js +42 -0
- package/src/components/Notifications.js +59 -0
- package/src/components/NumberField.js +389 -0
- package/src/components/NumberInput.js +5 -0
- package/src/components/Pagination.js +56 -0
- package/src/components/Paper.js +20 -0
- package/src/components/PasswordInput.js +29 -0
- package/src/components/PinInput.js +218 -0
- package/src/components/Popover.js +38 -0
- package/src/components/Popper.js +25 -0
- package/src/components/Progress.js +27 -0
- package/src/components/ProgressRing.js +11 -0
- package/src/components/Radio.js +22 -0
- package/src/components/RadioGroup.js +8 -0
- package/src/components/RangePicker.js +45 -0
- package/src/components/RangeSlider.js +143 -0
- package/src/components/Rating.js +42 -0
- package/src/components/ScrollArea.js +11 -0
- package/src/components/SearchInput.js +17 -0
- package/src/components/SegmentedControl.js +39 -0
- package/src/components/Select.js +71 -0
- package/src/components/SelectSearch.js +37 -0
- package/src/components/Sidebar.js +136 -0
- package/src/components/SimpleGrid.js +11 -0
- package/src/components/Skeleton.js +24 -0
- package/src/components/Slider.js +126 -0
- package/src/components/Space.js +8 -0
- package/src/components/Stack.js +27 -0
- package/src/components/Stepper.js +20 -0
- package/src/components/Switch.js +16 -0
- package/src/components/SwitchGroup.js +8 -0
- package/src/components/Table.js +42 -0
- package/src/components/Tabs.js +194 -0
- package/src/components/Tag.js +8 -0
- package/src/components/Text.js +42 -0
- package/src/components/TextInput.js +74 -0
- package/src/components/Textarea.js +15 -0
- package/src/components/Timeline.js +22 -0
- package/src/components/Title.js +18 -0
- package/src/components/Toast.js +16 -0
- package/src/components/ToastStack.js +21 -0
- package/src/components/Tooltip.js +12 -0
- package/src/hooks/useDisclosure.js +13 -0
- package/src/index.js +98 -0
- package/src/theme/fonts/Arimo-400.ttf +0 -0
- package/src/theme/fonts/Arimo-500.ttf +1449 -0
- package/src/theme/fonts/Arimo-600.ttf +1449 -0
- package/src/theme/fonts/Arimo-700.ttf +0 -0
- package/src/theme/fonts/Inter-400.woff2 +0 -0
- package/src/theme/fonts/Inter-500.woff2 +0 -0
- package/src/theme/fonts/Inter-600.woff2 +0 -0
- package/src/theme/fonts/Inter-700.woff2 +0 -0
- package/src/theme/fonts/Poppins-400.ttf +0 -0
- package/src/theme/fonts/Poppins-500.ttf +0 -0
- package/src/theme/fonts/Poppins-600.ttf +0 -0
- package/src/theme/fonts/Poppins-700.ttf +0 -0
- package/src/theme/icons.js +10 -0
- package/src/theme/styles.js +3630 -0
- package/src/theme/theme.js +71 -0
- package/src/utils.js +75 -0
- package/types/components/Accordion.d.ts +1 -0
- package/types/components/ActionIcon.d.ts +1 -0
- package/types/components/Affix.d.ts +1 -0
- package/types/components/Alert.d.ts +1 -0
- package/types/components/Anchor.d.ts +1 -0
- package/types/components/AppBar.d.ts +1 -0
- package/types/components/Avatar.d.ts +1 -0
- package/types/components/AvatarGroup.d.ts +1 -0
- package/types/components/Badge.d.ts +1 -0
- package/types/components/BadgeGroup.d.ts +1 -0
- package/types/components/Blockquote.d.ts +1 -0
- package/types/components/BottomBar.d.ts +4 -0
- package/types/components/Breadcrumbs.d.ts +1 -0
- package/types/components/Burger.d.ts +1 -0
- package/types/components/Button.d.ts +1 -0
- package/types/components/Calendar.d.ts +1 -0
- package/types/components/Card.d.ts +1 -0
- package/types/components/Center.d.ts +1 -0
- package/types/components/Checkbox.d.ts +1 -0
- package/types/components/CheckboxGroup.d.ts +1 -0
- package/types/components/Chip.d.ts +1 -0
- package/types/components/Code.d.ts +1 -0
- package/types/components/Col.d.ts +1 -0
- package/types/components/Collapse.d.ts +1 -0
- package/types/components/Container.d.ts +1 -0
- package/types/components/CopyButton.d.ts +1 -0
- package/types/components/DateInput.d.ts +1 -0
- package/types/components/DatePicker.d.ts +1 -0
- package/types/components/Divider.d.ts +1 -0
- package/types/components/Drawer.d.ts +1 -0
- package/types/components/EventCalendar.d.ts +1 -0
- package/types/components/Fieldset.d.ts +1 -0
- package/types/components/Flex.d.ts +1 -0
- package/types/components/Grid.d.ts +1 -0
- package/types/components/GridTable.d.ts +5 -0
- package/types/components/Group.d.ts +1 -0
- package/types/components/HoverCard.d.ts +1 -0
- package/types/components/Icon.d.ts +1 -0
- package/types/components/Image.d.ts +1 -0
- package/types/components/Indicator.d.ts +1 -0
- package/types/components/Kbd.d.ts +1 -0
- package/types/components/List.d.ts +5 -0
- package/types/components/Loading.d.ts +1 -0
- package/types/components/LoadingOverlay.d.ts +1 -0
- package/types/components/Menu.d.ts +2 -0
- package/types/components/Modal.d.ts +1 -0
- package/types/components/MultiSelect.d.ts +1 -0
- package/types/components/NavLink.d.ts +1 -0
- package/types/components/Notification.d.ts +1 -0
- package/types/components/Notifications.d.ts +1 -0
- package/types/components/NumberField.d.ts +1 -0
- package/types/components/NumberInput.d.ts +1 -0
- package/types/components/Pagination.d.ts +1 -0
- package/types/components/Paper.d.ts +1 -0
- package/types/components/PasswordInput.d.ts +1 -0
- package/types/components/PinInput.d.ts +1 -0
- package/types/components/Popover.d.ts +1 -0
- package/types/components/Popper.d.ts +1 -0
- package/types/components/Progress.d.ts +1 -0
- package/types/components/ProgressRing.d.ts +1 -0
- package/types/components/Radio.d.ts +1 -0
- package/types/components/RadioGroup.d.ts +1 -0
- package/types/components/RangePicker.d.ts +1 -0
- package/types/components/RangeSlider.d.ts +1 -0
- package/types/components/Rating.d.ts +1 -0
- package/types/components/ScrollArea.d.ts +1 -0
- package/types/components/SearchInput.d.ts +1 -0
- package/types/components/SegmentedControl.d.ts +1 -0
- package/types/components/Select.d.ts +1 -0
- package/types/components/SelectSearch.d.ts +1 -0
- package/types/components/Sidebar.d.ts +1 -0
- package/types/components/SimpleGrid.d.ts +1 -0
- package/types/components/Skeleton.d.ts +1 -0
- package/types/components/Slider.d.ts +5 -0
- package/types/components/Space.d.ts +1 -0
- package/types/components/Stack.d.ts +1 -0
- package/types/components/Stepper.d.ts +1 -0
- package/types/components/Switch.d.ts +1 -0
- package/types/components/SwitchGroup.d.ts +1 -0
- package/types/components/Table.d.ts +1 -0
- package/types/components/Tabs.d.ts +1 -0
- package/types/components/Tag.d.ts +1 -0
- package/types/components/Text.d.ts +1 -0
- package/types/components/TextInput.d.ts +1 -0
- package/types/components/Textarea.d.ts +1 -0
- package/types/components/Timeline.d.ts +1 -0
- package/types/components/Title.d.ts +1 -0
- package/types/components/Toast.d.ts +1 -0
- package/types/components/ToastStack.d.ts +1 -0
- package/types/components/Tooltip.d.ts +1 -0
- package/types/hooks/useDisclosure.d.ts +1 -0
- package/types/index.d.ts +93 -0
- package/types/theme/icons.d.ts +10 -0
- package/types/theme/styles.d.ts +1 -0
- package/types/theme/theme.d.ts +2 -0
- package/types/utils.d.ts +12 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Fieldset as HtmlFieldset, Legend, when } from '@granularjs/core';
|
|
2
|
+
import { cx, splitPropsChildren } from '../utils.js';
|
|
3
|
+
|
|
4
|
+
export function Fieldset(...args) {
|
|
5
|
+
const { props, children } = splitPropsChildren(args);
|
|
6
|
+
const { legend, className, ...rest } = props;
|
|
7
|
+
return HtmlFieldset(
|
|
8
|
+
{ ...rest, className: cx('g-ui-fieldset', className) },
|
|
9
|
+
when(legend, () => Legend({ className: 'g-ui-legend' }, legend)),
|
|
10
|
+
children
|
|
11
|
+
);
|
|
12
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Div } from '@granularjs/core';
|
|
2
|
+
import { cx, splitPropsChildren } from '../utils.js';
|
|
3
|
+
|
|
4
|
+
export function Flex(...args) {
|
|
5
|
+
const { props, children } = splitPropsChildren(args, { align: 'center', direction: 'row' });
|
|
6
|
+
const { direction, wrap, align, justify, gap, className, ...rest } = props;
|
|
7
|
+
return Div(
|
|
8
|
+
{
|
|
9
|
+
...rest,
|
|
10
|
+
className: cx(
|
|
11
|
+
'g-ui-flex',
|
|
12
|
+
[direction, (value) => {
|
|
13
|
+
if (value === 'column') return 'g-ui-flex-column';
|
|
14
|
+
return 'g-ui-flex-row';
|
|
15
|
+
}],
|
|
16
|
+
[wrap, 'g-ui-flex-wrap'],
|
|
17
|
+
[align, (value) => value && `g-ui-align-${value}`],
|
|
18
|
+
[justify, (value) => value && `g-ui-justify-${value}`],
|
|
19
|
+
[gap, (value) => value && `g-ui-gap-${value}`],
|
|
20
|
+
className
|
|
21
|
+
),
|
|
22
|
+
},
|
|
23
|
+
children
|
|
24
|
+
);
|
|
25
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Div } from '@granularjs/core';
|
|
2
|
+
import { cx, splitPropsChildren } from '../utils.js';
|
|
3
|
+
|
|
4
|
+
export function Grid(...args) {
|
|
5
|
+
const { props, children } = splitPropsChildren(args, { gap: 'md' });
|
|
6
|
+
const { className, gap, ...rest } = props;
|
|
7
|
+
return Div({ ...rest, className: cx('g-ui-grid-system', [gap, (value) => `g-ui-gap-${value}`], className) }, children);
|
|
8
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Div, Span, after, context } from '@granularjs/core';
|
|
2
|
+
import { splitPropsChildren, cx, classFlag } from '../utils.js';
|
|
3
|
+
|
|
4
|
+
const sizeContext = context([]);
|
|
5
|
+
const tableContext = context({ sort: null, onSort: null });
|
|
6
|
+
|
|
7
|
+
export function GridTable(...args) {
|
|
8
|
+
const { props, rawProps, children } = splitPropsChildren(args, { sizes: [], sort: null, stickyHeader: false });
|
|
9
|
+
const { className, sizes: sizesProp, sort: sortProp, stickyHeader: stickyProp, ...rest } = props;
|
|
10
|
+
const { onSort } = rawProps;
|
|
11
|
+
|
|
12
|
+
const sizes = sizeContext.scope(sizesProp.get());
|
|
13
|
+
after(sizesProp).change(v => sizes.set(v));
|
|
14
|
+
|
|
15
|
+
const table = tableContext.scope({ sort: sortProp.get(), onSort: onSort || null });
|
|
16
|
+
after(sortProp).change(v => table.set().sort = v);
|
|
17
|
+
|
|
18
|
+
return sizes.serve(table.serve(Div({
|
|
19
|
+
className: cx(
|
|
20
|
+
'g-ui-grid-table',
|
|
21
|
+
classFlag('g-ui-grid-table-sticky', stickyProp),
|
|
22
|
+
className
|
|
23
|
+
),
|
|
24
|
+
style: {
|
|
25
|
+
gridTemplateColumns: after(sizes).compute(s =>
|
|
26
|
+
Array.isArray(s) ? s.join(' ') : ''
|
|
27
|
+
),
|
|
28
|
+
},
|
|
29
|
+
...rest,
|
|
30
|
+
}, children)));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
GridTable.GridRow = (...args) => {
|
|
34
|
+
const { props, children } = splitPropsChildren(args, {});
|
|
35
|
+
const { className, header, ...rest } = props;
|
|
36
|
+
|
|
37
|
+
return Div(
|
|
38
|
+
{
|
|
39
|
+
className: cx(
|
|
40
|
+
'g-ui-grid-table-row',
|
|
41
|
+
classFlag('g-ui-grid-table-row-header', header),
|
|
42
|
+
className
|
|
43
|
+
),
|
|
44
|
+
...rest,
|
|
45
|
+
},
|
|
46
|
+
...children
|
|
47
|
+
);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
GridTable.GridCell = function (...args) {
|
|
51
|
+
const { props, rawProps, children } = splitPropsChildren(args, {});
|
|
52
|
+
const { className, sort: _sort, ...rest } = props;
|
|
53
|
+
const sortKey = rawProps.sort;
|
|
54
|
+
|
|
55
|
+
if (sortKey) {
|
|
56
|
+
const table = tableContext.state();
|
|
57
|
+
|
|
58
|
+
const direction = after(table.sort).compute(s =>
|
|
59
|
+
s?.key === sortKey ? s.direction : null
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const handleSort = () => {
|
|
63
|
+
const current = table.get().sort;
|
|
64
|
+
let next;
|
|
65
|
+
if (current?.key === sortKey) {
|
|
66
|
+
next = current.direction === 'asc'
|
|
67
|
+
? { key: sortKey, direction: 'desc' }
|
|
68
|
+
: null;
|
|
69
|
+
} else {
|
|
70
|
+
next = { key: sortKey, direction: 'asc' };
|
|
71
|
+
}
|
|
72
|
+
table.set().sort = next;
|
|
73
|
+
const { onSort } = table.get();
|
|
74
|
+
if (onSort) onSort(next);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
return Div(
|
|
78
|
+
{
|
|
79
|
+
className: cx('g-ui-grid-table-cell', 'g-ui-grid-table-cell-sortable', className),
|
|
80
|
+
onClick: handleSort,
|
|
81
|
+
...rest,
|
|
82
|
+
},
|
|
83
|
+
children,
|
|
84
|
+
Span({ className: 'g-ui-grid-table-sort-icon' },
|
|
85
|
+
after(direction).compute(d =>
|
|
86
|
+
d === 'asc' ? ' ↑' : d === 'desc' ? ' ↓' : ''
|
|
87
|
+
)
|
|
88
|
+
)
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return Div(
|
|
93
|
+
{
|
|
94
|
+
className: cx('g-ui-grid-table-cell', className),
|
|
95
|
+
...rest,
|
|
96
|
+
},
|
|
97
|
+
children
|
|
98
|
+
);
|
|
99
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Div } from '@granularjs/core';
|
|
2
|
+
import { cx, splitPropsChildren, classVar, classMap, classFlag } from '../utils.js';
|
|
3
|
+
|
|
4
|
+
export function Group(...args) {
|
|
5
|
+
const { props, children } = splitPropsChildren(args, { gap: 'md', align: 'center' });
|
|
6
|
+
const { gap, align, justify, position, noWrap, className, style, ...rest } = props;
|
|
7
|
+
const positionClass = classMap(position, {
|
|
8
|
+
apart: 'g-ui-justify-between',
|
|
9
|
+
center: 'g-ui-justify-center',
|
|
10
|
+
right: 'g-ui-justify-end',
|
|
11
|
+
left: 'g-ui-justify-start',
|
|
12
|
+
});
|
|
13
|
+
return Div(
|
|
14
|
+
{
|
|
15
|
+
...rest,
|
|
16
|
+
style,
|
|
17
|
+
className: cx(
|
|
18
|
+
'g-ui-group',
|
|
19
|
+
classVar('g-ui-gap-', gap, 'md'),
|
|
20
|
+
classVar('g-ui-align-', align, 'center'),
|
|
21
|
+
classVar('g-ui-justify-', justify, 'none'),
|
|
22
|
+
positionClass,
|
|
23
|
+
classFlag('g-ui-no-wrap', noWrap),
|
|
24
|
+
className
|
|
25
|
+
),
|
|
26
|
+
},
|
|
27
|
+
children
|
|
28
|
+
);
|
|
29
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Div } from '@granularjs/core';
|
|
2
|
+
import { cx, splitPropsChildren } from '../utils.js';
|
|
3
|
+
|
|
4
|
+
export function HoverCard(...args) {
|
|
5
|
+
const { props, children } = splitPropsChildren(args, { position: 'left' });
|
|
6
|
+
const { position, content, className, ...rest } = props;
|
|
7
|
+
return Div(
|
|
8
|
+
{ ...rest, className: cx('g-ui-hover-card', className) },
|
|
9
|
+
children,
|
|
10
|
+
Div({
|
|
11
|
+
className: cx(
|
|
12
|
+
'g-ui-hover-card-dropdown',
|
|
13
|
+
[position, (value) => {
|
|
14
|
+
if (value === 'right') return 'g-ui-hover-card-right';
|
|
15
|
+
return '';
|
|
16
|
+
}],
|
|
17
|
+
[position, (value) => {
|
|
18
|
+
if (value === 'center') return 'g-ui-hover-card-center';
|
|
19
|
+
return '';
|
|
20
|
+
}]
|
|
21
|
+
),
|
|
22
|
+
}, content)
|
|
23
|
+
);
|
|
24
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Span } from '@granularjs/core';
|
|
2
|
+
import { cx, splitPropsChildren, classVar } from '../utils.js';
|
|
3
|
+
|
|
4
|
+
export function Icon(...args) {
|
|
5
|
+
const { props, children } = splitPropsChildren(args, { size: 'md' });
|
|
6
|
+
|
|
7
|
+
return Span(
|
|
8
|
+
{
|
|
9
|
+
...props,
|
|
10
|
+
className: cx(
|
|
11
|
+
'g-ui-icon',
|
|
12
|
+
classVar('g-ui-icon-size-', props.size, 'md'),
|
|
13
|
+
classVar('g-ui-icon-color-', props.color),
|
|
14
|
+
props.className
|
|
15
|
+
),
|
|
16
|
+
},
|
|
17
|
+
...children
|
|
18
|
+
);
|
|
19
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Img } from '@granularjs/core';
|
|
2
|
+
import { cx, splitPropsChildren } from '../utils.js';
|
|
3
|
+
|
|
4
|
+
export function Image(...args) {
|
|
5
|
+
const { props } = splitPropsChildren(args);
|
|
6
|
+
const { className, ...rest } = props;
|
|
7
|
+
return Img({ ...rest, className: cx('g-ui-image', className) });
|
|
8
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Div, when } from '@granularjs/core';
|
|
2
|
+
import { cx, splitPropsChildren, classVar } from '../utils.js';
|
|
3
|
+
|
|
4
|
+
export function Indicator(...args) {
|
|
5
|
+
const { props, children } = splitPropsChildren(args, { show: true, position: 'top-right', color: 'danger', size: 'md' });
|
|
6
|
+
const { show, position, color, size, className, ...rest } = props;
|
|
7
|
+
return Div(
|
|
8
|
+
{
|
|
9
|
+
...rest,
|
|
10
|
+
className: cx(
|
|
11
|
+
'g-ui-indicator',
|
|
12
|
+
classVar('g-ui-indicator-position-', position, 'top-right'),
|
|
13
|
+
classVar('g-ui-indicator-color-', color, 'danger'),
|
|
14
|
+
classVar('g-ui-indicator-size-', size, 'md'),
|
|
15
|
+
className
|
|
16
|
+
),
|
|
17
|
+
},
|
|
18
|
+
children,
|
|
19
|
+
when(show, () => Div({ className: 'g-ui-indicator-badge' }))
|
|
20
|
+
);
|
|
21
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Span } from '@granularjs/core';
|
|
2
|
+
import { cx, splitPropsChildren } from '../utils.js';
|
|
3
|
+
|
|
4
|
+
export function Kbd(...args) {
|
|
5
|
+
const { props, children } = splitPropsChildren(args);
|
|
6
|
+
const { className, ...rest } = props;
|
|
7
|
+
return Span({ ...rest, className: cx('g-ui-kbd', className) }, children);
|
|
8
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Ul, Ol, Li, Div, Span, after, when, isSignal, isState, isStatePath, isComputed } from '@granularjs/core';
|
|
2
|
+
import { cx, splitPropsChildren, classVar, classFlag, classMap } from '../utils.js';
|
|
3
|
+
|
|
4
|
+
export function List(...args) {
|
|
5
|
+
const { props, children } = splitPropsChildren(args, { type: 'none', size: 'md' });
|
|
6
|
+
const { type, size, withPadding, className, ...rest } = props;
|
|
7
|
+
const typeClass = classMap(type, {
|
|
8
|
+
ordered: 'g-ui-list-ordered',
|
|
9
|
+
unordered: 'g-ui-list-unordered',
|
|
10
|
+
none: 'g-ui-list-none',
|
|
11
|
+
});
|
|
12
|
+
const isOrdered = after(type).compute((next) => next === 'ordered');
|
|
13
|
+
const isListNode = (value) =>
|
|
14
|
+
value && typeof value === 'object' && typeof value.tagName === 'string' &&
|
|
15
|
+
(value.tagName.toLowerCase() === 'ul' || value.tagName.toLowerCase() === 'ol');
|
|
16
|
+
const isListItemNode = (value) =>
|
|
17
|
+
value && typeof value === 'object' && typeof value.tagName === 'string' &&
|
|
18
|
+
value.tagName.toLowerCase() === 'li';
|
|
19
|
+
const wrapChild = (child) => {
|
|
20
|
+
const wrapValue = (value) => {
|
|
21
|
+
if (value == null || value === false) return null;
|
|
22
|
+
if (Array.isArray(value)) return value.map((item) => wrapValue(item));
|
|
23
|
+
if (isListItemNode(value)) return value;
|
|
24
|
+
if (isListNode(value)) return Li({ className: 'g-ui-list-nested-item' }, value);
|
|
25
|
+
return Li(Span({ className: 'g-ui-list-item-shell' }, value));
|
|
26
|
+
};
|
|
27
|
+
if (isSignal(child) || isState(child) || isStatePath(child) || isComputed(child)) {
|
|
28
|
+
return after(child).compute((next) => wrapValue(next));
|
|
29
|
+
}
|
|
30
|
+
return wrapValue(child);
|
|
31
|
+
};
|
|
32
|
+
const listChildren = children.map((child) => wrapChild(child));
|
|
33
|
+
const listProps = {
|
|
34
|
+
...rest,
|
|
35
|
+
className: cx(
|
|
36
|
+
'g-ui-list',
|
|
37
|
+
classVar('g-ui-list-size-', size, 'md'),
|
|
38
|
+
classFlag('g-ui-list-with-padding', withPadding),
|
|
39
|
+
typeClass,
|
|
40
|
+
className
|
|
41
|
+
),
|
|
42
|
+
};
|
|
43
|
+
return when(
|
|
44
|
+
isOrdered,
|
|
45
|
+
() => Ol(listProps, listChildren),
|
|
46
|
+
() => Ul(listProps, listChildren)
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function ListItem(...args) {
|
|
51
|
+
const { props, children } = splitPropsChildren(args, { withBorder: false });
|
|
52
|
+
const { leftSection, rightSection, title, body, withBorder, className, ...rest } = props;
|
|
53
|
+
const hasStructured = after(title, body).compute(([nextTitle, nextBody]) => !!nextTitle || !!nextBody);
|
|
54
|
+
return Li(
|
|
55
|
+
{
|
|
56
|
+
...rest,
|
|
57
|
+
className: cx('g-ui-list-item', classFlag('g-ui-list-item-border', withBorder), className),
|
|
58
|
+
},
|
|
59
|
+
Div(
|
|
60
|
+
{ className: 'g-ui-list-item-shell' },
|
|
61
|
+
when(leftSection, () => Span({ className: 'g-ui-list-item-section g-ui-list-item-section-left' }, leftSection)),
|
|
62
|
+
when(
|
|
63
|
+
hasStructured,
|
|
64
|
+
() =>
|
|
65
|
+
Div(
|
|
66
|
+
{ className: 'g-ui-list-item-content' },
|
|
67
|
+
when(title, () => Div({ className: 'g-ui-list-item-title' }, title)),
|
|
68
|
+
when(body, () => Div({ className: 'g-ui-list-item-body' }, body))
|
|
69
|
+
),
|
|
70
|
+
() => children
|
|
71
|
+
),
|
|
72
|
+
when(rightSection, () => Span({ className: 'g-ui-list-item-section g-ui-list-item-section-right' }, rightSection))
|
|
73
|
+
)
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
List.Item = ListItem;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Div, Span, after, when } from '@granularjs/core';
|
|
2
|
+
import { cx, splitPropsChildren, classVar } from '../utils.js';
|
|
3
|
+
|
|
4
|
+
export function Loading(...args) {
|
|
5
|
+
const { props } = splitPropsChildren(args, { variant: 'spinner', size: 'md' });
|
|
6
|
+
const { variant, size, className } = props;
|
|
7
|
+
const isDots = after(variant).compute((next) => next === 'dots');
|
|
8
|
+
const isBars = after(variant).compute((next) => next === 'bars');
|
|
9
|
+
return when(isDots,
|
|
10
|
+
() => Div({
|
|
11
|
+
className: cx('g-ui-loading g-ui-dots', classVar('g-ui-loading-size-', size, 'md'), className),
|
|
12
|
+
}),
|
|
13
|
+
() => when(
|
|
14
|
+
isBars,
|
|
15
|
+
() => Div(
|
|
16
|
+
{ className: cx('g-ui-loading g-ui-bars', classVar('g-ui-loading-size-', size, 'md'), className) },
|
|
17
|
+
Span(''),
|
|
18
|
+
Span(''),
|
|
19
|
+
Span('')
|
|
20
|
+
),
|
|
21
|
+
() => Div(
|
|
22
|
+
{
|
|
23
|
+
className: cx('g-ui-loading', classVar('g-ui-loading-size-', size, 'md'), className),
|
|
24
|
+
},
|
|
25
|
+
Div({ className: 'g-ui-spinner' })
|
|
26
|
+
)
|
|
27
|
+
)
|
|
28
|
+
);
|
|
29
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Div, when } from '@granularjs/core';
|
|
2
|
+
import { splitPropsChildren } from '../utils.js';
|
|
3
|
+
import { Loading } from './Loading.js';
|
|
4
|
+
|
|
5
|
+
export function LoadingOverlay(...args) {
|
|
6
|
+
const { props } = splitPropsChildren(args);
|
|
7
|
+
const { visible, ...rest } = props;
|
|
8
|
+
return when(visible, () => Div({ ...rest, className: 'g-ui-loading-overlay' }, Loading({})));
|
|
9
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { Div, when, after, state, portal } from '@granularjs/core';
|
|
2
|
+
import { cx, splitPropsChildren, resolveValue } from '../utils.js';
|
|
3
|
+
|
|
4
|
+
export const menuControlStore = state({ currentOpenState: null })
|
|
5
|
+
|
|
6
|
+
export function Menu(...args) {
|
|
7
|
+
const mainNode = state();
|
|
8
|
+
const dropdownNode = state();
|
|
9
|
+
const dropdownStyle = state({});
|
|
10
|
+
const { props, rawProps, children } = splitPropsChildren(args, { position: 'right' });
|
|
11
|
+
const { opened, content, position, className, ...rest } = props;
|
|
12
|
+
const { onChange } = rawProps;
|
|
13
|
+
const currentState = state(resolveValue(opened) ?? false);
|
|
14
|
+
after(opened).change((value) => {
|
|
15
|
+
const resolved = resolveValue(value);
|
|
16
|
+
if (resolved == null) return;
|
|
17
|
+
currentState.set(!!resolved);
|
|
18
|
+
if (!!resolved) {
|
|
19
|
+
closeOldSetCurrent()
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const closeOldSetCurrent = () => {
|
|
24
|
+
if (menuControlStore.get().currentOpenState === currentState) return;
|
|
25
|
+
menuControlStore.get().currentOpenState?.set(false)
|
|
26
|
+
menuControlStore.set().currentOpenState = currentState;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (opened.get()) {
|
|
30
|
+
closeOldSetCurrent()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const parsePosition = (value) => {
|
|
34
|
+
const raw = String(value ?? 'right').toLowerCase();
|
|
35
|
+
const parts = raw.split('-').filter(Boolean);
|
|
36
|
+
if (parts.length === 1) {
|
|
37
|
+
const single = parts[0];
|
|
38
|
+
if (single === 'top' || single === 'bottom') return { placement: single, align: 'center' };
|
|
39
|
+
if (single === 'left' || single === 'right') return { placement: 'bottom', align: single };
|
|
40
|
+
if (single === 'center') return { placement: 'bottom', align: 'center' };
|
|
41
|
+
return { placement: 'bottom', align: 'right' };
|
|
42
|
+
}
|
|
43
|
+
const [first, second] = parts;
|
|
44
|
+
if (first === 'top' || first === 'bottom') {
|
|
45
|
+
return { placement: first, align: second || 'center' };
|
|
46
|
+
}
|
|
47
|
+
if (first === 'left' || first === 'right') {
|
|
48
|
+
return { placement: first, align: second || 'center' };
|
|
49
|
+
}
|
|
50
|
+
return { placement: 'bottom', align: 'right' };
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const updatePosition = () => {
|
|
54
|
+
const trigger = mainNode.get();
|
|
55
|
+
const dropdown = dropdownNode.get();
|
|
56
|
+
if (!trigger || !dropdown) return;
|
|
57
|
+
if (typeof window === 'undefined') return;
|
|
58
|
+
const rect = trigger.getBoundingClientRect();
|
|
59
|
+
const dropdownRect = dropdown.getBoundingClientRect();
|
|
60
|
+
const positionValue = resolveValue(position) ?? 'right';
|
|
61
|
+
const spaceVar = getComputedStyle(document.documentElement).getPropertyValue('--g-ui-space-20');
|
|
62
|
+
const margin = Number.parseFloat(spaceVar) || 20;
|
|
63
|
+
const viewportWidth = window.innerWidth || 0;
|
|
64
|
+
const viewportHeight = window.innerHeight || 0;
|
|
65
|
+
const maxLeft = Math.max(margin, viewportWidth - dropdownRect.width - margin);
|
|
66
|
+
const maxTop = Math.max(margin, viewportHeight - dropdownRect.height - margin);
|
|
67
|
+
const { placement, align } = parsePosition(positionValue);
|
|
68
|
+
const gap = 8;
|
|
69
|
+
let top = rect.bottom + gap;
|
|
70
|
+
let left = rect.left;
|
|
71
|
+
if (placement === 'top' || placement === 'bottom') {
|
|
72
|
+
top = placement === 'top' ? rect.top - dropdownRect.height - gap : rect.bottom + gap;
|
|
73
|
+
if (align === 'center') {
|
|
74
|
+
left = rect.left + rect.width / 2 - dropdownRect.width / 2;
|
|
75
|
+
} else if (align === 'right') {
|
|
76
|
+
left = rect.right - dropdownRect.width;
|
|
77
|
+
} else {
|
|
78
|
+
left = rect.left;
|
|
79
|
+
}
|
|
80
|
+
} else if (placement === 'left' || placement === 'right') {
|
|
81
|
+
left = placement === 'left' ? rect.left - dropdownRect.width - gap : rect.right + gap;
|
|
82
|
+
if (align === 'center') {
|
|
83
|
+
top = rect.top + rect.height / 2 - dropdownRect.height / 2;
|
|
84
|
+
} else if (align === 'bottom') {
|
|
85
|
+
top = rect.bottom - dropdownRect.height;
|
|
86
|
+
} else {
|
|
87
|
+
top = rect.top;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
left = Math.max(margin, Math.min(left, maxLeft));
|
|
91
|
+
top = Math.max(margin, Math.min(top, maxTop));
|
|
92
|
+
dropdownStyle.set({
|
|
93
|
+
top: `${top}px`,
|
|
94
|
+
left: `${left}px`,
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const setOpen = (next) => {
|
|
99
|
+
currentState.set(next);
|
|
100
|
+
onChange?.(next);
|
|
101
|
+
|
|
102
|
+
if (next) {
|
|
103
|
+
closeOldSetCurrent()
|
|
104
|
+
if (typeof requestAnimationFrame === 'function') {
|
|
105
|
+
requestAnimationFrame(() => updatePosition());
|
|
106
|
+
} else {
|
|
107
|
+
setTimeout(() => updatePosition(), 0);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
const toggle = () => setOpen(!currentState.get())
|
|
112
|
+
const close = () => setOpen(false)
|
|
113
|
+
|
|
114
|
+
return Div(
|
|
115
|
+
{ ...rest, node: mainNode, className: cx('g-ui-menu', className) },
|
|
116
|
+
Div({ onClick: toggle }, children),
|
|
117
|
+
when(currentState, () =>
|
|
118
|
+
portal(
|
|
119
|
+
Div(
|
|
120
|
+
Div({ className: 'g-ui-menu-overlay', onClick: close }),
|
|
121
|
+
Div(
|
|
122
|
+
{ className: 'g-ui-menu-dropdown', node: dropdownNode, style: dropdownStyle },
|
|
123
|
+
content
|
|
124
|
+
)
|
|
125
|
+
)
|
|
126
|
+
)
|
|
127
|
+
)
|
|
128
|
+
);
|
|
129
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Div, Button as HtmlButton, portal, when, after } from '@granularjs/core';
|
|
2
|
+
import { cx, splitPropsChildren, classVar } from '../utils.js';
|
|
3
|
+
import { closeSvg } from '../theme/icons.js';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export function Modal(...args) {
|
|
8
|
+
const { props, rawProps, children } = splitPropsChildren(args, { size: 'md', centered: true, overlay: 'normal' });
|
|
9
|
+
const {
|
|
10
|
+
opened,
|
|
11
|
+
title,
|
|
12
|
+
size,
|
|
13
|
+
centered,
|
|
14
|
+
overlay,
|
|
15
|
+
position,
|
|
16
|
+
className,
|
|
17
|
+
style,
|
|
18
|
+
} = props;
|
|
19
|
+
const { onClose } = rawProps;
|
|
20
|
+
const positionClass = after(position, centered).compute(([pos, isCentered]) => {
|
|
21
|
+
const value = pos ?? (isCentered === false ? 'top-center' : 'center');
|
|
22
|
+
return `g-ui-modal-position-${value}`;
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return when(opened, () =>
|
|
26
|
+
portal(
|
|
27
|
+
Div(
|
|
28
|
+
{
|
|
29
|
+
className: cx(
|
|
30
|
+
'g-ui-modal-overlay',
|
|
31
|
+
classVar('g-ui-modal-overlay-', overlay, 'normal'),
|
|
32
|
+
positionClass
|
|
33
|
+
),
|
|
34
|
+
onClick: (ev) => {
|
|
35
|
+
if (ev.target === ev.currentTarget) onClose?.();
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
Div(
|
|
39
|
+
{
|
|
40
|
+
className: cx('g-ui-modal', classVar('g-ui-modal-size-', size, 'md'), className),
|
|
41
|
+
},
|
|
42
|
+
Div(
|
|
43
|
+
{ className: 'g-ui-modal-header' },
|
|
44
|
+
when(title, () => Div({ className: 'g-ui-modal-title' }, title)),
|
|
45
|
+
when(onClose, () =>
|
|
46
|
+
HtmlButton(
|
|
47
|
+
{
|
|
48
|
+
type: 'button',
|
|
49
|
+
className: 'g-ui-button g-ui-button-variant-subtle g-ui-button-size-xs g-ui-modal-close',
|
|
50
|
+
onClick: onClose,
|
|
51
|
+
innerHTML: closeSvg,
|
|
52
|
+
}
|
|
53
|
+
)
|
|
54
|
+
)
|
|
55
|
+
),
|
|
56
|
+
children
|
|
57
|
+
)
|
|
58
|
+
)
|
|
59
|
+
)
|
|
60
|
+
);
|
|
61
|
+
}
|