numori-ui 0.1.1 → 0.2.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.
@@ -0,0 +1,152 @@
1
+ <template>
2
+ <div
3
+ role="group"
4
+ :aria-label="ariaLabel"
5
+ class="relative inline-grid p-1"
6
+ :class="[trackClass, 'border border-gray-200 bg-gray-50 dark:border-gray-700 dark:bg-gray-900']"
7
+ :style="{ gridTemplateColumns: `repeat(${count}, minmax(0, 1fr))` }"
8
+ >
9
+ <!--
10
+ A single pill slides between segments rather than each segment owning its
11
+ own background, so the movement animates. Segments are equal-width, so the
12
+ pill's width is one column and it translates by whole columns. `top/bottom/
13
+ left` inset it inside the track's padding; `%` in translateX resolves
14
+ against the pill's own (one-column) width.
15
+ -->
16
+ <span
17
+ aria-hidden="true"
18
+ class="pointer-events-none absolute bottom-1 left-1 top-1 bg-primary-500 shadow-sm transition-transform duration-300 ease-out motion-reduce:transition-none"
19
+ :class="pillClass"
20
+ :style="pillStyle"
21
+ />
22
+
23
+ <button
24
+ v-for="(option, index) in options"
25
+ :key="option.value"
26
+ type="button"
27
+ :aria-pressed="isActive(option) ? 'true' : 'false'"
28
+ :disabled="option.disabled"
29
+ class="relative z-10 inline-flex items-center justify-center gap-1.5 font-semibold transition-colors disabled:cursor-not-allowed disabled:opacity-50"
30
+ :class="[
31
+ buttonSizeClass,
32
+ buttonShapeClass,
33
+ isActive(option) ? activeTextClass : idleTextClass,
34
+ ]"
35
+ @click="select(option, index)"
36
+ >
37
+ <UiIcon v-if="option.icon" :name="option.icon" :class="iconSizeClass" />
38
+ {{ option.label }}
39
+ </button>
40
+ </div>
41
+ </template>
42
+
43
+ <script setup>
44
+ /**
45
+ * UiSegmented — a segmented control: pick one of a few named options from a row
46
+ * of buttons, with a pill that slides to the active choice.
47
+ *
48
+ * This is a set of toggle buttons (`role="group"` + `aria-pressed`), not a
49
+ * switch, because the choice is between named options rather than on/off — "the
50
+ * second option is off" is not something a screen reader should say. Segments
51
+ * are equal width so the pill can slide by whole columns.
52
+ *
53
+ * For an on/off control use `UiToggle`; for many options or a searchable list
54
+ * use `UiSelect`.
55
+ *
56
+ * @example Billing period
57
+ * <UiSegmented
58
+ * v-model="billing"
59
+ * :options="[
60
+ * { value: 'monthly', label: 'Monthly' },
61
+ * { value: 'yearly', label: 'Yearly' },
62
+ * ]"
63
+ * aria-label="Billing period"
64
+ * />
65
+ *
66
+ * @example With icons and a labelled-by heading
67
+ * <h2 id="view-h" class="sr-only">View</h2>
68
+ * <UiSegmented v-model="view" :options="views" aria-labelledby="view-h" />
69
+ *
70
+ * @emits {string|number} update:modelValue — the chosen option's `value`
71
+ */
72
+ import { computed } from 'vue'
73
+ import UiIcon from '../icons/Icon.vue'
74
+
75
+ const props = defineProps({
76
+ /**
77
+ * Selected value (v-model), matched against each option's `value`.
78
+ * @type {string | number}
79
+ * @default undefined
80
+ */
81
+ modelValue: { type: [String, Number], default: undefined },
82
+
83
+ /**
84
+ * The options. Each is `{ value, label, icon?, disabled? }`.
85
+ * @type {Array<{ value: string|number, label: string, icon?: string, disabled?: boolean }>}
86
+ */
87
+ options: { type: Array, required: true },
88
+
89
+ /**
90
+ * Size preset controlling padding and font size.
91
+ * @type {string}
92
+ * @default 'md'
93
+ * @values 'sm' | 'md'
94
+ */
95
+ size: { type: String, default: 'md' },
96
+
97
+ /**
98
+ * Corner shape of the track and pill.
99
+ * @type {string}
100
+ * @default 'pill'
101
+ * @values 'pill' | 'rounded'
102
+ */
103
+ shape: { type: String, default: 'pill' },
104
+
105
+ /**
106
+ * Accessible name for the group. Omit if you label it with an external
107
+ * heading via `aria-labelledby` (which falls through to the root).
108
+ * @type {string}
109
+ * @default undefined
110
+ */
111
+ ariaLabel: { type: String, default: undefined },
112
+ })
113
+
114
+ const emit = defineEmits(['update:modelValue'])
115
+
116
+ const count = computed(() => props.options?.length || 1)
117
+
118
+ const isActive = (option) => option.value === props.modelValue
119
+
120
+ const activeIndex = computed(() => {
121
+ const i = (props.options ?? []).findIndex((o) => o.value === props.modelValue)
122
+ return i === -1 ? 0 : i
123
+ })
124
+
125
+ function select(option, index) {
126
+ if (option.disabled) return
127
+ emit('update:modelValue', option.value)
128
+ // index is accepted for symmetry with the template call site; the value is
129
+ // what identifies the option.
130
+ void index
131
+ }
132
+
133
+ const trackClass = computed(() => (props.shape === 'rounded' ? 'rounded-xl' : 'rounded-full'))
134
+ const buttonShapeClass = computed(() => (props.shape === 'rounded' ? 'rounded-lg' : 'rounded-full'))
135
+ const pillClass = computed(() => (props.shape === 'rounded' ? 'rounded-lg' : 'rounded-full'))
136
+
137
+ const buttonSizeClass = computed(() =>
138
+ props.size === 'sm' ? 'px-3 py-1 text-xs' : 'px-4 py-1.5 text-sm',
139
+ )
140
+ const iconSizeClass = computed(() => (props.size === 'sm' ? 'size-3.5' : 'size-4'))
141
+
142
+ const activeTextClass = 'text-white'
143
+ const idleTextClass =
144
+ 'text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-100'
145
+
146
+ const pillStyle = computed(() => ({
147
+ // Track padding is p-1 (0.25rem) each side, so the usable width is
148
+ // `100% - 0.5rem`; one segment is that divided by the option count.
149
+ width: `calc((100% - 0.5rem) / ${count.value})`,
150
+ transform: `translateX(calc(${activeIndex.value} * 100%))`,
151
+ }))
152
+ </script>
@@ -12,8 +12,10 @@
12
12
  import Alert from './Alert.vue'
13
13
  import Avatar from './Avatar.vue'
14
14
  import Badge from './Badge.vue'
15
+ import Breadcrumb from './Breadcrumb.vue'
15
16
  import Button from './Button.vue'
16
17
  import ButtonsGroup from './ButtonsGroup.vue'
18
+ import Card from './Card.vue'
17
19
  import Checkbox from './Checkbox.vue'
18
20
  import Divider from './Divider.vue'
19
21
  import Dropdown from './Dropdown.vue'
@@ -22,6 +24,7 @@ import DropdownRow from './DropdownRow.vue'
22
24
  import DropdownSubmenu from './DropdownSubmenu.vue'
23
25
  import FileInput from './FileInput.vue'
24
26
  import FormField from './FormField.vue'
27
+ import IconTile from './IconTile.vue'
25
28
  import Input from './Input.vue'
26
29
  import Kbd from './Kbd.vue'
27
30
  import ListMenu from './ListMenu.vue'
@@ -32,6 +35,8 @@ import Popup from './Popup.vue'
32
35
  import ProgressBar from './ProgressBar.vue'
33
36
  import Prompt from './Prompt.vue'
34
37
  import Radio from './Radio.vue'
38
+ import SectionHeading from './SectionHeading.vue'
39
+ import Segmented from './Segmented.vue'
35
40
  import Select from './Select.vue'
36
41
  import Slider from './Slider.vue'
37
42
  import Stepper from './Stepper.vue'
@@ -43,8 +48,10 @@ export {
43
48
  Alert as UiAlert,
44
49
  Avatar as UiAvatar,
45
50
  Badge as UiBadge,
51
+ Breadcrumb as UiBreadcrumb,
46
52
  Button as UiButton,
47
53
  ButtonsGroup as UiButtonsGroup,
54
+ Card as UiCard,
48
55
  Checkbox as UiCheckbox,
49
56
  Divider as UiDivider,
50
57
  Dropdown as UiDropdown,
@@ -53,6 +60,7 @@ export {
53
60
  DropdownSubmenu as UiDropdownSubmenu,
54
61
  FileInput as UiFileInput,
55
62
  FormField as UiFormField,
63
+ IconTile as UiIconTile,
56
64
  Input as UiInput,
57
65
  Kbd as UiKbd,
58
66
  ListMenu as UiListMenu,
@@ -63,6 +71,8 @@ export {
63
71
  ProgressBar as UiProgressBar,
64
72
  Prompt as UiPrompt,
65
73
  Radio as UiRadio,
74
+ SectionHeading as UiSectionHeading,
75
+ Segmented as UiSegmented,
66
76
  Select as UiSelect,
67
77
  Slider as UiSlider,
68
78
  Stepper as UiStepper,
@@ -80,8 +90,10 @@ export const components = {
80
90
  Alert,
81
91
  Avatar,
82
92
  Badge,
93
+ Breadcrumb,
83
94
  Button,
84
95
  ButtonsGroup,
96
+ Card,
85
97
  Checkbox,
86
98
  Divider,
87
99
  Dropdown,
@@ -90,6 +102,7 @@ export const components = {
90
102
  DropdownSubmenu,
91
103
  FileInput,
92
104
  FormField,
105
+ IconTile,
93
106
  Input,
94
107
  Kbd,
95
108
  ListMenu,
@@ -100,6 +113,8 @@ export const components = {
100
113
  ProgressBar,
101
114
  Prompt,
102
115
  Radio,
116
+ SectionHeading,
117
+ Segmented,
103
118
  Select,
104
119
  Slider,
105
120
  Stepper,
package/src/manifest.js CHANGED
@@ -23,8 +23,10 @@ export const COMPONENT_NAMES = [
23
23
  'Alert',
24
24
  'Avatar',
25
25
  'Badge',
26
+ 'Breadcrumb',
26
27
  'Button',
27
28
  'ButtonsGroup',
29
+ 'Card',
28
30
  'Checkbox',
29
31
  'Divider',
30
32
  'Dropdown',
@@ -33,6 +35,7 @@ export const COMPONENT_NAMES = [
33
35
  'DropdownSubmenu',
34
36
  'FileInput',
35
37
  'FormField',
38
+ 'IconTile',
36
39
  'Input',
37
40
  'Kbd',
38
41
  'ListMenu',
@@ -43,6 +46,8 @@ export const COMPONENT_NAMES = [
43
46
  'ProgressBar',
44
47
  'Prompt',
45
48
  'Radio',
49
+ 'SectionHeading',
50
+ 'Segmented',
46
51
  'Select',
47
52
  'Slider',
48
53
  'Stepper',