@realmorg/ui 0.0.0-stage → 2.0.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +44 -2
  3. package/components/accordion.html +139 -0
  4. package/components/alert-dialog.html +236 -0
  5. package/components/alert.html +83 -0
  6. package/components/aspect-ratio.html +29 -0
  7. package/components/attachment.html +98 -0
  8. package/components/avatar.html +149 -0
  9. package/components/badge.html +62 -0
  10. package/components/breadcrumb.html +159 -0
  11. package/components/bubble.html +77 -0
  12. package/components/button-group.html +98 -0
  13. package/components/button.html +194 -0
  14. package/components/calendar.html +176 -0
  15. package/components/card.html +143 -0
  16. package/components/carousel.html +208 -0
  17. package/components/chart.html +168 -0
  18. package/components/checkbox.html +99 -0
  19. package/components/code-block.html +64 -0
  20. package/components/collapsible.html +90 -0
  21. package/components/combobox.html +237 -0
  22. package/components/command.html +201 -0
  23. package/components/context-menu.html +81 -0
  24. package/components/dialog.html +327 -0
  25. package/components/direction.html +23 -0
  26. package/components/drawer.html +267 -0
  27. package/components/dropdown-menu.html +421 -0
  28. package/components/empty.html +132 -0
  29. package/components/field.html +143 -0
  30. package/components/hover-card.html +111 -0
  31. package/components/input-group.html +91 -0
  32. package/components/input-otp.html +151 -0
  33. package/components/input.html +94 -0
  34. package/components/item.html +208 -0
  35. package/components/kbd.html +45 -0
  36. package/components/label.html +46 -0
  37. package/components/marker.html +41 -0
  38. package/components/menubar.html +137 -0
  39. package/components/message-scroller.html +68 -0
  40. package/components/message.html +95 -0
  41. package/components/navigation-menu.html +233 -0
  42. package/components/pagination.html +160 -0
  43. package/components/popover.html +164 -0
  44. package/components/progress.html +45 -0
  45. package/components/radio-group.html +120 -0
  46. package/components/resizable.html +170 -0
  47. package/components/scroll-area.html +56 -0
  48. package/components/select.html +103 -0
  49. package/components/separator.html +31 -0
  50. package/components/sheet.html +173 -0
  51. package/components/sidebar.html +393 -0
  52. package/components/skeleton.html +36 -0
  53. package/components/slider.html +108 -0
  54. package/components/spinner.html +53 -0
  55. package/components/switch.html +95 -0
  56. package/components/table.html +81 -0
  57. package/components/tabs.html +182 -0
  58. package/components/textarea.html +80 -0
  59. package/components/toaster.html +134 -0
  60. package/components/toggle-group.html +71 -0
  61. package/components/toggle.html +87 -0
  62. package/components/tooltip.html +114 -0
  63. package/dist/theme.css +158 -0
  64. package/dist/ui.html +7923 -0
  65. package/package.json +40 -3
  66. package/theme.css +158 -0
@@ -0,0 +1,194 @@
1
+ <custom-element name="ui-button" form-associated delegates-focus>
2
+ <script>
3
+ const props = defineProps({
4
+ variant: prop.enum(["default", "destructive", "outline", "secondary", "ghost", "link"]).default("default"),
5
+ size: prop.enum(["default", "xs", "sm", "lg", "icon", "icon-xs", "icon-sm", "icon-lg"]).default("default"),
6
+ type: prop.enum(["button", "submit", "reset"]).default("button"),
7
+ disabled: prop.boolean().reflect(),
8
+ label: prop.string().attribute("aria-label"),
9
+ description: prop.string().attribute("aria-description"),
10
+ popovertarget: prop.string(),
11
+ popovertargetaction: prop.enum(["toggle", "show", "hide"]),
12
+ commandfor: prop.string(),
13
+ command: prop.string(),
14
+ });
15
+
16
+ const NATIVE_COMMANDS = "commandForElement" in HTMLButtonElement.prototype;
17
+ const COMMAND_METHODS = {
18
+ "show-modal": "showModal",
19
+ close: "close",
20
+ "request-close": "requestClose",
21
+ "toggle-popover": "togglePopover",
22
+ "show-popover": "showPopover",
23
+ "hide-popover": "hidePopover",
24
+ };
25
+ const DIALOG_COMMANDS = new Set(["show-modal", "close", "request-close"]);
26
+ const FORM_ACTIONS = { submit: "requestSubmit", reset: "reset" };
27
+
28
+ function target(id) {
29
+ return id ? host.getRootNode().getElementById(id) : null;
30
+ }
31
+
32
+ function nativeCommand(element) {
33
+ const command = props.command ?? "";
34
+ const customTarget = element && !(element instanceof HTMLDialogElement);
35
+ return customTarget && DIALOG_COMMANDS.has(command) ? `--${command}` : command;
36
+ }
37
+
38
+ function emulateCommand() {
39
+ const element = target(props.commandfor);
40
+ if (NATIVE_COMMANDS || !element || !props.command) return;
41
+ const event = Object.assign(new Event("command", { cancelable: true }), { command: props.command, source: host });
42
+ if (element.dispatchEvent(event)) element[COMMAND_METHODS[props.command]]?.();
43
+ }
44
+
45
+ function activate() {
46
+ if (props.disabled) return;
47
+ emulateCommand();
48
+ const action = FORM_ACTIONS[props.type];
49
+ if (internals.form && action) HTMLFormElement.prototype[action].call(internals.form);
50
+ }
51
+
52
+ observe(() => {
53
+ const button = refs.button;
54
+ if (!button) return;
55
+ button.popoverTargetElement = target(props.popovertarget);
56
+ if (props.popovertargetaction) button.popoverTargetAction = props.popovertargetaction;
57
+ if (!NATIVE_COMMANDS) return;
58
+ const element = target(props.commandfor);
59
+ button.commandForElement = element;
60
+ button.command = nativeCommand(element);
61
+ });
62
+ </script>
63
+
64
+ <style>
65
+ /* A double tap must not zoom the page. Set inside the shadow root, because a page-level
66
+ touch-action does not reach shadow content in iOS Safari. */
67
+ :host,
68
+ * {
69
+ touch-action: manipulation;
70
+ }
71
+ :host {
72
+ display: inline-flex;
73
+ vertical-align: middle;
74
+ }
75
+ :host([hidden]) {
76
+ display: none;
77
+ }
78
+ button {
79
+ all: unset;
80
+ box-sizing: border-box;
81
+ display: inline-flex;
82
+ flex: 1;
83
+ align-items: center;
84
+ justify-content: center;
85
+ gap: calc(var(--spacing) * 2);
86
+ height: calc(var(--spacing) * 9);
87
+ padding: calc(var(--spacing) * 2) calc(var(--spacing) * 4);
88
+ border: 1px solid transparent;
89
+ border-radius: var(--radius-md);
90
+ border-start-start-radius: var(--ui-radius-block-start, var(--ui-radius-start, var(--radius-md)));
91
+ border-end-start-radius: var(--ui-radius-block-end, var(--ui-radius-start, var(--radius-md)));
92
+ border-start-end-radius: var(--ui-radius-block-start, var(--ui-radius-end, var(--radius-md)));
93
+ border-end-end-radius: var(--ui-radius-block-end, var(--ui-radius-end, var(--radius-md)));
94
+ font: inherit;
95
+ font-size: var(--text-sm);
96
+ line-height: calc(var(--spacing) * 5);
97
+ font-weight: var(--font-weight-medium);
98
+ white-space: nowrap;
99
+ cursor: pointer;
100
+ transition: background-color var(--default-transition-duration), color var(--default-transition-duration), box-shadow var(--default-transition-duration), opacity var(--default-transition-duration);
101
+ background: var(--primary);
102
+ color: var(--primary-foreground);
103
+ }
104
+ /* Mixing toward the text colour darkens a light-mode fill and lightens a dark-mode one, so
105
+ hover never lowers the text contrast. */
106
+ button:hover {
107
+ background: color-mix(in oklab, var(--primary) 88%, var(--foreground));
108
+ }
109
+ button:focus-visible {
110
+ border-color: var(--ring);
111
+ box-shadow: var(--focus-ring);
112
+ }
113
+ button:disabled {
114
+ pointer-events: none;
115
+ opacity: 0.5;
116
+ }
117
+ ::slotted(svg) {
118
+ width: calc(var(--spacing) * 4);
119
+ height: calc(var(--spacing) * 4);
120
+ flex-shrink: 0;
121
+ pointer-events: none;
122
+ }
123
+ :host(:state(attr-variant-is-destructive)) button {
124
+ background: var(--destructive);
125
+ color: var(--destructive-foreground);
126
+ }
127
+ :host(:state(attr-variant-is-destructive)) button:hover {
128
+ background: color-mix(in oklab, var(--destructive) 88%, var(--foreground));
129
+ }
130
+ :host(:state(attr-variant-is-outline)) button {
131
+ border-color: var(--border);
132
+ background: var(--background);
133
+ color: var(--foreground);
134
+ box-shadow: var(--shadow-xs);
135
+ }
136
+ :host(:state(attr-variant-is-outline)) button:hover,
137
+ :host(:state(attr-variant-is-ghost)) button:hover {
138
+ background: var(--accent);
139
+ color: var(--accent-foreground);
140
+ }
141
+ :host(:state(attr-variant-is-secondary)) button {
142
+ background: var(--secondary);
143
+ color: var(--secondary-foreground);
144
+ }
145
+ :host(:state(attr-variant-is-secondary)) button:hover {
146
+ background: color-mix(in oklab, var(--secondary) 80%, transparent);
147
+ }
148
+ :host(:state(attr-variant-is-ghost)) button {
149
+ background: transparent;
150
+ color: var(--foreground);
151
+ }
152
+ :host(:state(attr-variant-is-link)) button {
153
+ background: transparent;
154
+ color: var(--primary);
155
+ text-underline-offset: 4px;
156
+ }
157
+ :host(:state(attr-variant-is-link)) button:hover {
158
+ text-decoration: underline;
159
+ }
160
+ :host(:state(attr-size-is-xs)) button {
161
+ height: calc(var(--spacing) * 6);
162
+ gap: calc(var(--spacing) * 1);
163
+ padding: 0 calc(var(--spacing) * 2);
164
+ font-size: var(--text-xs);
165
+ }
166
+ :host(:state(attr-size-is-sm)) button {
167
+ height: calc(var(--spacing) * 8);
168
+ gap: calc(var(--spacing) * 1.5);
169
+ padding: 0 calc(var(--spacing) * 3);
170
+ }
171
+ :host(:state(attr-size-is-lg)) button {
172
+ height: calc(var(--spacing) * 10);
173
+ padding: 0 calc(var(--spacing) * 6);
174
+ }
175
+ :host(:is(:state(attr-size-is-icon), :state(attr-size-is-icon-xs), :state(attr-size-is-icon-sm), :state(attr-size-is-icon-lg))) button {
176
+ padding: 0;
177
+ width: calc(var(--spacing) * 9);
178
+ }
179
+ :host(:state(attr-size-is-icon-xs)) button {
180
+ width: calc(var(--spacing) * 6);
181
+ height: calc(var(--spacing) * 6);
182
+ }
183
+ :host(:state(attr-size-is-icon-sm)) button {
184
+ width: calc(var(--spacing) * 8);
185
+ height: calc(var(--spacing) * 8);
186
+ }
187
+ :host(:state(attr-size-is-icon-lg)) button {
188
+ width: calc(var(--spacing) * 10);
189
+ height: calc(var(--spacing) * 10);
190
+ }
191
+ </style>
192
+
193
+ <button type="button" ref="button" part="button" _aria-label="@label" _aria-description="@description" _disabled="@disabled" onclick="activate()"><slot></slot></button>
194
+ </custom-element>
@@ -0,0 +1,176 @@
1
+ <import-element from="./button.html"></import-element>
2
+
3
+ <custom-element name="ui-calendar" form-associated>
4
+ <script>
5
+ const props = defineProps({
6
+ value: prop.string().default(""),
7
+ month: prop.string(),
8
+ min: prop.string(),
9
+ max: prop.string(),
10
+ locale: prop.string(),
11
+ });
12
+
13
+ const iso = (date) => date.toISOString().slice(0, 10);
14
+ const parse = (text) => new Date(`${text}T00:00:00Z`);
15
+ const now = new Date();
16
+ const today = iso(new Date(Date.UTC(now.getFullYear(), now.getMonth(), now.getDate())));
17
+ const KEYS = { ArrowLeft: -1, ArrowRight: 1, ArrowUp: -7, ArrowDown: 7 };
18
+
19
+ const view = useState({
20
+ shown: (props.month || props.value || today).slice(0, 7),
21
+ focused: props.value || today,
22
+ get title() {
23
+ return new Intl.DateTimeFormat(props.locale, { month: "long", year: "numeric", timeZone: "UTC" }).format(parse(`${this.shown}-01`));
24
+ },
25
+ get weekdays() {
26
+ const sunday = Date.UTC(2023, 0, 1);
27
+ return Array.from({ length: 7 }, (_, day) =>
28
+ new Intl.DateTimeFormat(props.locale, { weekday: "short", timeZone: "UTC" }).format(new Date(sunday + day * 864e5)),
29
+ );
30
+ },
31
+ get weeks() {
32
+ const first = parse(`${this.shown}-01`);
33
+ const start = new Date(first.getTime() - first.getUTCDay() * 864e5);
34
+ const days = Array.from({ length: 42 }, (_, n) => {
35
+ const date = iso(new Date(start.getTime() + n * 864e5));
36
+ return {
37
+ date,
38
+ day: Number(date.slice(8)),
39
+ outside: !date.startsWith(this.shown),
40
+ selected: date === props.value,
41
+ today: date === today,
42
+ disabled: (props.min && date < props.min) || (props.max && date > props.max) || false,
43
+ tabindex: date === this.focused ? 0 : -1,
44
+ };
45
+ });
46
+ return Array.from({ length: 6 }, (_, week) => ({ week, days: days.slice(week * 7, week * 7 + 7) }));
47
+ },
48
+ });
49
+
50
+ function shift(months) {
51
+ const date = parse(`${view.shown}-01`);
52
+ date.setUTCMonth(date.getUTCMonth() + months);
53
+ view.shown = iso(date).slice(0, 7);
54
+ }
55
+
56
+ function previous() {
57
+ shift(-1);
58
+ }
59
+
60
+ function next() {
61
+ shift(1);
62
+ }
63
+
64
+ function pick(day) {
65
+ props.value = day.date;
66
+ view.focused = day.date;
67
+ view.shown = day.date.slice(0, 7);
68
+ dispatch("change");
69
+ }
70
+
71
+ async function keys(day, event) {
72
+ const step = KEYS[event.key];
73
+ if (!step) return;
74
+ event.preventDefault();
75
+ view.focused = iso(new Date(parse(day.date).getTime() + step * 864e5));
76
+ view.shown = view.focused.slice(0, 7);
77
+ await tick();
78
+ refs.grid.querySelector(`[data-date="${view.focused}"]`)?.focus();
79
+ }
80
+ </script>
81
+
82
+ <style>
83
+ /* A double tap must not zoom the page. Set inside the shadow root, because a page-level
84
+ touch-action does not reach shadow content in iOS Safari. */
85
+ :host,
86
+ * {
87
+ touch-action: manipulation;
88
+ }
89
+ :host {
90
+ display: inline-block;
91
+ padding: calc(var(--spacing) * 3);
92
+ border: 1px solid var(--border);
93
+ border-radius: var(--radius-lg);
94
+ font-size: var(--text-sm);
95
+ }
96
+ header {
97
+ display: flex;
98
+ align-items: center;
99
+ justify-content: space-between;
100
+ margin-bottom: calc(var(--spacing) * 3);
101
+ }
102
+ .title {
103
+ font-weight: var(--font-weight-medium);
104
+ }
105
+ table {
106
+ border-collapse: collapse;
107
+ }
108
+ th {
109
+ width: calc(var(--spacing) * 9);
110
+ padding-bottom: calc(var(--spacing) * 1);
111
+ font-size: var(--text-xs);
112
+ font-weight: var(--font-weight-normal);
113
+ color: var(--muted-foreground);
114
+ }
115
+ td {
116
+ padding: 0;
117
+ }
118
+ button {
119
+ all: unset;
120
+ box-sizing: border-box;
121
+ display: grid;
122
+ place-content: center;
123
+ width: calc(var(--spacing) * 9);
124
+ height: calc(var(--spacing) * 9);
125
+ border-radius: var(--radius-md);
126
+ cursor: pointer;
127
+ }
128
+ button:hover {
129
+ background: var(--accent);
130
+ }
131
+ button:focus-visible {
132
+ box-shadow: var(--focus-ring);
133
+ }
134
+ button[data-outside] {
135
+ color: var(--muted-foreground);
136
+ }
137
+ button[data-today] {
138
+ background: var(--accent);
139
+ }
140
+ button[aria-selected="true"] {
141
+ background: var(--primary);
142
+ color: var(--primary-foreground);
143
+ }
144
+ button:disabled {
145
+ pointer-events: none;
146
+ opacity: 0.4;
147
+ }
148
+ </style>
149
+
150
+ <header part="header">
151
+ <ui-button variant="outline" size="icon-sm" aria-label="Previous month" onclick="previous()">‹</ui-button>
152
+ <span class="title" aria-live="polite"><slot name="#view.title"></slot></span>
153
+ <ui-button variant="outline" size="icon-sm" aria-label="Next month" onclick="next()">›</ui-button>
154
+ </header>
155
+ <table role="grid" ref="grid" part="grid">
156
+ <thead>
157
+ <tr><th repeat="#view.weekdays" as="weekday" scope="col"><slot name="#weekday"></slot></th></tr>
158
+ </thead>
159
+ <tbody>
160
+ <tr repeat="#view.weeks" as="row" key="week">
161
+ <td repeat="#row.days" as="day" key="date">
162
+ <button type="button"
163
+ part="day"
164
+ _data-date="#day.date"
165
+ _data-outside="#day.outside"
166
+ _data-today="#day.today"
167
+ _aria-selected="#day.selected"
168
+ _disabled="#day.disabled"
169
+ _tabindex="#day.tabindex"
170
+ onclick="pick(day)"
171
+ onkeydown="keys(day, event)"><slot name="#day.day"></slot></button>
172
+ </td>
173
+ </tr>
174
+ </tbody>
175
+ </table>
176
+ </custom-element>
@@ -0,0 +1,143 @@
1
+ <custom-element name="ui-card">
2
+ <style>
3
+ /* A double tap must not zoom the page. Set inside the shadow root, because a page-level
4
+ touch-action does not reach shadow content in iOS Safari. */
5
+ :host,
6
+ * {
7
+ touch-action: manipulation;
8
+ }
9
+ :host {
10
+ display: flex;
11
+ flex-direction: column;
12
+ gap: calc(var(--spacing) * 6);
13
+ padding: calc(var(--spacing) * 6) 0;
14
+ border: 1px solid var(--border);
15
+ border-radius: var(--radius-xl);
16
+ background: var(--card);
17
+ color: var(--card-foreground);
18
+ box-shadow: var(--shadow-xs);
19
+ }
20
+ </style>
21
+
22
+ <slot></slot>
23
+ </custom-element>
24
+
25
+ <custom-element name="ui-card-header">
26
+ <style>
27
+ :host,
28
+ * {
29
+ touch-action: manipulation;
30
+ }
31
+ :host {
32
+ display: grid;
33
+ grid-auto-rows: min-content;
34
+ align-items: start;
35
+ gap: calc(var(--spacing) * 1.5);
36
+ padding: 0 calc(var(--spacing) * 6);
37
+ }
38
+ ::slotted(:not(ui-card-action)) {
39
+ grid-column: 1;
40
+ }
41
+ </style>
42
+
43
+ <slot></slot>
44
+ </custom-element>
45
+
46
+ <custom-element name="ui-card-title">
47
+ <script>
48
+ defineProps({ level: prop.number().int().min(1).max(6).default(3) });
49
+ </script>
50
+
51
+ <style>
52
+ :host,
53
+ * {
54
+ touch-action: manipulation;
55
+ }
56
+ :host {
57
+ display: block;
58
+ }
59
+ [part="title"] {
60
+ margin: 0;
61
+ font-size: var(--text-base);
62
+ font-weight: var(--font-weight-semibold);
63
+ line-height: 1;
64
+ }
65
+ </style>
66
+
67
+ <div part="title" role="heading" _aria-level="@level"><slot></slot></div>
68
+ </custom-element>
69
+
70
+ <custom-element name="ui-card-description">
71
+ <style>
72
+ :host,
73
+ * {
74
+ touch-action: manipulation;
75
+ }
76
+ :host {
77
+ display: block;
78
+ font-size: var(--text-sm);
79
+ color: var(--muted-foreground);
80
+ }
81
+ </style>
82
+
83
+ <slot></slot>
84
+ </custom-element>
85
+
86
+ <custom-element name="ui-card-action">
87
+ <style>
88
+ :host,
89
+ * {
90
+ touch-action: manipulation;
91
+ }
92
+ :host {
93
+ display: block;
94
+ grid-column: 2;
95
+ grid-row: 1 / span 2;
96
+ justify-self: end;
97
+ }
98
+ </style>
99
+
100
+ <slot></slot>
101
+ </custom-element>
102
+
103
+ <custom-element name="ui-card-content">
104
+ <style>
105
+ :host,
106
+ * {
107
+ touch-action: manipulation;
108
+ }
109
+ :host {
110
+ display: block;
111
+ padding: 0 calc(var(--spacing) * 6);
112
+ }
113
+ </style>
114
+
115
+ <slot></slot>
116
+ </custom-element>
117
+
118
+ <custom-element name="ui-card-footer">
119
+ <style>
120
+ :host,
121
+ * {
122
+ touch-action: manipulation;
123
+ }
124
+ :host {
125
+ display: flex;
126
+ align-items: center;
127
+ gap: calc(var(--spacing) * 2);
128
+ padding: 0 calc(var(--spacing) * 6);
129
+ }
130
+ :host(:state(attr-justify-is-between)) {
131
+ justify-content: space-between;
132
+ }
133
+ :host(:state(attr-justify-is-end)) {
134
+ justify-content: flex-end;
135
+ }
136
+ :host(:state(attr-orientation-is-vertical)) {
137
+ flex-direction: column;
138
+ align-items: stretch;
139
+ }
140
+ </style>
141
+
142
+ <slot></slot>
143
+ </custom-element>