@thekestongroup/ui 0.7.0 → 0.9.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 (68) hide show
  1. package/dist/components/Breadcrumb/Breadcrumb.vue.d.ts +0 -1
  2. package/dist/components/Checkbox/Checkbox.vue.d.ts +2 -0
  3. package/dist/components/CheckboxGroup/CheckboxGroup.vue.d.ts +45 -0
  4. package/dist/components/Chip/Chip.vue.d.ts +0 -1
  5. package/dist/components/Header/Header.vue.d.ts +0 -1
  6. package/dist/components/InputDate/InputDate.vue.d.ts +1 -1
  7. package/dist/components/InputTextArea/InputTextArea.vue.d.ts +49 -0
  8. package/dist/components/LanguageSwitcher/LanguageSwitcher.vue.d.ts +24 -0
  9. package/dist/components/Notification/NotificationPane.vue.d.ts +1 -4
  10. package/dist/components/Select/Select.vue.d.ts +0 -1
  11. package/dist/components/SettingsRow/SettingsRow.vue.d.ts +28 -0
  12. package/dist/components/Sidebar/Sidebar.vue.d.ts +0 -1
  13. package/dist/components/Slideover/Slideover.vue.d.ts +0 -1
  14. package/dist/components/Spinner/Spinner.vue.d.ts +0 -1
  15. package/dist/components/Steps/Steps.vue.d.ts +20 -0
  16. package/dist/components/Switch/Switch.vue.d.ts +2 -0
  17. package/dist/components/Table/Table.vue.d.ts +21 -1
  18. package/dist/i18n/en.d.ts +146 -0
  19. package/dist/i18n/index.d.ts +32 -0
  20. package/dist/index.d.ts +12 -0
  21. package/dist/keston-ui.js +2200 -1694
  22. package/package.json +4 -2
  23. package/src/components/Age/Age.vue +4 -2
  24. package/src/components/AppShell/AppShell.vue +4 -2
  25. package/src/components/AvatarGroup/AvatarGroup.vue +4 -2
  26. package/src/components/Breadcrumb/Breadcrumb.vue +3 -2
  27. package/src/components/Calendar/Calendar.vue +8 -6
  28. package/src/components/Card/Card.vue +3 -1
  29. package/src/components/Checkbox/Checkbox.stories.ts +3 -0
  30. package/src/components/Checkbox/Checkbox.vue +3 -1
  31. package/src/components/CheckboxGroup/CheckboxGroup.stories.ts +48 -0
  32. package/src/components/CheckboxGroup/CheckboxGroup.vue +96 -0
  33. package/src/components/Chip/Chip.vue +3 -2
  34. package/src/components/FormField/FormField.vue +3 -1
  35. package/src/components/Header/Header.vue +6 -5
  36. package/src/components/Input/Input.vue +4 -2
  37. package/src/components/InputCode/InputCode.vue +4 -2
  38. package/src/components/InputDate/InputDate.vue +4 -2
  39. package/src/components/InputPassword/InputPassword.vue +4 -2
  40. package/src/components/InputRichText/InputRichText.vue +6 -4
  41. package/src/components/InputTextArea/InputTextArea.stories.ts +53 -0
  42. package/src/components/InputTextArea/InputTextArea.vue +89 -0
  43. package/src/components/LanguageSwitcher/LanguageSwitcher.stories.ts +21 -0
  44. package/src/components/LanguageSwitcher/LanguageSwitcher.vue +57 -0
  45. package/src/components/Link/Link.vue +1 -0
  46. package/src/components/Notification/Notification.vue +3 -1
  47. package/src/components/Notification/NotificationPane.vue +10 -8
  48. package/src/components/Notification/Toaster.vue +9 -7
  49. package/src/components/PageHeader/PageHeader.vue +13 -2
  50. package/src/components/Progress/Progress.vue +3 -1
  51. package/src/components/RadioGroup/RadioGroup.vue +3 -1
  52. package/src/components/Select/Select.vue +6 -5
  53. package/src/components/SettingsRow/SettingsRow.stories.ts +59 -0
  54. package/src/components/SettingsRow/SettingsRow.vue +39 -0
  55. package/src/components/Sidebar/Sidebar.vue +5 -4
  56. package/src/components/Slideover/Slideover.vue +8 -7
  57. package/src/components/Spinner/Spinner.vue +4 -3
  58. package/src/components/StatTile/StatTile.vue +3 -1
  59. package/src/components/Steps/Steps.stories.ts +38 -0
  60. package/src/components/Steps/Steps.vue +38 -0
  61. package/src/components/SummaryList/SummaryList.vue +5 -4
  62. package/src/components/Switch/Switch.vue +3 -1
  63. package/src/components/Table/Table.stories.ts +34 -0
  64. package/src/components/Table/Table.vue +120 -15
  65. package/src/i18n/en.ts +127 -0
  66. package/src/i18n/i18n.test.ts +56 -0
  67. package/src/i18n/index.ts +89 -0
  68. package/src/index.ts +14 -0
package/src/i18n/en.ts ADDED
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Keston UI's own words in English: what its components say and announce
3
+ * (button names, screen reader text, empty and error messages). Apps add
4
+ * these to their vue-i18n messages (see `createKestonI18n`) and keep their
5
+ * own under other keys.
6
+ *
7
+ * To add a language, copy this object, translate the values and give it to
8
+ * `createKestonI18n` under its code, e.g. `{ en, cy }`. Keep the keys and
9
+ * the `{placeholders}` as they are.
10
+ */
11
+ export const en = {
12
+ ui: {
13
+ age: {
14
+ born: 'Born {date}',
15
+ birthdayToday: 'Birthday today',
16
+ birthdayTomorrow: 'Birthday tomorrow',
17
+ birthdayInDays: 'Birthday in {days} days'
18
+ },
19
+ appShell: {
20
+ menu: 'Menu',
21
+ expandSidebar: 'Expand sidebar',
22
+ collapseSidebar: 'Collapse sidebar'
23
+ },
24
+ avatar: {
25
+ account: 'Account: {name}',
26
+ accountWithInitials: '{initials}, account: {name}'
27
+ },
28
+ avatarGroup: {
29
+ people: 'no people | 1 person | {count} people',
30
+ more: '{count} more: {names}'
31
+ },
32
+ breadcrumb: { label: 'Breadcrumb' },
33
+ calendar: {
34
+ previousMonth: 'Previous month',
35
+ nextMonth: 'Next month',
36
+ previousYear: 'Previous year',
37
+ nextYear: 'Next year',
38
+ previousYears: 'Previous years',
39
+ nextYears: 'Next years',
40
+ chooseMonth: 'Choose month',
41
+ chooseYear: 'Choose year'
42
+ },
43
+ chip: { remove: 'Remove' },
44
+ formField: { about: 'About {label}' },
45
+ header: {
46
+ menu: 'Menu',
47
+ signIn: 'Sign in',
48
+ account: 'Account: {name}',
49
+ accountWithInitials: '{initials}, account: {name}'
50
+ },
51
+ input: {
52
+ maxLength: 'Must be {count} characters or fewer',
53
+ minLength: 'Must be at least {count} characters'
54
+ },
55
+ inputCode: { character: 'Character {n} of {total}' },
56
+ inputDate: {
57
+ openCalendar: 'Open calendar',
58
+ enterDate: 'Enter a date like {example}'
59
+ },
60
+ inputPassword: {
61
+ capsLock: 'Caps Lock is on',
62
+ show: 'Show password'
63
+ },
64
+ inputRichText: {
65
+ formattingFor: 'Formatting for {label}',
66
+ bold: 'Bold',
67
+ italic: 'Italic',
68
+ underline: 'Underline'
69
+ },
70
+ languageSwitcher: { label: 'Language' },
71
+ notifications: {
72
+ title: 'Notifications',
73
+ region: 'Notification',
74
+ hotkeyRegion: 'Notifications ({hotkey})',
75
+ notifications: 'notifications',
76
+ empty: 'You’re all caught up.',
77
+ withUnread: '{label}, {count} unread',
78
+ dismiss: 'Dismiss: {title}',
79
+ close: 'Close: {title}',
80
+ clearAll: 'Clear all',
81
+ more: '+{count} more'
82
+ },
83
+ pageHeader: {
84
+ actions: '{title} actions',
85
+ moreActions: 'More actions'
86
+ },
87
+ progress: { stepOf: 'Step {current} of {total}' },
88
+ select: {
89
+ choose: 'Choose…',
90
+ search: 'Search…',
91
+ noMatches: 'No matches',
92
+ showOptions: 'Show options',
93
+ remove: 'Remove {name}'
94
+ },
95
+ sidebar: {
96
+ main: 'Main',
97
+ backFrom: 'Back from {name}',
98
+ expand: 'Expand sidebar',
99
+ collapse: 'Collapse sidebar'
100
+ },
101
+ slideover: {
102
+ close: 'Close',
103
+ cancel: 'Cancel',
104
+ previous: 'Previous',
105
+ next: 'Next',
106
+ finish: 'Finish',
107
+ steps: 'Steps',
108
+ stepOf: 'Step {current} of {total}: {name}'
109
+ },
110
+ spinner: { loading: 'Loading' },
111
+ statTile: { up: 'Up', down: 'Down', flat: 'No change' },
112
+ steps: {
113
+ stepOf: 'Step {current} of {total}',
114
+ stepOfNamed: 'Step {current} of {total}: {name}'
115
+ },
116
+ summaryList: { notSet: 'Not set' },
117
+ table: {
118
+ table: 'Table',
119
+ empty: 'Nothing to show.',
120
+ selectAll: 'Select all rows',
121
+ selectRow: 'Select row {n}',
122
+ select: 'Select'
123
+ }
124
+ }
125
+ }
126
+
127
+ export type UiMessages = typeof en
@@ -0,0 +1,56 @@
1
+ import { beforeEach, describe, expect, it, vi } from 'vitest'
2
+ import { createKestonI18n, en } from './index'
3
+
4
+ // Tests run in Node: stand in for the browser's storage and <html>.
5
+ const store = new Map<string, string>()
6
+ const html = { lang: '' }
7
+ vi.stubGlobal('localStorage', {
8
+ getItem: (k: string) => store.get(k) ?? null,
9
+ setItem: (k: string, v: string) => void store.set(k, v),
10
+ clear: () => store.clear()
11
+ })
12
+ vi.stubGlobal('document', { documentElement: html })
13
+
14
+ describe('createKestonI18n', () => {
15
+ beforeEach(() => store.clear())
16
+
17
+ it('has Keston UI’s words and the app’s own', () => {
18
+ const i18n = createKestonI18n({ messages: { en: { users: { title: 'Users' } } } })
19
+ expect(i18n.global.t('ui.slideover.close')).toBe('Close')
20
+ expect(i18n.global.t('users.title')).toBe('Users')
21
+ })
22
+
23
+ it('falls back to English for a language that lacks a word', () => {
24
+ const i18n = createKestonI18n({ locale: 'cy', messages: { cy: { users: { title: 'Defnyddwyr' } } } })
25
+ expect(i18n.global.t('users.title')).toBe('Defnyddwyr')
26
+ expect(i18n.global.t('ui.slideover.close')).toBe('Close')
27
+ })
28
+
29
+ it('remembers the language and sets <html lang>', async () => {
30
+ const i18n = createKestonI18n({ messages: { cy: {} } })
31
+ i18n.global.locale.value = 'cy'
32
+ await Promise.resolve()
33
+ expect(localStorage.getItem('keston-locale')).toBe('cy')
34
+ expect(html.lang).toBe('cy')
35
+ expect(createKestonI18n({ messages: { cy: {} } }).global.locale.value).toBe('cy')
36
+ })
37
+
38
+ it('ignores a saved language the app no longer has', () => {
39
+ localStorage.setItem('keston-locale', 'fr')
40
+ expect(createKestonI18n().global.locale.value).toBe('en')
41
+ })
42
+
43
+ it('has a working message for every key', () => {
44
+ const i18n = createKestonI18n()
45
+ const leaves = (node: Record<string, unknown>, path = ''): string[] =>
46
+ Object.entries(node).flatMap(([k, v]) =>
47
+ typeof v === 'object' && v ? leaves(v as Record<string, unknown>, `${path}${k}.`) : [`${path}${k}`]
48
+ )
49
+ const keys = leaves(en)
50
+ expect(keys.length).toBeGreaterThan(50)
51
+ for (const key of keys) {
52
+ const text = i18n.global.t(key, { count: 2, n: 2, current: 1, total: 3, name: 'X', label: 'X', title: 'X', names: 'X', hotkey: 'X', example: 'X', initials: 'X', date: 'X', days: 2 }, 2)
53
+ expect(text, key).not.toBe(key)
54
+ }
55
+ })
56
+ })
@@ -0,0 +1,89 @@
1
+ import { watch } from 'vue'
2
+ import { createI18n } from 'vue-i18n'
3
+ import { en } from './en'
4
+
5
+ export { en } from './en'
6
+ export type { UiMessages } from './en'
7
+
8
+ /** Words by language code, then by key (nested objects are fine). */
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
+ export type Messages = Record<string, Record<string, any>>
11
+
12
+ /** Keston UI's own words, by language. Today: English. */
13
+ export const uiMessages: Messages = { en }
14
+
15
+ export interface KestonI18nOptions {
16
+ /**
17
+ * The app's own words, by language code: `{ en: { users: { title: 'Users' } } }`.
18
+ * Keston UI's words are added to each language (the app's win if a key
19
+ * is repeated), so only languages that Keston UI also has — or that the
20
+ * app lists here — are available.
21
+ */
22
+ messages?: Messages
23
+ /** The language to start in. Default: the one saved last time, else the browser's, else `fallbackLocale`. */
24
+ locale?: string
25
+ /** Used for any word a language is missing. Default `en`. */
26
+ fallbackLocale?: string
27
+ /** Where the chosen language is remembered (localStorage). Default `keston-locale`. */
28
+ storageKey?: string
29
+ }
30
+
31
+ /**
32
+ * Sets up vue-i18n the way every Keston app should: Keston UI's words plus
33
+ * the app's own, English as the fallback, the language remembered between
34
+ * visits, and `<html lang>` kept in step. Install it with `app.use(i18n)`.
35
+ *
36
+ * ```ts
37
+ * const i18n = createKestonI18n({ messages: { en } })
38
+ * createApp(App).use(i18n).mount('#app')
39
+ * ```
40
+ */
41
+ export function createKestonI18n(options: KestonI18nOptions = {}) {
42
+ const { messages = {}, fallbackLocale = 'en', storageKey = 'keston-locale' } = options
43
+
44
+ const codes = [...new Set([...Object.keys(uiMessages), ...Object.keys(messages)])]
45
+ const merged: Messages = {}
46
+ for (const code of codes) merged[code] = { ...uiMessages[code], ...messages[code] }
47
+
48
+ const i18n = createI18n({
49
+ legacy: false,
50
+ locale: options.locale ?? initialLocale(codes, fallbackLocale, storageKey),
51
+ fallbackLocale,
52
+ messages: merged
53
+ })
54
+
55
+ // Remember the choice, and tell the browser (screen readers pick the
56
+ // voice by it, browsers offer translation by it).
57
+ watch(
58
+ i18n.global.locale,
59
+ (locale) => {
60
+ try {
61
+ localStorage.setItem(storageKey, locale)
62
+ } catch {
63
+ // Private windows can refuse storage; the choice just isn't remembered.
64
+ }
65
+ if (typeof document !== 'undefined') document.documentElement.lang = locale
66
+ },
67
+ { immediate: true }
68
+ )
69
+
70
+ return i18n
71
+ }
72
+
73
+ /** Saved choice, else the browser's languages in order, else the fallback. */
74
+ function initialLocale(codes: string[], fallback: string, storageKey: string): string {
75
+ try {
76
+ const saved = localStorage.getItem(storageKey)
77
+ if (saved && codes.includes(saved)) return saved
78
+ } catch {
79
+ // No storage: carry on.
80
+ }
81
+ if (typeof navigator !== 'undefined') {
82
+ for (const wanted of navigator.languages ?? []) {
83
+ const exact = codes.find((c) => c.toLowerCase() === wanted.toLowerCase())
84
+ const base = codes.find((c) => c.toLowerCase() === wanted.split('-')[0]!.toLowerCase())
85
+ if (exact ?? base) return (exact ?? base)!
86
+ }
87
+ }
88
+ return fallback
89
+ }
package/src/index.ts CHANGED
@@ -12,6 +12,8 @@ export { default as Header } from './components/Header/Header.vue'
12
12
  export type { HeaderProps, HeaderUser, HeaderUserAction } from './components/Header/Header.vue'
13
13
  export { default as PageHeader } from './components/PageHeader/PageHeader.vue'
14
14
  export type { PageHeaderAction, PageHeaderProps } from './components/PageHeader/PageHeader.vue'
15
+ export { default as SettingsRow } from './components/SettingsRow/SettingsRow.vue'
16
+ export type { SettingsRowProps } from './components/SettingsRow/SettingsRow.vue'
15
17
 
16
18
  // Element
17
19
  export { default as Avatar } from './components/Avatar/Avatar.vue'
@@ -58,6 +60,12 @@ export { default as Switch } from './components/Switch/Switch.vue'
58
60
  export type { SwitchProps } from './components/Switch/Switch.vue'
59
61
  export { default as Calendar } from './components/Calendar/Calendar.vue'
60
62
  export type { CalendarProps } from './components/Calendar/Calendar.vue'
63
+ export { default as InputTextArea } from './components/InputTextArea/InputTextArea.vue'
64
+ export type { InputTextAreaProps } from './components/InputTextArea/InputTextArea.vue'
65
+ export { default as CheckboxGroup } from './components/CheckboxGroup/CheckboxGroup.vue'
66
+ export type { CheckboxGroupProps, CheckboxOption, CheckboxGroupValue } from './components/CheckboxGroup/CheckboxGroup.vue'
67
+ export { default as LanguageSwitcher } from './components/LanguageSwitcher/LanguageSwitcher.vue'
68
+ export type { LanguageSwitcherProps } from './components/LanguageSwitcher/LanguageSwitcher.vue'
61
69
 
62
70
  // Data
63
71
  export { default as Table } from './components/Table/Table.vue'
@@ -85,6 +93,8 @@ export type { SidebarProps, SidebarItem, SidebarSection } from './components/Sid
85
93
  export { sidebarTrail } from './components/Sidebar/sidebar'
86
94
  export { default as Link } from './components/Link/Link.vue'
87
95
  export type { LinkProps } from './components/Link/Link.vue'
96
+ export { default as Steps } from './components/Steps/Steps.vue'
97
+ export type { StepsProps } from './components/Steps/Steps.vue'
88
98
 
89
99
  // Overlay
90
100
  export { default as Popover } from './components/Popover/Popover.vue'
@@ -115,6 +125,10 @@ export type {
115
125
  ToastOptions
116
126
  } from './components/Notification/notifications'
117
127
 
128
+ // Languages
129
+ export { createKestonI18n, uiMessages, en } from './i18n'
130
+ export type { KestonI18nOptions, Messages, UiMessages } from './i18n'
131
+
118
132
  // Helpers
119
133
  export { age, daysToBirthday, formatDate, formatDateTime, toDate } from './lib/dates'
120
134
  export type { DateInput } from './lib/dates'