@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.
Files changed (220) hide show
  1. package/README.md +116 -0
  2. package/dist/fonts/Arimo-400.ttf +0 -0
  3. package/dist/fonts/Arimo-500.ttf +1449 -0
  4. package/dist/fonts/Arimo-600.ttf +1449 -0
  5. package/dist/fonts/Arimo-700.ttf +0 -0
  6. package/dist/fonts/Inter-400.woff2 +0 -0
  7. package/dist/fonts/Inter-500.woff2 +0 -0
  8. package/dist/fonts/Inter-600.woff2 +0 -0
  9. package/dist/fonts/Inter-700.woff2 +0 -0
  10. package/dist/fonts/Poppins-400.ttf +0 -0
  11. package/dist/fonts/Poppins-500.ttf +0 -0
  12. package/dist/fonts/Poppins-600.ttf +0 -0
  13. package/dist/fonts/Poppins-700.ttf +0 -0
  14. package/dist/granular-ui.min.js +3605 -0
  15. package/dist/granular-ui.min.js.map +7 -0
  16. package/package.json +55 -0
  17. package/src/components/Accordion.js +25 -0
  18. package/src/components/ActionIcon.js +20 -0
  19. package/src/components/Affix.js +11 -0
  20. package/src/components/Alert.js +33 -0
  21. package/src/components/Anchor.js +8 -0
  22. package/src/components/AppBar.js +14 -0
  23. package/src/components/Avatar.js +13 -0
  24. package/src/components/AvatarGroup.js +8 -0
  25. package/src/components/Badge.js +22 -0
  26. package/src/components/BadgeGroup.js +8 -0
  27. package/src/components/Blockquote.js +8 -0
  28. package/src/components/BottomBar.js +43 -0
  29. package/src/components/Breadcrumbs.js +19 -0
  30. package/src/components/Burger.js +13 -0
  31. package/src/components/Button.js +37 -0
  32. package/src/components/Calendar.js +109 -0
  33. package/src/components/Card.js +40 -0
  34. package/src/components/Center.js +8 -0
  35. package/src/components/Checkbox.js +46 -0
  36. package/src/components/CheckboxGroup.js +8 -0
  37. package/src/components/Chip.js +35 -0
  38. package/src/components/Code.js +8 -0
  39. package/src/components/Col.js +8 -0
  40. package/src/components/Collapse.js +8 -0
  41. package/src/components/Container.js +19 -0
  42. package/src/components/CopyButton.js +30 -0
  43. package/src/components/DateInput.js +123 -0
  44. package/src/components/DatePicker.js +7 -0
  45. package/src/components/Divider.js +22 -0
  46. package/src/components/Drawer.js +32 -0
  47. package/src/components/EventCalendar.js +972 -0
  48. package/src/components/Fieldset.js +12 -0
  49. package/src/components/Flex.js +25 -0
  50. package/src/components/Grid.js +8 -0
  51. package/src/components/GridTable.js +99 -0
  52. package/src/components/Group.js +29 -0
  53. package/src/components/HoverCard.js +24 -0
  54. package/src/components/Icon.js +19 -0
  55. package/src/components/Image.js +8 -0
  56. package/src/components/Indicator.js +21 -0
  57. package/src/components/Kbd.js +8 -0
  58. package/src/components/List.js +77 -0
  59. package/src/components/Loading.js +29 -0
  60. package/src/components/LoadingOverlay.js +9 -0
  61. package/src/components/Menu.js +129 -0
  62. package/src/components/Modal.js +61 -0
  63. package/src/components/MultiSelect.js +153 -0
  64. package/src/components/NavLink.js +72 -0
  65. package/src/components/Notification.js +42 -0
  66. package/src/components/Notifications.js +59 -0
  67. package/src/components/NumberField.js +389 -0
  68. package/src/components/NumberInput.js +5 -0
  69. package/src/components/Pagination.js +56 -0
  70. package/src/components/Paper.js +20 -0
  71. package/src/components/PasswordInput.js +29 -0
  72. package/src/components/PinInput.js +218 -0
  73. package/src/components/Popover.js +38 -0
  74. package/src/components/Popper.js +25 -0
  75. package/src/components/Progress.js +27 -0
  76. package/src/components/ProgressRing.js +11 -0
  77. package/src/components/Radio.js +22 -0
  78. package/src/components/RadioGroup.js +8 -0
  79. package/src/components/RangePicker.js +45 -0
  80. package/src/components/RangeSlider.js +143 -0
  81. package/src/components/Rating.js +42 -0
  82. package/src/components/ScrollArea.js +11 -0
  83. package/src/components/SearchInput.js +17 -0
  84. package/src/components/SegmentedControl.js +39 -0
  85. package/src/components/Select.js +71 -0
  86. package/src/components/SelectSearch.js +37 -0
  87. package/src/components/Sidebar.js +136 -0
  88. package/src/components/SimpleGrid.js +11 -0
  89. package/src/components/Skeleton.js +24 -0
  90. package/src/components/Slider.js +126 -0
  91. package/src/components/Space.js +8 -0
  92. package/src/components/Stack.js +27 -0
  93. package/src/components/Stepper.js +20 -0
  94. package/src/components/Switch.js +16 -0
  95. package/src/components/SwitchGroup.js +8 -0
  96. package/src/components/Table.js +42 -0
  97. package/src/components/Tabs.js +194 -0
  98. package/src/components/Tag.js +8 -0
  99. package/src/components/Text.js +42 -0
  100. package/src/components/TextInput.js +74 -0
  101. package/src/components/Textarea.js +15 -0
  102. package/src/components/Timeline.js +22 -0
  103. package/src/components/Title.js +18 -0
  104. package/src/components/Toast.js +16 -0
  105. package/src/components/ToastStack.js +21 -0
  106. package/src/components/Tooltip.js +12 -0
  107. package/src/hooks/useDisclosure.js +13 -0
  108. package/src/index.js +98 -0
  109. package/src/theme/fonts/Arimo-400.ttf +0 -0
  110. package/src/theme/fonts/Arimo-500.ttf +1449 -0
  111. package/src/theme/fonts/Arimo-600.ttf +1449 -0
  112. package/src/theme/fonts/Arimo-700.ttf +0 -0
  113. package/src/theme/fonts/Inter-400.woff2 +0 -0
  114. package/src/theme/fonts/Inter-500.woff2 +0 -0
  115. package/src/theme/fonts/Inter-600.woff2 +0 -0
  116. package/src/theme/fonts/Inter-700.woff2 +0 -0
  117. package/src/theme/fonts/Poppins-400.ttf +0 -0
  118. package/src/theme/fonts/Poppins-500.ttf +0 -0
  119. package/src/theme/fonts/Poppins-600.ttf +0 -0
  120. package/src/theme/fonts/Poppins-700.ttf +0 -0
  121. package/src/theme/icons.js +10 -0
  122. package/src/theme/styles.js +3630 -0
  123. package/src/theme/theme.js +71 -0
  124. package/src/utils.js +75 -0
  125. package/types/components/Accordion.d.ts +1 -0
  126. package/types/components/ActionIcon.d.ts +1 -0
  127. package/types/components/Affix.d.ts +1 -0
  128. package/types/components/Alert.d.ts +1 -0
  129. package/types/components/Anchor.d.ts +1 -0
  130. package/types/components/AppBar.d.ts +1 -0
  131. package/types/components/Avatar.d.ts +1 -0
  132. package/types/components/AvatarGroup.d.ts +1 -0
  133. package/types/components/Badge.d.ts +1 -0
  134. package/types/components/BadgeGroup.d.ts +1 -0
  135. package/types/components/Blockquote.d.ts +1 -0
  136. package/types/components/BottomBar.d.ts +4 -0
  137. package/types/components/Breadcrumbs.d.ts +1 -0
  138. package/types/components/Burger.d.ts +1 -0
  139. package/types/components/Button.d.ts +1 -0
  140. package/types/components/Calendar.d.ts +1 -0
  141. package/types/components/Card.d.ts +1 -0
  142. package/types/components/Center.d.ts +1 -0
  143. package/types/components/Checkbox.d.ts +1 -0
  144. package/types/components/CheckboxGroup.d.ts +1 -0
  145. package/types/components/Chip.d.ts +1 -0
  146. package/types/components/Code.d.ts +1 -0
  147. package/types/components/Col.d.ts +1 -0
  148. package/types/components/Collapse.d.ts +1 -0
  149. package/types/components/Container.d.ts +1 -0
  150. package/types/components/CopyButton.d.ts +1 -0
  151. package/types/components/DateInput.d.ts +1 -0
  152. package/types/components/DatePicker.d.ts +1 -0
  153. package/types/components/Divider.d.ts +1 -0
  154. package/types/components/Drawer.d.ts +1 -0
  155. package/types/components/EventCalendar.d.ts +1 -0
  156. package/types/components/Fieldset.d.ts +1 -0
  157. package/types/components/Flex.d.ts +1 -0
  158. package/types/components/Grid.d.ts +1 -0
  159. package/types/components/GridTable.d.ts +5 -0
  160. package/types/components/Group.d.ts +1 -0
  161. package/types/components/HoverCard.d.ts +1 -0
  162. package/types/components/Icon.d.ts +1 -0
  163. package/types/components/Image.d.ts +1 -0
  164. package/types/components/Indicator.d.ts +1 -0
  165. package/types/components/Kbd.d.ts +1 -0
  166. package/types/components/List.d.ts +5 -0
  167. package/types/components/Loading.d.ts +1 -0
  168. package/types/components/LoadingOverlay.d.ts +1 -0
  169. package/types/components/Menu.d.ts +2 -0
  170. package/types/components/Modal.d.ts +1 -0
  171. package/types/components/MultiSelect.d.ts +1 -0
  172. package/types/components/NavLink.d.ts +1 -0
  173. package/types/components/Notification.d.ts +1 -0
  174. package/types/components/Notifications.d.ts +1 -0
  175. package/types/components/NumberField.d.ts +1 -0
  176. package/types/components/NumberInput.d.ts +1 -0
  177. package/types/components/Pagination.d.ts +1 -0
  178. package/types/components/Paper.d.ts +1 -0
  179. package/types/components/PasswordInput.d.ts +1 -0
  180. package/types/components/PinInput.d.ts +1 -0
  181. package/types/components/Popover.d.ts +1 -0
  182. package/types/components/Popper.d.ts +1 -0
  183. package/types/components/Progress.d.ts +1 -0
  184. package/types/components/ProgressRing.d.ts +1 -0
  185. package/types/components/Radio.d.ts +1 -0
  186. package/types/components/RadioGroup.d.ts +1 -0
  187. package/types/components/RangePicker.d.ts +1 -0
  188. package/types/components/RangeSlider.d.ts +1 -0
  189. package/types/components/Rating.d.ts +1 -0
  190. package/types/components/ScrollArea.d.ts +1 -0
  191. package/types/components/SearchInput.d.ts +1 -0
  192. package/types/components/SegmentedControl.d.ts +1 -0
  193. package/types/components/Select.d.ts +1 -0
  194. package/types/components/SelectSearch.d.ts +1 -0
  195. package/types/components/Sidebar.d.ts +1 -0
  196. package/types/components/SimpleGrid.d.ts +1 -0
  197. package/types/components/Skeleton.d.ts +1 -0
  198. package/types/components/Slider.d.ts +5 -0
  199. package/types/components/Space.d.ts +1 -0
  200. package/types/components/Stack.d.ts +1 -0
  201. package/types/components/Stepper.d.ts +1 -0
  202. package/types/components/Switch.d.ts +1 -0
  203. package/types/components/SwitchGroup.d.ts +1 -0
  204. package/types/components/Table.d.ts +1 -0
  205. package/types/components/Tabs.d.ts +1 -0
  206. package/types/components/Tag.d.ts +1 -0
  207. package/types/components/Text.d.ts +1 -0
  208. package/types/components/TextInput.d.ts +1 -0
  209. package/types/components/Textarea.d.ts +1 -0
  210. package/types/components/Timeline.d.ts +1 -0
  211. package/types/components/Title.d.ts +1 -0
  212. package/types/components/Toast.d.ts +1 -0
  213. package/types/components/ToastStack.d.ts +1 -0
  214. package/types/components/Tooltip.d.ts +1 -0
  215. package/types/hooks/useDisclosure.d.ts +1 -0
  216. package/types/index.d.ts +93 -0
  217. package/types/theme/icons.d.ts +10 -0
  218. package/types/theme/styles.d.ts +1 -0
  219. package/types/theme/theme.d.ts +2 -0
  220. package/types/utils.d.ts +12 -0
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@granularjs/ui",
3
+ "version": "0.1.0",
4
+ "description": "90+ production-ready UI components for Granular. Dark/light themes, CSS variables, accessible, zero dependencies beyond @granularjs/core.",
5
+ "type": "module",
6
+ "main": "./dist/granular-ui.min.js",
7
+ "module": "./dist/granular-ui.min.js",
8
+ "types": "./types/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./types/index.d.ts",
12
+ "import": "./dist/granular-ui.min.js",
13
+ "default": "./dist/granular-ui.min.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "types",
19
+ "src"
20
+ ],
21
+ "scripts": {
22
+ "build:minify": "mkdir -p ./dist/fonts && cp -R src/theme/fonts/* ./dist/fonts/ && npx -y esbuild src/index.js --bundle --minify --sourcemap --format=esm --external:@granularjs/core --outfile=./dist/granular-ui.min.js && npx -y -p typescript@latest tsc -p tsconfig.json",
23
+ "build:debug": "mkdir -p ./dist/fonts && cp -R src/theme/fonts/* ./dist/fonts/ && npx -y esbuild src/index.js --bundle --sourcemap --format=esm --external:@granularjs/core --outfile=./dist/granular-ui.js && npx -y -p typescript@latest tsc -p tsconfig.json",
24
+ "build:watch": "npx -y esbuild src/index.js --bundle --minify --sourcemap --format=esm --external:@granularjs/core --outfile=./dist/granular-ui.min.js --watch",
25
+ "version": "npm run build:minify && git add -A",
26
+ "postversion": "git push && git push --tags"
27
+ },
28
+ "peerDependencies": {
29
+ "@granularjs/core": "^1.0.0"
30
+ },
31
+ "author": "Guilherme Ferreira",
32
+ "license": "MIT",
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "https://github.com/zerobytes/granular-ui.git"
36
+ },
37
+ "homepage": "https://granular.web.app",
38
+ "bugs": {
39
+ "url": "https://github.com/zerobytes/granular-ui/issues"
40
+ },
41
+ "keywords": [
42
+ "granular",
43
+ "granularjs",
44
+ "ui",
45
+ "components",
46
+ "component-library",
47
+ "design-system",
48
+ "theme",
49
+ "dark-mode",
50
+ "reactive",
51
+ "frontend",
52
+ "javascript",
53
+ "no-vdom"
54
+ ]
55
+ }
@@ -0,0 +1,25 @@
1
+ import { Div } from '@granularjs/core';
2
+ import { state, when, after } from '@granularjs/core';
3
+ import { cx, splitPropsChildren, resolveBool } from '../utils.js';
4
+
5
+ export function Accordion(...args) {
6
+ const { props, children } = splitPropsChildren(args, { opened: false });
7
+ const { opened, className, ...rest } = props;
8
+ const openedState = state(resolveBool(opened));
9
+
10
+ after(opened).change((next) => {
11
+ openedState.set(resolveBool(next));
12
+ });
13
+
14
+ const toggle = () => {
15
+ openedState.set(!openedState.get());
16
+ };
17
+
18
+ const header = children[0];
19
+ const content = children[1];
20
+ return Div(
21
+ { ...rest, className: cx('g-ui-accordion', className) },
22
+ Div({ className: 'g-ui-accordion-header', onClick: toggle }, header),
23
+ when(openedState, () => Div({ className: 'g-ui-accordion-content' }, content))
24
+ );
25
+ }
@@ -0,0 +1,20 @@
1
+ import { Button } from '@granularjs/core';
2
+ import { cx, splitPropsChildren, classVar } from '../utils.js';
3
+
4
+ export function ActionIcon(...args) {
5
+ const { props, children } = splitPropsChildren(args, { size: 'md', variant: 'filled' });
6
+ const { size, variant, className, ...rest } = props;
7
+ return Button(
8
+ {
9
+ ...rest,
10
+ type: 'button',
11
+ className: cx(
12
+ 'g-ui-action-icon',
13
+ classVar('g-ui-action-icon-size-', size, 'md'),
14
+ classVar('g-ui-action-icon-', variant, 'filled'),
15
+ className
16
+ ),
17
+ },
18
+ children
19
+ );
20
+ }
@@ -0,0 +1,11 @@
1
+ import { Div } from '@granularjs/core';
2
+ import { cx, splitPropsChildren } from '../utils.js';
3
+
4
+ export function Affix(...args) {
5
+ const { props, children } = splitPropsChildren(args, { position: 'bottom-right' });
6
+ const { position, className, ...rest } = props;
7
+ return Div(
8
+ { ...rest, className: cx('g-ui-affix', [position, (value) => `g-ui-affix-${value}`], className) },
9
+ children
10
+ );
11
+ }
@@ -0,0 +1,33 @@
1
+ import { Button, Div, Span, after, when } from '@granularjs/core';
2
+ import { cx, splitPropsChildren, resolveBool } from '../utils.js';
3
+
4
+ export function Alert(...args) {
5
+ const { props, rawProps, children } = splitPropsChildren(args, { color: 'blue' });
6
+ const {
7
+ title,
8
+ color,
9
+ icon,
10
+ withCloseButton,
11
+ className,
12
+ ...rest
13
+ } = props;
14
+ const { onClose } = rawProps;
15
+
16
+ const hasContent = after(title, withCloseButton).compute(([title, showClose]) => {
17
+ return title || showClose
18
+ });
19
+ const hasIcon = after(icon).compute((icon) => {
20
+ return icon !== undefined
21
+ });
22
+
23
+ return Div(
24
+ { ...rest, className: cx('g-ui-alert', [color, (value) => `g-ui-alert-${value}`], className) },
25
+ Div(
26
+ { className: 'g-ui-alert-header' },
27
+ when(icon, () => Span({ className: 'g-ui-alert-icon' }, icon)),
28
+ when(title, () => Div({ className: 'g-ui-alert-title' }, title)),
29
+ when(withCloseButton, () => Button({ type: 'button', className: 'g-ui-alert-close', onClick: () => onClose?.() }, '×'))
30
+ ),
31
+ children
32
+ );
33
+ }
@@ -0,0 +1,8 @@
1
+ import { A } from '@granularjs/core';
2
+ import { cx, splitPropsChildren } from '../utils.js';
3
+
4
+ export function Anchor(...args) {
5
+ const { props, children } = splitPropsChildren(args);
6
+ const { className, ...rest } = props;
7
+ return A({ ...rest, className: cx('g-ui-anchor', className) }, children);
8
+ }
@@ -0,0 +1,14 @@
1
+ import { Div } from '@granularjs/core';
2
+ import { cx, splitPropsChildren, classVar } from '../utils.js';
3
+
4
+ export function AppBar(...args) {
5
+ const { props, children } = splitPropsChildren(args, { position: 'sticky' });
6
+ const { position, className, ...rest } = props;
7
+ return Div(
8
+ {
9
+ ...rest,
10
+ className: cx('g-ui-appbar', classVar('g-ui-appbar-', position, 'sticky'), className),
11
+ },
12
+ children
13
+ );
14
+ }
@@ -0,0 +1,13 @@
1
+ import { Div, Img, when } from '@granularjs/core';
2
+ import { cx, splitPropsChildren } from '../utils.js';
3
+
4
+ export function Avatar(...args) {
5
+ const { props, children } = splitPropsChildren(args, { size: 'md', alt: '' });
6
+ const { src, size, alt, className, ...rest } = props;
7
+ return Div(
8
+ { ...rest, className: cx('g-ui-avatar', [size, (value) => `g-ui-avatar-size-${value}`], className) },
9
+ when(src, () => Img({ className: 'g-ui-avatar-img', src, alt }), () => {
10
+ return children;
11
+ })
12
+ );
13
+ }
@@ -0,0 +1,8 @@
1
+ import { Div } from '@granularjs/core';
2
+ import { cx, splitPropsChildren } from '../utils.js';
3
+
4
+ export function AvatarGroup(...args) {
5
+ const { props, children } = splitPropsChildren(args);
6
+ const { className, ...rest } = props;
7
+ return Div({ ...rest, className: cx('g-ui-avatar-group', className) }, children);
8
+ }
@@ -0,0 +1,22 @@
1
+ import { Span } from '@granularjs/core';
2
+ import { cx, splitPropsChildren, classVar, classFlag, classMap } from '../utils.js';
3
+
4
+ export function Badge(...args) {
5
+ const { props, children } = splitPropsChildren(args, { variant: 'filled', size: 'md' });
6
+ const { variant, size, className, dot, style, ...rest } = props;
7
+ const dotClass = classMap(variant, { dot: 'g-ui-badge-dot' });
8
+ return Span(
9
+ {
10
+ ...rest,
11
+ className: cx(
12
+ 'g-ui-badge',
13
+ classVar('g-ui-badge-variant-', variant, 'filled'),
14
+ classVar('g-ui-badge-size-', size, 'md'),
15
+ classFlag('g-ui-badge-dot', dot),
16
+ dotClass,
17
+ className
18
+ ),
19
+ },
20
+ children
21
+ );
22
+ }
@@ -0,0 +1,8 @@
1
+ import { Div } from '@granularjs/core';
2
+ import { cx, splitPropsChildren } from '../utils.js';
3
+
4
+ export function BadgeGroup(...args) {
5
+ const { props, children } = splitPropsChildren(args);
6
+ const { className, ...rest } = props;
7
+ return Div({ ...rest, className: cx('g-ui-badge-group', className) }, children);
8
+ }
@@ -0,0 +1,8 @@
1
+ import { Blockquote as HtmlBlockquote } from '@granularjs/core';
2
+ import { cx, splitPropsChildren } from '../utils.js';
3
+
4
+ export function Blockquote(...args) {
5
+ const { props, children } = splitPropsChildren(args);
6
+ const { className, ...rest } = props;
7
+ return HtmlBlockquote({ ...rest, className: cx('g-ui-blockquote', className) }, children);
8
+ }
@@ -0,0 +1,43 @@
1
+ import { Button, Div, Span, when } from '@granularjs/core';
2
+ import { cx, splitPropsChildren, classVar, classFlag } from '../utils.js';
3
+
4
+ export function BottomBar(...args) {
5
+ const { props, children } = splitPropsChildren(args, { grow: true });
6
+ const { grow, className, ...rest } = props;
7
+
8
+ return Div(
9
+ {
10
+ ...rest,
11
+ className: cx(
12
+ 'g-ui-bottombar',
13
+ classFlag('g-ui-bottombar-grow', grow),
14
+ className
15
+ ),
16
+ },
17
+ children
18
+ );
19
+ }
20
+
21
+ BottomBar.Action = function BottomBarAction(...args) {
22
+ const { props, rawProps, children } = splitPropsChildren(args, { variant: 'subtle' });
23
+ const { icon, label, active, disabled, variant, className, ...rest } = props;
24
+ const { onClick } = rawProps;
25
+
26
+ return Button(
27
+ {
28
+ ...rest,
29
+ className: cx(
30
+ 'g-ui-bottombar-action',
31
+ classVar('g-ui-bottombar-action-variant-', variant, 'subtle'),
32
+ classFlag('g-ui-bottombar-action-active', active),
33
+ classFlag('g-ui-bottombar-action-disabled', disabled),
34
+ className
35
+ ),
36
+ onClick,
37
+ disabled,
38
+ },
39
+ when(icon, () => Span({ className: 'g-ui-bottombar-action-icon' }, icon)),
40
+ when(label, () => Span({ className: 'g-ui-bottombar-action-label' }, label)),
41
+ children
42
+ );
43
+ };
@@ -0,0 +1,19 @@
1
+ import { Nav, Span } from '@granularjs/core';
2
+ import { cx, splitPropsChildren } from '../utils.js';
3
+
4
+ export function Breadcrumbs(...args) {
5
+ const { props, children } = splitPropsChildren(args, { separator: '/' });
6
+ const { separator, className, ...rest } = props;
7
+ const items = [];
8
+ if (Array.isArray(children)) items.push(...children);
9
+ else items.push(children);
10
+ const filtered = items.filter(Boolean);
11
+ const nodes = [];
12
+ filtered.forEach((item, idx) => {
13
+ nodes.push(item);
14
+ if (idx < filtered.length - 1) {
15
+ nodes.push(Span({ className: 'g-ui-breadcrumbs-separator' }, separator));
16
+ }
17
+ });
18
+ return Nav({ ...rest, className: cx('g-ui-breadcrumbs', className) }, nodes);
19
+ }
@@ -0,0 +1,13 @@
1
+ import { Span } from '@granularjs/core';
2
+ import { cx, splitPropsChildren } from '../utils.js';
3
+
4
+ export function Burger(...args) {
5
+ const { props } = splitPropsChildren(args);
6
+ const { opened, className, ...rest } = props;
7
+ return Span(
8
+ { ...rest, className: cx('g-ui-burger', [opened, 'g-ui-burger-open'], className) },
9
+ Span(''),
10
+ Span(''),
11
+ Span('')
12
+ );
13
+ }
@@ -0,0 +1,37 @@
1
+ import { Button as HtmlButton, Span, when, after} from '@granularjs/core';
2
+ import { cx, splitPropsChildren, resolveBool, classVar, classFlag } from '../utils.js';
3
+
4
+ export function Button(...args) {
5
+ const { props, children } = splitPropsChildren(args, { variant: 'filled', size: 'md' });
6
+ const {
7
+ variant,
8
+ size,
9
+ fullWidth,
10
+ loading,
11
+ leftSection,
12
+ rightSection,
13
+ className,
14
+ disabled,
15
+ ...rest
16
+ } = props;
17
+
18
+ const isDisabled = after(disabled, loading).compute(([disabled, loading]) => disabled || loading);
19
+
20
+ return HtmlButton(
21
+ {
22
+ ...rest,
23
+ disabled: isDisabled,
24
+ className: cx(
25
+ 'g-ui-button',
26
+ classVar('g-ui-button-variant-', variant, 'filled'),
27
+ classVar('g-ui-button-size-', size, 'md'),
28
+ classFlag('g-ui-button-full', fullWidth),
29
+ classFlag('g-ui-button-loading', loading),
30
+ className
31
+ ),
32
+ },
33
+ when(leftSection, () => Span({ className: 'g-ui-button-section-left' }, leftSection)),
34
+ when(loading, () => Span('Loading...'), () => children),
35
+ when(rightSection, () => Span({ className: 'g-ui-button-section-right' }, rightSection))
36
+ );
37
+ }
@@ -0,0 +1,109 @@
1
+ import { Button, Div, state, after } from '@granularjs/core';
2
+ import { cx, splitPropsChildren, resolveValue, classVar } from '../utils.js';
3
+ import { forwardSvg, backwardSvg } from '../theme/icons.js';
4
+ import { ActionIcon } from './ActionIcon.js';
5
+ import { Icon } from './Icon.js';
6
+
7
+ const weekDays = ['S', 'M', 'T', 'W', 'T', 'F', 'S'];
8
+
9
+ export function Calendar(...args) {
10
+ const { props, rawProps } = splitPropsChildren(args, { size: 'md' });
11
+ const { value, className, size, ...rest } = props;
12
+ const { onChange } = rawProps;
13
+ const resolveDate = (next) => {
14
+ const resolved = resolveValue(next);
15
+ if (resolved instanceof Date) return resolved;
16
+ if (resolved == null) return null;
17
+ const parsed = new Date(resolved);
18
+ if (Number.isNaN(parsed.getTime())) return null;
19
+ return parsed;
20
+ };
21
+ const currentState = state(resolveDate(value) ?? new Date());
22
+ const viewState = state(new Date(currentState.get()));
23
+
24
+ after(value).change((next) => {
25
+ const resolved = resolveDate(next);
26
+ if (resolved == null) return;
27
+ currentState.set(resolved);
28
+ viewState.set(new Date(resolved));
29
+ });
30
+
31
+ const createDate = (year, month, day) => {
32
+ const maxDay = new Date(year, month + 1, 0).getDate();
33
+ return new Date(year, month, Math.min(day, maxDay));
34
+ };
35
+
36
+ const setDate = (day) => {
37
+ const current = viewState.get();
38
+ const next = createDate(current.getFullYear(), current.getMonth(), day);
39
+ currentState.set(next);
40
+ viewState.set(next);
41
+ onChange?.(next);
42
+ };
43
+
44
+ const shiftMonth = (delta) => {
45
+ const current = viewState.get();
46
+ const next = createDate(current.getFullYear(), current.getMonth() + delta, current.getDate());
47
+ viewState.set(next);
48
+ };
49
+
50
+ const shiftYear = (delta) => {
51
+ const current = viewState.get();
52
+ const next = createDate(current.getFullYear() + delta, current.getMonth(), current.getDate());
53
+ viewState.set(next);
54
+ };
55
+
56
+ const monthLabel = after(viewState).compute((current) => current.toLocaleString('default', { month: 'long' }));
57
+ const yearLabel = after(viewState).compute((current) => String(current.getFullYear()));
58
+ const gridCells = after(viewState, currentState).compute(([current, selected]) => {
59
+ const year = current.getFullYear();
60
+ const month = current.getMonth();
61
+ const first = new Date(year, month, 1);
62
+ const start = first.getDay();
63
+ const daysInMonth = new Date(year, month + 1, 0).getDate();
64
+ const cells = [];
65
+ for (let i = 0; i < start; i += 1) cells.push({ muted: true, label: '' });
66
+ for (let d = 1; d <= daysInMonth; d += 1) cells.push({ label: d });
67
+ return [
68
+ ...weekDays.map((d) => Div({ className: 'g-ui-calendar-cell g-ui-calendar-cell-muted' }, d)),
69
+ ...cells.map((c) =>
70
+ Div(
71
+ {
72
+ className: cx(
73
+ 'g-ui-calendar-cell',
74
+ c.muted && 'g-ui-calendar-cell-muted',
75
+ c.label &&
76
+ selected.getFullYear() === year &&
77
+ selected.getMonth() === month &&
78
+ c.label === selected.getDate() &&
79
+ 'g-ui-calendar-cell-active'
80
+ ),
81
+ onClick: () => c.label && setDate(c.label),
82
+ },
83
+ c.label
84
+ )
85
+ ),
86
+ ];
87
+ });
88
+
89
+ return Div(
90
+ { ...rest, className: cx('g-ui-calendar', className, classVar('g-ui-calendar-size-', size, 'md')) },
91
+ Div(
92
+ { className: 'g-ui-calendar-header' },
93
+ ActionIcon(
94
+ { size: 'xs', variant: 'subtle', className: 'g-ui-calendar-nav', onClick: () => shiftMonth(-1) },
95
+ Icon({ size: 'sm', className: 'g-ui-calendar-nav-icon', innerHTML: backwardSvg })
96
+ ),
97
+ Div(
98
+ { className: 'g-ui-calendar-title-group' },
99
+ Button({ type: 'button', className: 'g-ui-calendar-title-button', onClick: () => shiftMonth(1) }, monthLabel),
100
+ Button({ type: 'button', className: 'g-ui-calendar-title-button', onClick: () => shiftYear(1) }, yearLabel)
101
+ ),
102
+ ActionIcon(
103
+ { size: 'xs', variant: 'subtle', className: 'g-ui-calendar-nav', onClick: () => shiftMonth(1) },
104
+ Icon({ size: 'sm', className: 'g-ui-calendar-nav-icon', innerHTML: forwardSvg })
105
+ )
106
+ ),
107
+ Div({ className: 'g-ui-calendar-grid' }, gridCells)
108
+ );
109
+ }
@@ -0,0 +1,40 @@
1
+ import { Div, list, when, after } from '@granularjs/core';
2
+ import { cx, splitPropsChildren, classVar } from '../utils.js';
3
+ import { Button } from './Button.js';
4
+
5
+ export function Card(...args) {
6
+ const { props, children } = splitPropsChildren(args, { padding: 'md', radius: 'md', shadow: 'none', border: 'default' });
7
+ const { title, content, actions, border, padding, radius, shadow, className, style, ...rest } = props;
8
+
9
+ return Div(
10
+ when(title, () => Div({ className: 'g-ui-card-title' }, title)),
11
+ when(content, () => Div({ className: 'g-ui-card-content' }, content)),
12
+ when(actions, () => Div(
13
+ { className: 'g-ui-card-actions' },
14
+ list(actions, (action) => Button(
15
+ {
16
+ className: 'g-ui-card-action',
17
+ onClick: (e) => action.onClick.get()?.(e),
18
+ leftSection: action.leftSection,
19
+ rightSection: action.rightSection,
20
+ size: after(action.size).compute(s => s || 'sm'),
21
+ variant: after(action.variant).compute(v => v || 'outline'),
22
+ ...(action.props.get() || {}),
23
+ },
24
+ action.label
25
+ ))
26
+ )),
27
+ {
28
+ className: cx(
29
+ 'g-ui-card',
30
+ classVar('g-ui-card-border-', border, 'md'),
31
+ classVar('g-ui-card-padding-', padding, 'md'),
32
+ classVar('g-ui-card-radius-', radius, 'md'),
33
+ classVar('g-ui-card-shadow-', shadow, 'md'),
34
+ className
35
+ ),
36
+ ...rest,
37
+ },
38
+ children
39
+ );
40
+ }
@@ -0,0 +1,8 @@
1
+ import { Div } from '@granularjs/core';
2
+ import { cx, splitPropsChildren } from '../utils.js';
3
+
4
+ export function Center(...args) {
5
+ const { props, children } = splitPropsChildren(args);
6
+ const { className, ...rest } = props;
7
+ return Div({ ...rest, className: cx('g-ui-center', className) }, children);
8
+ }
@@ -0,0 +1,46 @@
1
+ import { Div, Input, Label, Span, when, state, after } from '@granularjs/core';
2
+ import { cx, splitPropsChildren, classVar, resolveBool } from '../utils.js';
3
+ import { checkedSvg, indeterminateSvg } from '../theme/icons.js';
4
+
5
+ export function Checkbox(...args) {
6
+ const { props, rawProps } = splitPropsChildren(args, { size: 'md' });
7
+ const { checked, label, description, size, indeterminate, className, style, inputProps, ...rest } = props;
8
+ const { onChange } = rawProps;
9
+ const currentState = state(resolveBool(checked));
10
+
11
+ after(checked).change((next) => {
12
+ if (next == null) return;
13
+ currentState.set(!!next);
14
+ onChange?.(next);
15
+ });
16
+
17
+ const control = Label(
18
+ { className: 'g-ui-checkbox-control' },
19
+ Input({
20
+ type: 'checkbox',
21
+ indeterminate: indeterminate,
22
+ checked: currentState,
23
+ className: cx(
24
+ 'g-ui-checkbox-input',
25
+ classVar('g-ui-checkbox-size-', size, 'md'),
26
+ inputProps?.className
27
+ ),
28
+ ...rest,
29
+ }),
30
+ when(currentState,
31
+ () => Div({ className: 'g-ui-checkbox-checked', innerHTML: checkedSvg }),
32
+ () => {
33
+ if (!currentState.get() && indeterminate.get()) {
34
+ return Div({ className: 'g-ui-checkbox-indeterminate', innerHTML: indeterminateSvg });
35
+ }
36
+ }
37
+ ),
38
+ when(label, () => Span({ className: 'g-ui-checkbox-label' }, label))
39
+ );
40
+
41
+ return Div(
42
+ { className: cx('g-ui-checkbox', classVar('g-ui-checkbox-size-', size, 'md'), className) },
43
+ control,
44
+ when(description, () => Span({ className: 'g-ui-checkbox-description' }, description))
45
+ );
46
+ }
@@ -0,0 +1,8 @@
1
+ import { Div } from '@granularjs/core';
2
+ import { cx, splitPropsChildren } from '../utils.js';
3
+
4
+ export function CheckboxGroup(...args) {
5
+ const { props, children } = splitPropsChildren(args);
6
+ const { className, ...rest } = props;
7
+ return Div({ ...rest, className: cx('g-ui-checkbox-group', className) }, children);
8
+ }
@@ -0,0 +1,35 @@
1
+ import { Button, after, state } from '@granularjs/core';
2
+ import { cx, splitPropsChildren, classVar } from '../utils.js';
3
+
4
+ export function Chip(...args) {
5
+ const { props, rawProps, children } = splitPropsChildren(args, { size: 'md', variant: 'filled' });
6
+ const { checked, size, variant, className, ...rest } = props;
7
+ const { onChange } = rawProps;
8
+ const currentState = state(!!checked);
9
+ after(checked).change((next) => {
10
+ if (next == null) return;
11
+ currentState.set(!!next);
12
+ });
13
+ const setChecked = (next) => {
14
+ currentState.set(next);
15
+ onChange?.(next);
16
+ };
17
+ return Button(
18
+ {
19
+ ...rest,
20
+ type: 'button',
21
+ className: cx(
22
+ 'g-ui-chip',
23
+ classVar('g-ui-chip-size-', size, 'md'),
24
+ classVar('g-ui-chip-variant-', variant, 'filled'),
25
+ after(currentState).compute((current) => {
26
+ if (current) return 'g-ui-chip-active';
27
+ return '';
28
+ }),
29
+ className
30
+ ),
31
+ onClick: () => setChecked(!currentState.get()),
32
+ },
33
+ children
34
+ );
35
+ }
@@ -0,0 +1,8 @@
1
+ import { Code as HtmlCode } from '@granularjs/core';
2
+ import { cx, splitPropsChildren } from '../utils.js';
3
+
4
+ export function Code(...args) {
5
+ const { props, children } = splitPropsChildren(args);
6
+ const { className, ...rest } = props;
7
+ return HtmlCode({ ...rest, className: cx('g-ui-code', className) }, children);
8
+ }
@@ -0,0 +1,8 @@
1
+ import { Div } from '@granularjs/core';
2
+ import { cx, splitPropsChildren } from '../utils.js';
3
+
4
+ export function Col(...args) {
5
+ const { props, children } = splitPropsChildren(args, { span: 12 });
6
+ const { span, className, ...rest } = props;
7
+ return Div({ ...rest, className: cx([span, (value) => `g-ui-col-span-${value}`], className) }, children);
8
+ }
@@ -0,0 +1,8 @@
1
+ import { Div, when } from '@granularjs/core';
2
+ import { cx, splitPropsChildren } from '../utils.js';
3
+
4
+ export function Collapse(...args) {
5
+ const { props, children } = splitPropsChildren(args);
6
+ const { opened, className, ...rest } = props;
7
+ return when(opened, () => Div({ ...rest, className: cx('g-ui-collapse', className) }, children));
8
+ }
@@ -0,0 +1,19 @@
1
+ import { Div } from '@granularjs/core';
2
+ import { cx, splitPropsChildren, classVar, classFlag } from '../utils.js';
3
+
4
+ export function Container(...args) {
5
+ const { props, children } = splitPropsChildren(args, { size: 'md' });
6
+ const { size, fluid, className, style, ...rest } = props;
7
+ return Div(
8
+ {
9
+ ...rest,
10
+ className: cx(
11
+ 'g-ui-container',
12
+ classFlag('g-ui-container-fluid', fluid),
13
+ classVar('g-ui-container-size-', size, 'md'),
14
+ className
15
+ ),
16
+ },
17
+ children
18
+ );
19
+ }