@journ/nude-solid 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +159 -2
  3. package/dist/accordion.d.ts +42 -0
  4. package/dist/accordion.jsx +64 -0
  5. package/dist/alert.d.ts +15 -0
  6. package/dist/alert.jsx +9 -0
  7. package/dist/badge.d.ts +2 -0
  8. package/dist/badge.jsx +3 -0
  9. package/dist/bulk-bar.d.ts +9 -0
  10. package/dist/bulk-bar.jsx +6 -0
  11. package/dist/button.d.ts +8 -0
  12. package/dist/button.jsx +9 -0
  13. package/dist/card.d.ts +17 -0
  14. package/dist/card.jsx +10 -0
  15. package/dist/checkbox.d.ts +9 -0
  16. package/dist/checkbox.jsx +3 -0
  17. package/dist/collapsible.d.ts +35 -0
  18. package/dist/collapsible.jsx +39 -0
  19. package/dist/composer.d.ts +7 -0
  20. package/dist/composer.jsx +5 -0
  21. package/dist/controllable.d.ts +11 -0
  22. package/dist/controllable.js +26 -0
  23. package/dist/description-list.d.ts +9 -0
  24. package/dist/description-list.jsx +6 -0
  25. package/dist/dialog.d.ts +49 -0
  26. package/dist/dialog.jsx +84 -0
  27. package/dist/divider.d.ts +2 -0
  28. package/dist/divider.jsx +3 -0
  29. package/dist/empty-state.d.ts +13 -0
  30. package/dist/empty-state.jsx +8 -0
  31. package/dist/events.d.ts +4 -0
  32. package/dist/events.js +6 -0
  33. package/dist/field.d.ts +40 -0
  34. package/dist/field.jsx +55 -0
  35. package/dist/index.d.ts +36 -0
  36. package/dist/index.js +36 -0
  37. package/dist/input.d.ts +2 -0
  38. package/dist/input.jsx +3 -0
  39. package/dist/lib/form-reset.d.ts +4 -0
  40. package/dist/lib/form-reset.js +17 -0
  41. package/dist/lib/toggle.d.ts +40 -0
  42. package/dist/lib/toggle.jsx +70 -0
  43. package/dist/list-row.d.ts +19 -0
  44. package/dist/list-row.jsx +11 -0
  45. package/dist/nav-bar.d.ts +7 -0
  46. package/dist/nav-bar.jsx +5 -0
  47. package/dist/page-header.d.ts +9 -0
  48. package/dist/page-header.jsx +6 -0
  49. package/dist/page.d.ts +9 -0
  50. package/dist/page.jsx +6 -0
  51. package/dist/part.d.ts +8 -0
  52. package/dist/part.jsx +10 -0
  53. package/dist/portal.d.ts +8 -0
  54. package/dist/portal.jsx +3 -0
  55. package/dist/progress.d.ts +8 -0
  56. package/dist/progress.jsx +3 -0
  57. package/dist/radio.d.ts +45 -0
  58. package/dist/radio.jsx +83 -0
  59. package/dist/select.d.ts +15 -0
  60. package/dist/select.jsx +33 -0
  61. package/dist/sidebar.d.ts +21 -0
  62. package/dist/sidebar.jsx +12 -0
  63. package/dist/skeleton.d.ts +2 -0
  64. package/dist/skeleton.jsx +3 -0
  65. package/dist/stat.d.ts +11 -0
  66. package/dist/stat.jsx +7 -0
  67. package/dist/switch.d.ts +9 -0
  68. package/dist/switch.jsx +3 -0
  69. package/dist/table.d.ts +17 -0
  70. package/dist/table.jsx +10 -0
  71. package/dist/tabs.d.ts +49 -0
  72. package/dist/tabs.jsx +68 -0
  73. package/dist/tag-input.d.ts +52 -0
  74. package/dist/tag-input.jsx +107 -0
  75. package/dist/text.d.ts +2 -0
  76. package/dist/text.jsx +3 -0
  77. package/dist/textarea.d.ts +2 -0
  78. package/dist/textarea.jsx +3 -0
  79. package/dist/tile.d.ts +15 -0
  80. package/dist/tile.jsx +9 -0
  81. package/package.json +277 -3
package/dist/radio.jsx ADDED
@@ -0,0 +1,83 @@
1
+ import { Show, createContext, createUniqueId, omit, onSettled, useContext } from 'solid-js';
2
+ import { createControllable } from './controllable.js';
3
+ import { composeEventHandlers } from './events.js';
4
+ import { part } from './part.jsx';
5
+ import { createFormReset } from './lib/form-reset.js';
6
+ const Context = createContext();
7
+ const ItemContext = createContext();
8
+ const useRadio = () => useContext(Context);
9
+ const Provider = (props) => (<Context value={props}>{props.children}</Context>);
10
+ const Root = (props) => {
11
+ const id = createUniqueId();
12
+ let element;
13
+ const [value, select] = createControllable({
14
+ value: () => props.value,
15
+ defaultValue: () => props.defaultValue ?? null,
16
+ onChange: next => props.onValueChange?.(next),
17
+ });
18
+ createFormReset(() => element, () => {
19
+ select(props.defaultValue ?? null);
20
+ onSettled(() => {
21
+ for (const input of element?.querySelectorAll('input[type="radio"]') ?? []) {
22
+ if (input.closest('[data-slot="radio"]') === element)
23
+ input.checked = input.value === value();
24
+ }
25
+ });
26
+ });
27
+ return (<Provider state={{
28
+ get value() {
29
+ return value();
30
+ },
31
+ }} actions={{ select }} meta={{
32
+ get name() {
33
+ return typeof props.name === 'string' ? props.name : id;
34
+ },
35
+ get disabled() {
36
+ return props.disabled ?? false;
37
+ },
38
+ get required() {
39
+ return props.required ?? false;
40
+ },
41
+ }}>
42
+ <fieldset {...omit(props, 'value', 'defaultValue', 'onValueChange', 'required', 'ref')} ref={[
43
+ props.ref,
44
+ next => {
45
+ element = next;
46
+ },
47
+ ]} data-slot='radio'/>
48
+ </Provider>);
49
+ };
50
+ const Item = (props) => {
51
+ const context = useRadio();
52
+ return (<ItemContext value={{
53
+ get value() {
54
+ return props.value;
55
+ },
56
+ get disabled() {
57
+ return props.disabled || context.meta.disabled;
58
+ },
59
+ }}>
60
+ <label {...omit(props, 'value', 'disabled')} data-slot='radio-item' data-state={context.state.value === props.value ? 'checked' : 'unchecked'}/>
61
+ </ItemContext>);
62
+ };
63
+ const Control = (props) => {
64
+ const context = useRadio();
65
+ const item = useContext(ItemContext);
66
+ return (<input {...omit(props, 'onChange')} type='radio' data-slot='radio-control' name={context.meta.name} value={item.value} checked={context.state.value === item.value} disabled={item.disabled || props.disabled} required={context.meta.required || props.required} onChange={event => {
67
+ composeEventHandlers(props.onChange, () => {
68
+ if (event.currentTarget.checked)
69
+ context.actions.select(item.value);
70
+ })(event);
71
+ event.currentTarget.checked = context.state.value === item.value;
72
+ }}/>);
73
+ };
74
+ const Indicator = (props) => {
75
+ const context = useRadio();
76
+ const item = useContext(ItemContext);
77
+ return (<Show when={context.state.value === item.value}>
78
+ <span {...props} data-slot='radio-indicator' aria-hidden='true'/>
79
+ </Show>);
80
+ };
81
+ const Legend = part('legend', 'radio-legend');
82
+ const Radio = { Root, Provider, Legend, Item, Control, Indicator };
83
+ export { Radio, useRadio };
@@ -0,0 +1,15 @@
1
+ import type { JSX } from '@solidjs/web';
2
+ type SelectProps = Omit<JSX.SelectHTMLAttributes<HTMLSelectElement>, 'value' | 'multiple' | 'onChange'> & {
3
+ value?: string;
4
+ defaultValue?: string;
5
+ onValueChange?: (value: string) => void;
6
+ onChange?: JSX.EventHandler<HTMLSelectElement, Event>;
7
+ };
8
+ declare const Root: (props: SelectProps) => JSX.Element;
9
+ declare const Select: {
10
+ Root: typeof Root;
11
+ Item: import("./part.jsx").Part<"option">;
12
+ Group: import("./part.jsx").Part<"optgroup">;
13
+ };
14
+ export { Select };
15
+ export type { SelectProps };
@@ -0,0 +1,33 @@
1
+ import { omit, onSettled } from 'solid-js';
2
+ import { createControllable } from './controllable.js';
3
+ import { composeEventHandlers } from './events.js';
4
+ import { part } from './part.jsx';
5
+ import { createFormReset } from './lib/form-reset.js';
6
+ const Root = (props) => {
7
+ let element;
8
+ const [value, setValue] = createControllable({
9
+ value: () => props.value,
10
+ defaultValue: () => props.defaultValue ?? '',
11
+ onChange: next => props.onValueChange?.(next),
12
+ });
13
+ createFormReset(() => element, () => {
14
+ setValue(props.defaultValue ?? '');
15
+ onSettled(() => {
16
+ if (element)
17
+ element.value = value();
18
+ });
19
+ });
20
+ return (<select {...omit(props, 'defaultValue', 'onValueChange', 'onChange', 'ref')} ref={[
21
+ props.ref,
22
+ next => {
23
+ element = next;
24
+ },
25
+ ]} data-slot='select' value={value()} onChange={event => {
26
+ composeEventHandlers(props.onChange, () => setValue(event.currentTarget.value))(event);
27
+ event.currentTarget.value = value();
28
+ }}/>);
29
+ };
30
+ const Item = part('option', 'select-item');
31
+ const Group = part('optgroup', 'select-group');
32
+ const Select = { Root, Item, Group };
33
+ export { Select };
@@ -0,0 +1,21 @@
1
+ declare const Layout: import("./part.jsx").Part<"div">;
2
+ declare const Content: import("./part.jsx").Part<"main">;
3
+ declare const Root: import("./part.jsx").Part<"aside">;
4
+ declare const Header: import("./part.jsx").Part<"div">;
5
+ declare const Body: import("./part.jsx").Part<"nav">;
6
+ declare const Section: import("./part.jsx").Part<"div">;
7
+ declare const Heading: import("./part.jsx").Part<"h3">;
8
+ declare const Item: import("./part.jsx").Part<"a">;
9
+ declare const Footer: import("./part.jsx").Part<"div">;
10
+ declare const Sidebar: {
11
+ Layout: typeof Layout;
12
+ Root: typeof Root;
13
+ Header: typeof Header;
14
+ Body: typeof Body;
15
+ Section: typeof Section;
16
+ Heading: typeof Heading;
17
+ Item: typeof Item;
18
+ Footer: typeof Footer;
19
+ Content: typeof Content;
20
+ };
21
+ export { Sidebar };
@@ -0,0 +1,12 @@
1
+ import { part } from './part.jsx';
2
+ const Layout = part('div', 'sidebar-layout');
3
+ const Content = part('main', 'sidebar-content');
4
+ const Root = part('aside', 'sidebar');
5
+ const Header = part('div', 'sidebar-header');
6
+ const Body = part('nav', 'sidebar-body');
7
+ const Section = part('div', 'sidebar-section');
8
+ const Heading = part('h3', 'sidebar-heading');
9
+ const Item = part('a', 'sidebar-item');
10
+ const Footer = part('div', 'sidebar-footer');
11
+ const Sidebar = { Layout, Root, Header, Body, Section, Heading, Item, Footer, Content };
12
+ export { Sidebar };
@@ -0,0 +1,2 @@
1
+ declare const Skeleton: import("./part.jsx").Part<"div">;
2
+ export { Skeleton };
@@ -0,0 +1,3 @@
1
+ import { part } from './part.jsx';
2
+ const Skeleton = part('div', 'skeleton', { 'aria-hidden': 'true' });
3
+ export { Skeleton };
package/dist/stat.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ declare const Root: import("./part.jsx").Part<"div">;
2
+ declare const Label: import("./part.jsx").Part<"p">;
3
+ declare const Value: import("./part.jsx").Part<"p">;
4
+ declare const Hint: import("./part.jsx").Part<"p">;
5
+ declare const Stat: {
6
+ Root: typeof Root;
7
+ Label: typeof Label;
8
+ Value: typeof Value;
9
+ Hint: typeof Hint;
10
+ };
11
+ export { Stat };
package/dist/stat.jsx ADDED
@@ -0,0 +1,7 @@
1
+ import { part } from './part.jsx';
2
+ const Root = part('div', 'stat');
3
+ const Label = part('p', 'stat-label');
4
+ const Value = part('p', 'stat-value');
5
+ const Hint = part('p', 'stat-hint');
6
+ const Stat = { Root, Label, Value, Hint };
7
+ export { Stat };
@@ -0,0 +1,9 @@
1
+ declare const useSwitch: () => import("./checkbox.jsx").CheckboxContextValue, Switch: {
2
+ Root: (props: import("./checkbox.jsx").CheckboxProps) => import("@solidjs/web").JSX.Element;
3
+ Provider: (props: import("solid-js").ParentProps<import("./checkbox.jsx").CheckboxContextValue>) => import("@solidjs/web").JSX.Element;
4
+ Control: (props: import("./lib/toggle.jsx").ToggleControlProps) => import("@solidjs/web").JSX.Element;
5
+ Indicator: (props: import("@solidjs/web").JSX.HTMLAttributes<HTMLSpanElement>) => import("@solidjs/web").JSX.Element;
6
+ Thumb: (props: import("@solidjs/web").JSX.HTMLAttributes<HTMLSpanElement>) => import("@solidjs/web").JSX.Element;
7
+ };
8
+ export { Switch, useSwitch };
9
+ export type { ToggleContextValue as SwitchContextValue, ToggleProps as SwitchProps } from './lib/toggle.jsx';
@@ -0,0 +1,3 @@
1
+ import { createToggle } from './lib/toggle.jsx';
2
+ const { useToggle: useSwitch, ...Switch } = createToggle('switch');
3
+ export { Switch, useSwitch };
@@ -0,0 +1,17 @@
1
+ declare const Root: import("./part.jsx").Part<"table">;
2
+ declare const Caption: import("./part.jsx").Part<"caption">;
3
+ declare const Head: import("./part.jsx").Part<"thead">;
4
+ declare const Body: import("./part.jsx").Part<"tbody">;
5
+ declare const Row: import("./part.jsx").Part<"tr">;
6
+ declare const Header: import("./part.jsx").Part<"th">;
7
+ declare const Cell: import("./part.jsx").Part<"td">;
8
+ declare const Table: {
9
+ Root: typeof Root;
10
+ Caption: typeof Caption;
11
+ Head: typeof Head;
12
+ Body: typeof Body;
13
+ Row: typeof Row;
14
+ Header: typeof Header;
15
+ Cell: typeof Cell;
16
+ };
17
+ export { Table };
package/dist/table.jsx ADDED
@@ -0,0 +1,10 @@
1
+ import { part } from './part.jsx';
2
+ const Root = part('table', 'table');
3
+ const Caption = part('caption', 'table-caption');
4
+ const Head = part('thead', 'table-head');
5
+ const Body = part('tbody', 'table-body');
6
+ const Row = part('tr', 'table-row');
7
+ const Header = part('th', 'table-header');
8
+ const Cell = part('td', 'table-cell');
9
+ const Table = { Root, Caption, Head, Body, Row, Header, Cell };
10
+ export { Table };
package/dist/tabs.d.ts ADDED
@@ -0,0 +1,49 @@
1
+ import type { JSX } from '@solidjs/web';
2
+ import { type ParentProps } from 'solid-js';
3
+ import { type ButtonProps } from './button.jsx';
4
+ type TabsContextValue = {
5
+ state: {
6
+ readonly value: string;
7
+ };
8
+ actions: {
9
+ select: (value: string) => void;
10
+ };
11
+ meta: {
12
+ readonly id: string;
13
+ readonly orientation: 'horizontal' | 'vertical';
14
+ readonly activationMode: 'automatic' | 'manual';
15
+ readonly dir: 'ltr' | 'rtl';
16
+ };
17
+ };
18
+ declare const useTabs: () => TabsContextValue;
19
+ declare const Provider: (props: ParentProps<TabsContextValue>) => JSX.Element;
20
+ type TabsProps = ParentProps<{
21
+ value?: string;
22
+ defaultValue: string;
23
+ onValueChange?: (value: string) => void;
24
+ orientation?: 'horizontal' | 'vertical';
25
+ activationMode?: 'automatic' | 'manual';
26
+ dir?: 'ltr' | 'rtl';
27
+ }>;
28
+ declare const Root: (props: TabsProps) => JSX.Element;
29
+ type ListProps = Omit<JSX.HTMLAttributes<HTMLDivElement>, 'onKeyDown'> & {
30
+ onKeyDown?: JSX.EventHandler<HTMLDivElement, KeyboardEvent>;
31
+ };
32
+ declare const List: (props: ListProps) => JSX.Element;
33
+ type TriggerProps = ButtonProps & {
34
+ value: string;
35
+ };
36
+ declare const Trigger: (props: TriggerProps) => JSX.Element;
37
+ type ContentProps = JSX.HTMLAttributes<HTMLDivElement> & {
38
+ value: string;
39
+ };
40
+ declare const Content: (props: ContentProps) => JSX.Element;
41
+ declare const Tabs: {
42
+ Root: typeof Root;
43
+ Provider: typeof Provider;
44
+ List: typeof List;
45
+ Trigger: typeof Trigger;
46
+ Content: typeof Content;
47
+ };
48
+ export { Tabs, useTabs };
49
+ export type { TabsContextValue, TabsProps, TriggerProps as TabsTriggerProps, ContentProps as TabsContentProps };
package/dist/tabs.jsx ADDED
@@ -0,0 +1,68 @@
1
+ import { createContext, createUniqueId, omit, useContext } from 'solid-js';
2
+ import { Button } from './button.jsx';
3
+ import { createControllable } from './controllable.js';
4
+ import { composeEventHandlers } from './events.js';
5
+ const Context = createContext();
6
+ const useTabs = () => useContext(Context);
7
+ const Provider = (props) => (<Context value={props}>{props.children}</Context>);
8
+ const Root = (props) => {
9
+ const id = createUniqueId();
10
+ const [value, select] = createControllable({
11
+ value: () => props.value,
12
+ defaultValue: () => props.defaultValue,
13
+ onChange: next => props.onValueChange?.(next),
14
+ });
15
+ return (<Provider state={{
16
+ get value() {
17
+ return value();
18
+ },
19
+ }} actions={{ select }} meta={{
20
+ id,
21
+ get orientation() {
22
+ return props.orientation ?? 'horizontal';
23
+ },
24
+ get activationMode() {
25
+ return props.activationMode ?? 'automatic';
26
+ },
27
+ get dir() {
28
+ return props.dir ?? 'ltr';
29
+ },
30
+ }}>
31
+ {props.children}
32
+ </Provider>);
33
+ };
34
+ const List = (props) => {
35
+ const context = useTabs();
36
+ return (<div {...omit(props, 'onKeyDown')} data-slot='tabs-list' role='tablist' aria-orientation={context.meta.orientation} dir={context.meta.dir} onKeyDown={event => composeEventHandlers(props.onKeyDown, () => {
37
+ if (event.altKey || event.ctrlKey || event.metaKey)
38
+ return;
39
+ const vertical = context.meta.orientation === 'vertical';
40
+ const forward = vertical ? 'ArrowDown' : context.meta.dir === 'rtl' ? 'ArrowLeft' : 'ArrowRight';
41
+ const backward = vertical ? 'ArrowUp' : context.meta.dir === 'rtl' ? 'ArrowRight' : 'ArrowLeft';
42
+ if (![forward, backward, 'Home', 'End'].includes(event.key))
43
+ return;
44
+ const tabs = Array.from(event.currentTarget.querySelectorAll('[role="tab"]:not(:disabled)')).filter(tab => tab.closest('[role="tablist"]') === event.currentTarget);
45
+ const index = tabs.findIndex(tab => tab === event.target);
46
+ if (index < 0 || tabs.length === 0)
47
+ return;
48
+ const next = event.key === 'Home'
49
+ ? 0
50
+ : event.key === 'End'
51
+ ? tabs.length - 1
52
+ : (index + (event.key === forward ? 1 : -1) + tabs.length) % tabs.length;
53
+ event.preventDefault();
54
+ tabs[next]?.focus();
55
+ if (context.meta.activationMode === 'automatic')
56
+ tabs[next]?.click();
57
+ })(event)}/>);
58
+ };
59
+ const Trigger = (props) => {
60
+ const context = useTabs();
61
+ return (<Button {...omit(props, 'value', 'onClick')} data-slot='tabs-trigger' role='tab' id={`${context.meta.id}-tab-${encodeURIComponent(props.value)}`} aria-controls={`${context.meta.id}-panel-${encodeURIComponent(props.value)}`} aria-selected={context.state.value === props.value ? 'true' : 'false'} tabindex={context.state.value === props.value ? 0 : -1} data-state={context.state.value === props.value ? 'active' : 'inactive'} onClick={event => composeEventHandlers(props.onClick, () => context.actions.select(props.value))(event)}/>);
62
+ };
63
+ const Content = (props) => {
64
+ const context = useTabs();
65
+ return (<div {...omit(props, 'value')} data-slot='tabs-content' role='tabpanel' tabindex={0} id={`${context.meta.id}-panel-${encodeURIComponent(props.value)}`} aria-labelledby={`${context.meta.id}-tab-${encodeURIComponent(props.value)}`} data-state={context.state.value === props.value ? 'active' : 'inactive'} hidden={context.state.value !== props.value}/>);
66
+ };
67
+ const Tabs = { Root, Provider, List, Trigger, Content };
68
+ export { Tabs, useTabs };
@@ -0,0 +1,52 @@
1
+ import type { JSX } from '@solidjs/web';
2
+ import { type ParentProps } from 'solid-js';
3
+ import { type ButtonProps } from './button.jsx';
4
+ type TagInputContextValue = {
5
+ state: {
6
+ readonly tags: readonly string[];
7
+ readonly text: string;
8
+ readonly invalid: boolean;
9
+ };
10
+ actions: {
11
+ edit: (text: string) => void;
12
+ add: (...tags: string[]) => void;
13
+ remove: (tag: string) => void;
14
+ removeLast: () => void;
15
+ };
16
+ meta: {
17
+ readonly disabled: boolean;
18
+ };
19
+ };
20
+ type TagInputProps = ParentProps<{
21
+ value?: readonly string[];
22
+ defaultValue?: readonly string[];
23
+ onValueChange?: (tags: readonly string[]) => void;
24
+ validate?: (tag: string) => boolean;
25
+ disabled?: boolean;
26
+ }>;
27
+ declare const useTagInput: () => TagInputContextValue;
28
+ declare const Provider: (props: ParentProps<TagInputContextValue>) => JSX.Element;
29
+ declare const Root: (props: TagInputProps) => JSX.Element;
30
+ type TagFieldProps = Omit<JSX.InputHTMLAttributes<HTMLInputElement>, 'value' | 'onInput' | 'onKeyDown' | 'onBlur' | 'onPaste'> & {
31
+ onInput?: JSX.EventHandler<HTMLInputElement, InputEvent>;
32
+ onKeyDown?: JSX.EventHandler<HTMLInputElement, KeyboardEvent>;
33
+ onBlur?: JSX.EventHandler<HTMLInputElement, FocusEvent>;
34
+ onPaste?: JSX.EventHandler<HTMLInputElement, ClipboardEvent>;
35
+ };
36
+ declare const Field: (props: TagFieldProps) => JSX.Element;
37
+ declare const Tag: (props: JSX.HTMLAttributes<HTMLSpanElement> & {
38
+ value: string;
39
+ }) => JSX.Element;
40
+ declare const Remove: (props: ButtonProps) => JSX.Element;
41
+ declare const Tags: () => JSX.Element;
42
+ declare const TagInput: {
43
+ Root: typeof Root;
44
+ Provider: typeof Provider;
45
+ Frame: import("./part.jsx").Part<"div">;
46
+ Field: typeof Field;
47
+ Tags: typeof Tags;
48
+ Tag: typeof Tag;
49
+ Remove: typeof Remove;
50
+ };
51
+ export { TagInput, useTagInput };
52
+ export type { TagInputContextValue, TagInputProps, TagFieldProps };
@@ -0,0 +1,107 @@
1
+ import { For, createContext, createSignal, omit, useContext } from 'solid-js';
2
+ import { Button } from './button.jsx';
3
+ import { createControllable } from './controllable.js';
4
+ import { composeEventHandlers } from './events.js';
5
+ import { part } from './part.jsx';
6
+ const Context = createContext();
7
+ const TagContext = createContext();
8
+ const useTagInput = () => useContext(Context);
9
+ const Provider = (props) => (<Context value={props}>{props.children}</Context>);
10
+ const Root = (props) => {
11
+ const [tags, setTags] = createControllable({
12
+ value: () => props.value,
13
+ defaultValue: () => props.defaultValue ?? [],
14
+ onChange: next => props.onValueChange?.(next),
15
+ });
16
+ const [text, setText] = createSignal('');
17
+ const [invalid, setInvalid] = createSignal(false);
18
+ const edit = (next) => {
19
+ setInvalid(false);
20
+ setText(next);
21
+ };
22
+ const add = (...incoming) => {
23
+ if (props.disabled)
24
+ return;
25
+ const result = incoming.reduce((current, raw) => {
26
+ const tag = raw.trim();
27
+ if (!tag || current.tags.some(existing => existing.toLowerCase() === tag.toLowerCase()))
28
+ return current;
29
+ if (props.validate && !props.validate(tag))
30
+ return { ...current, rejected: true };
31
+ return { ...current, tags: [...current.tags, tag] };
32
+ }, { tags: tags(), rejected: false });
33
+ if (result.tags !== tags())
34
+ setTags(result.tags);
35
+ setInvalid(result.rejected);
36
+ if (!result.rejected)
37
+ setText('');
38
+ };
39
+ const remove = (tag) => {
40
+ if (!props.disabled)
41
+ setTags(current => current.filter(existing => existing !== tag));
42
+ };
43
+ const removeLast = () => {
44
+ if (!props.disabled)
45
+ setTags(current => (current.length ? current.slice(0, -1) : current));
46
+ };
47
+ return (<Provider state={{
48
+ get tags() {
49
+ return tags();
50
+ },
51
+ get text() {
52
+ return text();
53
+ },
54
+ get invalid() {
55
+ return invalid();
56
+ },
57
+ }} actions={{ edit, add, remove, removeLast }} meta={{
58
+ get disabled() {
59
+ return props.disabled ?? false;
60
+ },
61
+ }}>
62
+ {props.children}
63
+ </Provider>);
64
+ };
65
+ const Field = (props) => {
66
+ const context = useTagInput();
67
+ return (<input {...omit(props, 'onInput', 'onKeyDown', 'onBlur', 'onPaste')} data-slot='tag-input-field' value={context.state.text} disabled={context.meta.disabled || props.disabled} aria-invalid={context.state.invalid ? 'true' : undefined} onInput={event => composeEventHandlers(props.onInput, () => context.actions.edit(event.currentTarget.value))(event)} onKeyDown={event => composeEventHandlers(props.onKeyDown, () => {
68
+ if (event.isComposing)
69
+ return;
70
+ if (event.key === 'Enter' || event.key === ',') {
71
+ event.preventDefault();
72
+ context.actions.add(context.state.text);
73
+ }
74
+ if (event.key === 'Backspace' && !context.state.text)
75
+ context.actions.removeLast();
76
+ })(event)} onBlur={event => composeEventHandlers(props.onBlur, () => context.actions.add(context.state.text))(event)} onPaste={event => composeEventHandlers(props.onPaste, () => {
77
+ const pasted = event.clipboardData?.getData('text') ?? '';
78
+ if (/[,\n;]/.test(pasted)) {
79
+ event.preventDefault();
80
+ context.actions.add(...pasted.split(/[,\n;]+/));
81
+ }
82
+ })(event)}/>);
83
+ };
84
+ const Tag = (props) => (<TagContext value={{
85
+ get value() {
86
+ return props.value;
87
+ },
88
+ }}>
89
+ <span {...omit(props, 'value')} data-slot='tag-input-tag'/>
90
+ </TagContext>);
91
+ const Remove = (props) => {
92
+ const context = useTagInput();
93
+ const tag = useContext(TagContext);
94
+ return (<Button {...omit(props, 'onClick')} data-slot='tag-input-remove' aria-label={props['aria-label'] ?? `Remove ${tag.value}`} disabled={context.meta.disabled || props.disabled} onClick={event => composeEventHandlers(props.onClick, () => context.actions.remove(tag.value))(event)}/>);
95
+ };
96
+ const Tags = () => {
97
+ const context = useTagInput();
98
+ return (<For each={context.state.tags}>
99
+ {tag => (<Tag value={tag}>
100
+ {tag}
101
+ <Remove />
102
+ </Tag>)}
103
+ </For>);
104
+ };
105
+ const Frame = part('div', 'tag-input');
106
+ const TagInput = { Root, Provider, Frame, Field, Tags, Tag, Remove };
107
+ export { TagInput, useTagInput };
package/dist/text.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ declare const Text: import("./part.jsx").Part<"p">;
2
+ export { Text };
package/dist/text.jsx ADDED
@@ -0,0 +1,3 @@
1
+ import { part } from './part.jsx';
2
+ const Text = part('p', 'text');
3
+ export { Text };
@@ -0,0 +1,2 @@
1
+ declare const Textarea: import("./part.jsx").Part<"textarea">;
2
+ export { Textarea };
@@ -0,0 +1,3 @@
1
+ import { part } from './part.jsx';
2
+ const Textarea = part('textarea', 'textarea');
3
+ export { Textarea };
package/dist/tile.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ declare const Root: import("./part.jsx").Part<"div">;
2
+ declare const Button: import("./part.jsx").Part<"button">;
3
+ declare const Link: import("./part.jsx").Part<"a">;
4
+ declare const Icon: import("./part.jsx").Part<"span">;
5
+ declare const Title: import("./part.jsx").Part<"span">;
6
+ declare const Description: import("./part.jsx").Part<"span">;
7
+ declare const Tile: {
8
+ Root: typeof Root;
9
+ Button: typeof Button;
10
+ Link: typeof Link;
11
+ Icon: typeof Icon;
12
+ Title: typeof Title;
13
+ Description: typeof Description;
14
+ };
15
+ export { Tile };
package/dist/tile.jsx ADDED
@@ -0,0 +1,9 @@
1
+ import { part } from './part.jsx';
2
+ const Root = part('div', 'tile');
3
+ const Button = part('button', 'tile', { type: 'button' });
4
+ const Link = part('a', 'tile');
5
+ const Icon = part('span', 'tile-icon', { 'aria-hidden': 'true' });
6
+ const Title = part('span', 'tile-title');
7
+ const Description = part('span', 'tile-description');
8
+ const Tile = { Root, Button, Link, Icon, Title, Description };
9
+ export { Tile };