@nexxtmove/ui 1.21.0 → 1.23.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/dist/nuxt.js CHANGED
@@ -66,11 +66,13 @@ var s = {
66
66
  NexxtVideoPlayer: "components/organisms/VideoPlayer/VideoPlayer.vue",
67
67
  NexxtEditorSettingsBlock: "components/editor/atoms/EditorSettingsBlock/EditorSettingsBlock.vue",
68
68
  NexxtEditorAlignItems: "components/editor/molecules/EditorAlignItems/EditorAlignItems.vue",
69
+ NexxtEditorColor: "components/editor/molecules/EditorColor/EditorColor.vue",
69
70
  NexxtEditorFlexDirection: "components/editor/molecules/EditorFlexDirection/EditorFlexDirection.vue",
70
71
  NexxtEditorGap: "components/editor/molecules/EditorGap/EditorGap.vue",
72
+ NexxtEditorHeadingType: "components/editor/molecules/EditorHeadingType/EditorHeadingType.vue",
71
73
  NexxtEditorJustifyContent: "components/editor/molecules/EditorJustifyContent/EditorJustifyContent.vue",
72
- NexxtEditorRadius: "components/editor/molecules/EditorRadius/EditorRadius.vue",
73
- NexxtEditorPadding: "components/editor/molecules/EditorPadding/EditorPadding.vue"
74
+ NexxtEditorPadding: "components/editor/molecules/EditorPadding/EditorPadding.vue",
75
+ NexxtEditorRadius: "components/editor/molecules/EditorRadius/EditorRadius.vue"
74
76
  }, c = ["@nexxtmove/ui/ui.css", "@nexxtmove/ui/dist/ui.css"], l = (e, t) => e.some((e) => e === t || c.includes(e)), u = i({
75
77
  meta: {
76
78
  name: "@nexxtmove/ui",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nexxtmove/ui",
3
3
  "type": "module",
4
- "version": "1.21.0",
4
+ "version": "1.23.0",
5
5
  "exports": {
6
6
  ".": {
7
7
  "types": "./dist/index.d.ts",
@@ -0,0 +1,155 @@
1
+ <script lang="ts">
2
+ /**
3
+ * The CSS property the chosen colour is written to. It is the prefix of the
4
+ * Tailwind class the model carries, so it decides whether the colour becomes a
5
+ * background or a text colour. `border` is deliberately not offered: a border
6
+ * is colour plus width, and that pair gets a component of its own.
7
+ */
8
+ export type EditorColorProperty = 'bg' | 'text'
9
+
10
+ /**
11
+ * The colour as the editor needs it: a Tailwind arbitrary-value class such as
12
+ * `'bg-[#1777EA]'`, so the consumer can put the model value straight on the
13
+ * element it styles.
14
+ */
15
+ export type EditorColorValue = `${EditorColorProperty}-[#${string}]`
16
+
17
+ /** Overridable copy of the picker. Every key is optional. */
18
+ export interface EditorColorMessages {
19
+ /** Text shown while no colour is set. Defaults to `'Kies kleur...'`. */
20
+ placeholder?: string
21
+ }
22
+
23
+ export interface NexxtEditorColorProps {
24
+ /**
25
+ * Header text of the settings block. Defaults to the Dutch `'Kleur'`; the
26
+ * library has no i18n layer, so a consumer in another language passes its
27
+ * own copy in.
28
+ */
29
+ label?: string
30
+ /**
31
+ * Render a switch next to the label that collapses and expands the picker.
32
+ * The switch state is the `enabled` model; the colour itself is kept while
33
+ * the block is collapsed.
34
+ */
35
+ switchable?: boolean
36
+ /**
37
+ * The prefix of the class that is written: `'bg'` for a background colour,
38
+ * `'text'` for a text colour. Changing it rewrites the current value, so the
39
+ * model never disagrees with this prop.
40
+ */
41
+ property?: EditorColorProperty
42
+ /**
43
+ * Copy of the picker. Merged per key, so overriding one key keeps the
44
+ * defaults of the others. Copy is never translated inside the component.
45
+ */
46
+ messages?: EditorColorMessages
47
+ }
48
+
49
+ const DEFAULT_MESSAGES = {
50
+ placeholder: 'Kies kleur...',
51
+ } satisfies Required<EditorColorMessages>
52
+
53
+ /**
54
+ * A full model value: one of the two prefixes, then a 6- or 8-digit hex between
55
+ * brackets. A `border-[…]` class is therefore read as unparseable, the same as
56
+ * any other class this component does not own. The
57
+ * alpha pair is accepted on read so a stored `#1777EA80` survives a round trip,
58
+ * even though the picker itself is opened without an alpha channel here.
59
+ */
60
+ const VALUE_PATTERN = /^(bg|text)-\[(#[0-9A-Fa-f]{6}(?:[0-9A-Fa-f]{2})?)\]$/
61
+ </script>
62
+
63
+ <script lang="ts" setup>
64
+ import { computed, watch } from 'vue'
65
+ import NexxtEditorSettingsBlock from '../../atoms/EditorSettingsBlock/EditorSettingsBlock.vue'
66
+ import NexxtColorPicker from '../../../organisms/ColorPicker/ColorPicker.vue'
67
+
68
+ defineOptions({ name: 'NexxtEditorColor' })
69
+
70
+ const {
71
+ label = 'Kleur',
72
+ switchable = false,
73
+ property = 'bg',
74
+ messages,
75
+ } = defineProps<NexxtEditorColorProps>()
76
+
77
+ /**
78
+ * The chosen colour, as the Tailwind class to apply.
79
+ *
80
+ * Beware: Tailwind only generates an arbitrary class for text it finds in the
81
+ * source at build time. A value that arrives at runtime -- from a database,
82
+ * say -- therefore gets no CSS of its own; the consumer either translates it
83
+ * into an inline style or safelists the classes it can produce. The hex is
84
+ * always parseable out of the string, which is what makes that translation
85
+ * possible.
86
+ */
87
+ const model = defineModel<EditorColorValue>({ required: true })
88
+
89
+ /** Open state of the block. Only has an effect when `switchable` is `true`. */
90
+ const enabled = defineModel<boolean>('enabled', { default: true })
91
+
92
+ const copy = computed(() => ({ ...DEFAULT_MESSAGES, ...messages }))
93
+
94
+ /**
95
+ * The `#` is part of the model's type, so a plain `string` cannot be written
96
+ * into it. This narrows the picker's output and the regex capture to the shape
97
+ * the model promises, without a cast.
98
+ */
99
+ const isHex = (value: string): value is `#${string}` => value.startsWith('#')
100
+
101
+ /** The hex out of the model, or an empty string when it is not a colour class. */
102
+ const hex = computed(() => {
103
+ const captured = VALUE_PATTERN.exec(model.value)?.[2]
104
+ return captured && isHex(captured) ? captured : ''
105
+ })
106
+
107
+ // An unparseable value -- empty, a token class such as `bg-red-500`, or copy
108
+ // from before this component -- leaves the picker empty and its placeholder
109
+ // visible, rather than being reported as a problem: the first pick writes a
110
+ // valid class back.
111
+ const picked = computed({
112
+ get: () => hex.value,
113
+ // The picker clears its own value in no flow it offers, but an empty string
114
+ // would still wipe a perfectly good colour, so it is dropped rather than
115
+ // written through. The picker keeps rendering the model's colour.
116
+ set: (value: string) => {
117
+ if (isHex(value)) model.value = `${property}-[${value}]`
118
+ },
119
+ })
120
+
121
+ // `property` is a prop, so the parent can flip a background setting into a
122
+ // text-colour one while a value is already set. Rewriting the prefix here is
123
+ // what keeps the stored class and the prop from drifting apart.
124
+ watch(
125
+ () => property,
126
+ (next) => {
127
+ if (hex.value) model.value = `${next}-[${hex.value}]`
128
+ },
129
+ )
130
+ </script>
131
+
132
+ <template>
133
+ <NexxtEditorSettingsBlock v-model="enabled" :label="label" :switchable="switchable">
134
+ <!--
135
+ The block label is a <p> (or the switch's own label), so the picker gets
136
+ no `label` of its own -- that would print the heading twice. Its trigger
137
+ falls back to the placeholder for its accessible name, which is why the
138
+ placeholder is the one piece of copy this component passes down.
139
+ -->
140
+ <!--
141
+ `matchWidth` makes the panel as wide as the full-width trigger instead of
142
+ the fixed `w-70` it defaults to. It works by setting a `min-width` on the
143
+ floating element, so a panel in a container narrower than its content
144
+ would still be wider than the trigger; in the settings column it is not.
145
+ -->
146
+ <NexxtColorPicker
147
+ v-model="picked"
148
+ full-width
149
+ match-width
150
+ :formats="['hex']"
151
+ :show-alpha="false"
152
+ :placeholder="copy.placeholder"
153
+ />
154
+ </NexxtEditorSettingsBlock>
155
+ </template>
@@ -0,0 +1,120 @@
1
+ <script lang="ts">
2
+ /**
3
+ * The heading levels the editor offers, in the order they are listed. The level
4
+ * is what the option shows -- its label and its `h1`..`h6` icon -- and the size
5
+ * is what the model carries. The sizes are Tailwind's default scale on purpose,
6
+ * not the theme's `heading-*` utilities: this value is data the editor stores
7
+ * and puts back on an element, so it has to be a class every consumer resolves.
8
+ */
9
+ const HEADING_LEVELS = [
10
+ { level: 1, size: 'text-4xl' },
11
+ { level: 2, size: 'text-3xl' },
12
+ { level: 3, size: 'text-2xl' },
13
+ { level: 4, size: 'text-xl' },
14
+ { level: 5, size: 'text-lg' },
15
+ { level: 6, size: 'text-base' },
16
+ ] as const
17
+
18
+ /**
19
+ * The heading as the editor needs it: the Tailwind font-size class itself, so
20
+ * the consumer can put the model value straight on the element it styles.
21
+ * Weight is deliberately not part of it -- that becomes a setting of its own.
22
+ */
23
+ export type EditorHeadingTypeValue = (typeof HEADING_LEVELS)[number]['size']
24
+
25
+ /** Overridable copy for the six options. Every key is optional. */
26
+ export interface EditorHeadingTypeMessages {
27
+ /** Label of the `h1` option. Defaults to `'Heading 1'`. */
28
+ h1?: string
29
+ /** Label of the `h2` option. Defaults to `'Heading 2'`. */
30
+ h2?: string
31
+ /** Label of the `h3` option. Defaults to `'Heading 3'`. */
32
+ h3?: string
33
+ /** Label of the `h4` option. Defaults to `'Heading 4'`. */
34
+ h4?: string
35
+ /** Label of the `h5` option. Defaults to `'Heading 5'`. */
36
+ h5?: string
37
+ /** Label of the `h6` option. Defaults to `'Heading 6'`. */
38
+ h6?: string
39
+ }
40
+
41
+ export interface NexxtEditorHeadingTypeProps {
42
+ /**
43
+ * Header text of the settings block. Defaults to the Dutch `'Type'`; the
44
+ * library has no i18n layer, so a consumer in another language passes its
45
+ * own copy in.
46
+ */
47
+ label?: string
48
+ /**
49
+ * Labels of the six options. The defaults use the English term "Heading",
50
+ * as the Dutch design in Figma does, and are merged per key, so overriding
51
+ * one label keeps the defaults of the others. Copy is never translated
52
+ * inside the component.
53
+ */
54
+ messages?: EditorHeadingTypeMessages
55
+ }
56
+
57
+ const DEFAULT_MESSAGES = {
58
+ h1: 'Heading 1',
59
+ h2: 'Heading 2',
60
+ h3: 'Heading 3',
61
+ h4: 'Heading 4',
62
+ h5: 'Heading 5',
63
+ h6: 'Heading 6',
64
+ } satisfies Required<EditorHeadingTypeMessages>
65
+ </script>
66
+
67
+ <script lang="ts" setup>
68
+ import { computed } from 'vue'
69
+ import NexxtEditorSettingsBlock from '../../atoms/EditorSettingsBlock/EditorSettingsBlock.vue'
70
+ import NexxtSelect from '../../../molecules/Select/Select.vue'
71
+ import type { SelectOption } from '../../../molecules/Select/Select.vue'
72
+
73
+ defineOptions({ name: 'NexxtEditorHeadingType' })
74
+
75
+ const { label = 'Type', messages } = defineProps<NexxtEditorHeadingTypeProps>()
76
+
77
+ /** The selected heading, as the Tailwind font-size class to apply. */
78
+ const model = defineModel<EditorHeadingTypeValue>({ required: true })
79
+
80
+ const copy = computed(() => ({ ...DEFAULT_MESSAGES, ...messages }))
81
+
82
+ // The level doubles as the messages key and the Font Awesome icon name --
83
+ // `h1` through `h6` all exist in the kit.
84
+ const options = computed<SelectOption[]>(() =>
85
+ HEADING_LEVELS.map(({ level, size }) => {
86
+ const key = `h${level}` as const
87
+ return { value: size, label: copy.value[key], icon: key }
88
+ }),
89
+ )
90
+
91
+ const values = HEADING_LEVELS.map(({ size }) => size)
92
+
93
+ // Select types its model as the open `string | number | null` of its options,
94
+ // so writing straight back into the narrower model is a type error. The setter
95
+ // is the one place that narrowing happens, and it is guarded: a value that is
96
+ // not one of the six options is dropped rather than written through.
97
+ const selected = computed({
98
+ get: () => model.value,
99
+ set: (value: string | number | null) => {
100
+ const found = values.find((option) => option === value)
101
+ if (found) model.value = found
102
+ },
103
+ })
104
+ </script>
105
+
106
+ <template>
107
+ <NexxtEditorSettingsBlock :label="label">
108
+ <!--
109
+ Select is `inline-flex` and its field carries a `min-w-60`, so without
110
+ `w-full` it would sit at that minimum instead of filling the block. The
111
+ class lands on Select's root, whose trigger is already `w-full`.
112
+ -->
113
+ <!--
114
+ The block label is a <p>, not a <label>, so the combobox would have no
115
+ accessible name of its own; `aria-label` gives it the same copy without
116
+ repeating it on screen.
117
+ -->
118
+ <NexxtSelect v-model="selected" :options="options" :aria-label="label" class="w-full" />
119
+ </NexxtEditorSettingsBlock>
120
+ </template>
@@ -3,11 +3,25 @@ import { computed, ref, useTemplateRef, watch } from 'vue'
3
3
  import NexxtIcon from '../../atoms/Icon/Icon.vue'
4
4
  import NexxtFloatingPanel from '../../atoms/FloatingPanel/FloatingPanel.vue'
5
5
  import type Icon from '../../atoms/Icon/Icon.vue'
6
-
7
- export type SelectOption = { label: string; value: string | number } | string
6
+ import type { NexxtIconName } from '../../atoms/Icon/Icon.vue'
7
+
8
+ export type SelectOption =
9
+ | {
10
+ label: string
11
+ value: string | number
12
+ /**
13
+ * Icon rendered before the option's label in the list, and in the field
14
+ * while the option is selected. Optional; an explicit `leftIcon` on the
15
+ * field wins over it.
16
+ */
17
+ icon?: NexxtIconName
18
+ }
19
+ | string
8
20
 
9
21
  const getLabel = (opt: SelectOption) => (typeof opt === 'string' ? opt : opt.label)
10
22
  const getValue = (opt: SelectOption): string | number => (typeof opt === 'string' ? opt : opt.value)
23
+ const getIcon = (opt: SelectOption): NexxtIconName | undefined =>
24
+ typeof opt === 'string' ? undefined : opt.icon
11
25
 
12
26
  const generateId = () => 'select-' + Math.random().toString(36).slice(2, 10)
13
27
  const selectId = generateId()
@@ -31,6 +45,13 @@ interface NexxtSelectProps {
31
45
  leftIcon?: InstanceType<typeof Icon>['name']
32
46
  /** Mark the field as required (renders an asterisk next to the label). */
33
47
  required?: boolean
48
+ /**
49
+ * Accessible name of the field, for when it is labelled by something outside
50
+ * the component and `label` would duplicate that copy on screen. Lands on the
51
+ * combobox itself, which a fallthrough attribute cannot reach: the component
52
+ * root is the wrapper around it.
53
+ */
54
+ ariaLabel?: string
34
55
  }
35
56
 
36
57
  const props = withDefaults(defineProps<NexxtSelectProps>(), {
@@ -55,6 +76,14 @@ const selectedIndex = computed(() =>
55
76
  props.options.findIndex((opt) => getValue(opt) === model.value),
56
77
  )
57
78
 
79
+ // The field shows one icon at most. An explicit `leftIcon` is the field's own
80
+ // decoration and outranks the selected option's icon, which is only a fallback.
81
+ const triggerIcon = computed<NexxtIconName | undefined>(() => {
82
+ if (props.leftIcon) return props.leftIcon
83
+ const found = props.options.find((opt) => getValue(opt) === model.value)
84
+ return found ? getIcon(found) : undefined
85
+ })
86
+
58
87
  const select = (opt: SelectOption, close: () => void) => {
59
88
  model.value = getValue(opt)
60
89
  close()
@@ -139,22 +168,26 @@ watch(model, () => {
139
168
  <div
140
169
  :id="selectId"
141
170
  role="combobox"
171
+ :aria-label="ariaLabel"
142
172
  :aria-expanded="isOpen"
143
173
  aria-haspopup="listbox"
144
174
  :aria-controls="isOpen ? listboxId : undefined"
145
175
  :aria-activedescendant="isOpen && activeIndex >= 0 ? optionId(activeIndex) : undefined"
146
176
  tabindex="0"
147
177
  class="group flex w-full cursor-pointer items-center gap-2 rounded-lg ring transition-colors ease-out focus:ring-cornflower-blue-500 focus:outline-none"
148
- :class="[error ? 'ring-brick-400' : 'ring-gray-200', { 'pl-3': leftIcon, 'pr-3': true }]"
178
+ :class="[
179
+ error ? 'ring-brick-400' : 'ring-gray-200',
180
+ { 'pl-3': triggerIcon, 'pr-3': true },
181
+ ]"
149
182
  @click="toggle"
150
183
  @keydown="onKeydown"
151
184
  >
152
- <span v-if="leftIcon" class="flex items-center">
153
- <NexxtIcon :name="leftIcon" />
185
+ <span v-if="triggerIcon" class="flex items-center">
186
+ <NexxtIcon :name="triggerIcon" />
154
187
  </span>
155
188
  <span
156
189
  class="flex h-10 w-full min-w-60 items-center text-sm"
157
- :class="[selectedLabel ? 'text-gray-900' : 'text-gray-400', { 'pl-3': !leftIcon }]"
190
+ :class="[selectedLabel ? 'text-gray-900' : 'text-gray-400', { 'pl-3': !triggerIcon }]"
158
191
  >
159
192
  {{ selectedLabel ?? placeholder }}
160
193
  </span>
@@ -186,7 +219,16 @@ watch(model, () => {
186
219
  @click="select(opt, close)"
187
220
  @mousemove="activeIndex = index"
188
221
  >
189
- {{ getLabel(opt) }}
222
+ <span class="flex items-center gap-2">
223
+ <!-- The cast is the v-if guard restated: `name` is required, and
224
+ template narrowing does not carry across a function call. -->
225
+ <NexxtIcon
226
+ v-if="getIcon(opt)"
227
+ :name="getIcon(opt) as NexxtIconName"
228
+ class="shrink-0"
229
+ />
230
+ {{ getLabel(opt) }}
231
+ </span>
190
232
  <NexxtIcon v-if="model === getValue(opt)" name="check" class="text-xs" />
191
233
  </li>
192
234
  </ul>
@@ -63,9 +63,11 @@
63
63
  "NexxtVideoPlayer": "components/organisms/VideoPlayer/VideoPlayer.vue",
64
64
  "NexxtEditorSettingsBlock": "components/editor/atoms/EditorSettingsBlock/EditorSettingsBlock.vue",
65
65
  "NexxtEditorAlignItems": "components/editor/molecules/EditorAlignItems/EditorAlignItems.vue",
66
+ "NexxtEditorColor": "components/editor/molecules/EditorColor/EditorColor.vue",
66
67
  "NexxtEditorFlexDirection": "components/editor/molecules/EditorFlexDirection/EditorFlexDirection.vue",
67
68
  "NexxtEditorGap": "components/editor/molecules/EditorGap/EditorGap.vue",
69
+ "NexxtEditorHeadingType": "components/editor/molecules/EditorHeadingType/EditorHeadingType.vue",
68
70
  "NexxtEditorJustifyContent": "components/editor/molecules/EditorJustifyContent/EditorJustifyContent.vue",
69
- "NexxtEditorRadius": "components/editor/molecules/EditorRadius/EditorRadius.vue",
70
- "NexxtEditorPadding": "components/editor/molecules/EditorPadding/EditorPadding.vue"
71
+ "NexxtEditorPadding": "components/editor/molecules/EditorPadding/EditorPadding.vue",
72
+ "NexxtEditorRadius": "components/editor/molecules/EditorRadius/EditorRadius.vue"
71
73
  }
package/src/index.ts CHANGED
@@ -25,6 +25,15 @@ export type {
25
25
  EditorGapMessages,
26
26
  EditorGapValue,
27
27
  } from './components/editor/molecules/EditorGap/EditorGap.vue'
28
+ export type {
29
+ EditorColorMessages,
30
+ EditorColorProperty,
31
+ EditorColorValue,
32
+ } from './components/editor/molecules/EditorColor/EditorColor.vue'
33
+ export type {
34
+ EditorHeadingTypeMessages,
35
+ EditorHeadingTypeValue,
36
+ } from './components/editor/molecules/EditorHeadingType/EditorHeadingType.vue'
28
37
  export type {
29
38
  EditorRadiusMessages,
30
39
  EditorRadiusValue,
@@ -58,11 +67,13 @@ export { default as NexxtDatePicker } from './components/organisms/DatePicker/Da
58
67
  export { default as NexxtDoughnutChart } from './components/molecules/DoughnutChart/DoughnutChart.vue'
59
68
  export { default as NexxtDropdownButton } from './components/organisms/DropdownButton/DropdownButton.vue'
60
69
  export { default as NexxtEditorAlignItems } from './components/editor/molecules/EditorAlignItems/EditorAlignItems.vue'
70
+ export { default as NexxtEditorColor } from './components/editor/molecules/EditorColor/EditorColor.vue'
61
71
  export { default as NexxtEditorFlexDirection } from './components/editor/molecules/EditorFlexDirection/EditorFlexDirection.vue'
62
72
  export { default as NexxtEditorGap } from './components/editor/molecules/EditorGap/EditorGap.vue'
73
+ export { default as NexxtEditorHeadingType } from './components/editor/molecules/EditorHeadingType/EditorHeadingType.vue'
63
74
  export { default as NexxtEditorJustifyContent } from './components/editor/molecules/EditorJustifyContent/EditorJustifyContent.vue'
64
- export { default as NexxtEditorRadius } from './components/editor/molecules/EditorRadius/EditorRadius.vue'
65
75
  export { default as NexxtEditorPadding } from './components/editor/molecules/EditorPadding/EditorPadding.vue'
76
+ export { default as NexxtEditorRadius } from './components/editor/molecules/EditorRadius/EditorRadius.vue'
66
77
  export { default as NexxtEditorSettingsBlock } from './components/editor/atoms/EditorSettingsBlock/EditorSettingsBlock.vue'
67
78
  export { default as NexxtEnergyLabel } from './components/atoms/EnergyLabel/EnergyLabel.vue'
68
79
  export { default as NexxtFloatingPanel } from './components/atoms/FloatingPanel/FloatingPanel.vue'