sit-onyx 0.1.0-alpha.0 → 0.1.0-alpha.2

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/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  </a>
7
7
  </p>
8
8
 
9
- # Onyx
9
+ # onyx
10
10
 
11
11
  A design system and Vue.js component library created by [Schwarz IT](https://it.schwarz).
12
12
 
@@ -40,7 +40,7 @@ After that, import the global CSS file in your `main.ts` file:
40
40
 
41
41
  ```ts
42
42
  import "sit-onyx/style.css";
43
- // if you override some Onyx styles (e.g. CSS variables),
43
+ // if you override some onyx styles (e.g. CSS variables),
44
44
  // make sure to import your custom CSS file after the default "sit-onyx/style.css"
45
45
  ```
46
46
 
@@ -22,3 +22,12 @@ export declare const Required: {
22
22
  label: string;
23
23
  };
24
24
  };
25
+ /**
26
+ * This example shows an input with a custom error.
27
+ */
28
+ export declare const CustomError: {
29
+ args: {
30
+ label: string;
31
+ errorMessage: string;
32
+ };
33
+ };
@@ -7,8 +7,8 @@ export type TestInputProps = {
7
7
  /** Label to show next to the input */
8
8
  label?: string;
9
9
  /**
10
- * Error message to show when the input is invalid.
11
- * If unset, a default error message is used that is provided by Onyx depending
10
+ * Error message to show when the input is invalid. Will only show up after the input was touched.
11
+ * If unset, a default error message is used that is provided by onyx depending
12
12
  * on your current locale/language and validation.
13
13
  */
14
14
  errorMessage?: string;
@@ -2,13 +2,13 @@ import type { ObjectToDottedStrings } from '../types/i18n';
2
2
  import type { DeepPartial } from '../types/utils';
3
3
  import { type MaybeRef } from "vue";
4
4
  import enUS from "./locales/en-US.json";
5
- /** Available translations that are used by Onyx components. */
5
+ /** Available translations that are used by onyx components. */
6
6
  export type OnyxTranslations = typeof enUS;
7
7
  export type ProvideI18nOptions = {
8
8
  /**
9
9
  * Current locale / language to use.
10
10
  * If a ref is passed (e.g. the locale from the `vue-i18n` package)
11
- * all Onyx messages will be updated if it changes (if locale is supported).
11
+ * all onyx messages will be updated if it changes (if locale is supported).
12
12
  * If a message is missing for your currently set locale, English will be used as fallback.
13
13
  *
14
14
  * @default "en-US"
@@ -32,12 +32,13 @@ export type ProvideI18nOptions = {
32
32
  messages?: Record<string, DeepPartial<OnyxTranslations>>;
33
33
  };
34
34
  /**
35
- * Provides a global i18n instance that is used by Onyx.
36
- * Must only be called once in the `App.vue` file of a project that consumes Onyx.
35
+ * Provides a global i18n instance that is used by onyx.
36
+ * Must only be called once in the `App.vue` file of a project that consumes onyx.
37
37
  */
38
38
  export declare const provideI18n: (options: ProvideI18nOptions) => void;
39
39
  /**
40
- * Injects the Onyx i18n instance.
40
+ * Injects the onyx i18n instance.
41
+ * Creates a fallback if provide was never called.
41
42
  */
42
43
  export declare const injectI18n: () => {
43
44
  locale: import("vue").ComputedRef<string>;
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("vue"),M={tooShort:"Please lengthen this text to {minLength} characters or more (you are currently using 1 character) | Please lengthen this text to {minLength} characters or more (you are currently using {n} characters)",tooLong:"Please shorten this text to {maxLength} characters or less (you are currently using 1 character) | Please shorten this text to {maxLength} characters or less (you are currently using {n} characters)",rangeUnderflow:"Value must be greater than or equal to {min}",rangeOverflow:"Value must be less than or equal to {max}",patternMismatch:"Please match the format requested.",valueMissing:"Please fill in this field.",stepMismatch:"Please enter a value that is a multiple of {step}.",badInput:'"{value}" does not match the expected type.',typeMismatch:{generic:'"{value}" does not match the expected type.',email:'"{value}" must be a valid email address.',number:'"{value}" must be a number.',tel:'"{value}" must be a valid phone number.',url:'"{value}" must a valid URL.'}},p={validations:M},y=Symbol(),_=a=>{const n=t.computed(()=>t.unref(a==null?void 0:a.locale)??"en-US"),e=t.computed(()=>a!=null&&a.messages&&n.value in a.messages?a.messages[n.value]:p),r=t.computed(()=>(l,u={})=>{let i=f(l,e.value)??f(l,p)??"";const o=typeof u.n=="number"?u.n:void 0;return i=P(i,o),E(i,u)});return{locale:n,t:r}},S=a=>{t.provide(y,_(a))},I=()=>{const a=_();return t.inject(y,a)},f=(a,n)=>{const e=a.split(".").reduce((r,l)=>!r||typeof r=="string"?r:r[l],n);return e&&typeof e=="string"?e:void 0},P=(a,n)=>{const e=a.split(" | ").map(l=>l.trim());if(e.length<=1)return a;let r=1;return n===0&&(r=0),n&&(n<=0||n>1)&&(r=2),e.length===2?r===1?e[0]:e[1]:e[r]},E=(a,n)=>n?Object.entries(n).reduce((r,[l,u])=>u===void 0?r:r.replace(new RegExp(`{${l}}`,"gi"),u.toString()),a).replace(/\s?{.*}\s?/gi,""):a,L=a=>{if(a.valueMissing)return"valueMissing";const n=Object.entries(Object.getOwnPropertyDescriptors(ValidityState.prototype)).filter(([e,r])=>e!=="valid"&&r.enumerable).map(([e])=>e);for(const e of n)if(e in a&&a[e])return e},T={key:0,class:"input__error","aria-live":"polite"},V={class:"input__info"},C=Object.keys(p.validations.typeMismatch),N=t.defineComponent({__name:"TestInput",props:{modelValue:{default:""},label:{default:""},errorMessage:{},required:{type:Boolean},pattern:{},type:{default:"text"},max:{},maxLength:{},min:{},step:{},minLength:{}},emits:["update:modelValue","change","validityChange"],setup(a,{emit:n}){var d;const e=a,r=n,{t:l}=I(),u=t.ref(!1),i=t.ref(null),o=t.ref((d=i.value)==null?void 0:d.validity),m=t.computed({get:()=>e.modelValue,set:s=>r("update:modelValue",s)}),b=t.computed(()=>{if(!o.value||o.value.valid)return"";const s=L(o.value);if(e.errorMessage||s==="customError")return e.errorMessage;if(!s)return"";if(s==="typeMismatch"){const c=C.includes(e.type)?e.type:"generic";return l.value(`validations.typeMismatch.${c}`,{value:m.value})}return l.value(`validations.${s}`,{value:m.value,n:m.value.toString().length,minLength:e.minLength,maxLength:e.maxLength,min:e.min,max:e.max,step:e.step})}),x=s=>{const c=s.target;r("change",c.value)};return t.watch([m,i],()=>{i.value&&(o.value=i.value.validity)}),t.watch(o,s=>{s&&r("validityChange",s)},{deep:!0}),(s,c)=>{var v,g;return t.openBlock(),t.createElementBlock("label",{class:t.normalizeClass(["input",{"input--touched":u.value}])},[t.createElementVNode("span",{class:t.normalizeClass(["input__label",{"input__label--required":e.required}])},t.toDisplayString(e.label),3),t.withDirectives(t.createElementVNode("input",t.mergeProps(e,{ref_key:"inputElement",ref:i,"onUpdate:modelValue":c[0]||(c[0]=h=>m.value=h),onChange:x,onBlur:c[1]||(c[1]=h=>u.value=!0)}),null,16),[[t.vModelDynamic,m.value]]),u.value&&!((v=o.value)!=null&&v.valid)?(t.openBlock(),t.createElementBlock("p",T,t.toDisplayString(b.value),1)):t.createCommentVNode("",!0),t.createElementVNode("p",V,'Model value: "'+t.toDisplayString(m.value)+'", is valid: '+t.toDisplayString((g=o.value)==null?void 0:g.valid),1)],2)}}}),O=(a,n)=>{const e=a.__vccOpts||a;for(const[r,l]of n)e[r]=l;return e},k=O(N,[["__scopeId","data-v-5c77ef30"]]);exports.TestInput=k;exports.provideI18n=S;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("vue"),M={tooShort:"Please lengthen this text to {minLength} characters or more (you are currently using 1 character) | Please lengthen this text to {minLength} characters or more (you are currently using {n} characters)",tooLong:"Please shorten this text to {maxLength} characters or less (you are currently using 1 character) | Please shorten this text to {maxLength} characters or less (you are currently using {n} characters)",rangeUnderflow:"Value must be greater than or equal to {min}",rangeOverflow:"Value must be less than or equal to {max}",patternMismatch:"Please match the format requested.",valueMissing:"Please fill in this field.",stepMismatch:"Please enter a value that is a multiple of {step}.",badInput:'"{value}" does not match the expected type.',typeMismatch:{generic:'"{value}" does not match the expected type.',email:'"{value}" must be a valid email address.',number:'"{value}" must be a number.',tel:'"{value}" must be a valid phone number.',url:'"{value}" must a valid URL.'}},p={validations:M},f=Symbol(),x=a=>{const n=t.computed(()=>t.unref(a==null?void 0:a.locale)??"en-US"),e=t.computed(()=>a!=null&&a.messages&&n.value in a.messages?a.messages[n.value]:p),r=t.computed(()=>(s,i={})=>{let l=y(s,e.value)??y(s,p)??"";const o=typeof i.n=="number"?i.n:void 0;return l=P(l,o),V(l,i)});return{locale:n,t:r}},S=a=>{t.provide(f,x(a))},I=()=>t.inject(f,()=>x(),!0),y=(a,n)=>{const e=a.split(".").reduce((r,s)=>!r||typeof r=="string"?r:r[s],n);return e&&typeof e=="string"?e:void 0},P=(a,n)=>{const e=a.split(" | ").map(s=>s.trim());if(e.length<=1)return a;let r=1;return n===0&&(r=0),n&&(n<=0||n>1)&&(r=2),e.length===2?r===1?e[0]:e[1]:e[r]},V=(a,n)=>n?Object.entries(n).reduce((r,[s,i])=>i===void 0?r:r.replace(new RegExp(`{${s}}`,"gi"),i.toString()),a).replace(/\s?{.*}\s?/gi,""):a,E=a=>{if(a.valueMissing)return"valueMissing";const n=Object.entries(Object.getOwnPropertyDescriptors(ValidityState.prototype)).filter(([e,r])=>e!=="valid"&&r.enumerable).map(([e])=>e);for(const e of n)if(e in a&&a[e])return e},L={key:0,class:"onyx-input__error","aria-live":"polite"},T={class:"onyx-input__info"},C=Object.keys(p.validations.typeMismatch),N=t.defineComponent({__name:"TestInput",props:{modelValue:{default:""},label:{default:""},errorMessage:{},required:{type:Boolean},pattern:{},type:{default:"text"},max:{},maxLength:{},min:{},step:{},minLength:{}},emits:["update:modelValue","change","validityChange"],setup(a,{emit:n}){var d;const e=a,r=n,{t:s}=I(),i=t.ref(!1),l=t.ref(null),o=t.ref((d=l.value)==null?void 0:d.validity),m=t.computed({get:()=>e.modelValue,set:u=>r("update:modelValue",u)}),_=t.computed(()=>{if(!o.value||o.value.valid)return"";const u=E(o.value);if(e.errorMessage||u==="customError")return e.errorMessage;if(!u)return"";if(u==="typeMismatch"){const c=C.includes(e.type)?e.type:"generic";return s.value(`validations.typeMismatch.${c}`,{value:m.value})}return s.value(`validations.${u}`,{value:m.value,n:m.value.toString().length,minLength:e.minLength,maxLength:e.maxLength,min:e.min,max:e.max,step:e.step})}),b=u=>{const c=u.target;r("change",c.value)};return t.watch([m,l],()=>{l.value&&(o.value=l.value.validity)}),t.watch(o,u=>{u&&r("validityChange",u)},{deep:!0}),t.watch([e.errorMessage,l],()=>{l.value&&l.value.setCustomValidity(e.errorMessage||"")},{immediate:!0}),(u,c)=>{var v,g;return t.openBlock(),t.createElementBlock("label",{class:t.normalizeClass(["onyx-input",{"onyx-input--touched":i.value}])},[t.createElementVNode("span",{class:t.normalizeClass(["onyx-input__label",{"onyx-input__label--required":e.required}])},t.toDisplayString(e.label),3),t.withDirectives(t.createElementVNode("input",t.mergeProps(e,{ref_key:"inputElement",ref:l,"onUpdate:modelValue":c[0]||(c[0]=h=>m.value=h),onChange:b,onBlur:c[1]||(c[1]=h=>i.value=!0)}),null,16),[[t.vModelDynamic,m.value]]),i.value&&!((v=o.value)!=null&&v.valid)?(t.openBlock(),t.createElementBlock("p",L,t.toDisplayString(_.value),1)):t.createCommentVNode("",!0),t.createElementVNode("p",T,'Model value: "'+t.toDisplayString(m.value)+'", is valid: '+t.toDisplayString((g=o.value)==null?void 0:g.valid),1)],2)}}}),O=(a,n)=>{const e=a.__vccOpts||a;for(const[r,s]of n)e[r]=s;return e},D=O(N,[["__scopeId","data-v-b84504d3"]]);exports.TestInput=D;exports.provideI18n=S;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { provide as E, inject as C, computed as m, unref as O, defineComponent as N, ref as p, watch as b, openBlock as x, createElementBlock as M, normalizeClass as I, createElementVNode as d, toDisplayString as v, withDirectives as k, mergeProps as q, vModelDynamic as U, createCommentVNode as w } from "vue";
1
+ import { provide as E, inject as C, computed as m, unref as O, defineComponent as N, ref as p, watch as d, openBlock as b, createElementBlock as M, normalizeClass as L, createElementVNode as g, toDisplayString as v, withDirectives as q, mergeProps as U, vModelDynamic as k, createCommentVNode as w } from "vue";
2
2
  const D = {
3
3
  tooShort: "Please lengthen this text to {minLength} characters or more (you are currently using 1 character) | Please lengthen this text to {minLength} characters or more (you are currently using {n} characters)",
4
4
  tooLong: "Please shorten this text to {maxLength} characters or less (you are currently using 1 character) | Please shorten this text to {maxLength} characters or less (you are currently using {n} characters)",
@@ -15,21 +15,18 @@ const D = {
15
15
  tel: '"{value}" must be a valid phone number.',
16
16
  url: '"{value}" must a valid URL.'
17
17
  }
18
- }, g = {
18
+ }, h = {
19
19
  validations: D
20
- }, P = Symbol(), S = (t) => {
21
- const r = m(() => O(t == null ? void 0 : t.locale) ?? "en-US"), e = m(() => t != null && t.messages && r.value in t.messages ? t.messages[r.value] : g), a = m(() => (n, l = {}) => {
22
- let u = L(n, e.value) ?? L(n, g) ?? "";
23
- const i = typeof l.n == "number" ? l.n : void 0;
24
- return u = B(u, i), $(u, l);
20
+ }, I = Symbol(), V = (t) => {
21
+ const r = m(() => O(t == null ? void 0 : t.locale) ?? "en-US"), e = m(() => t != null && t.messages && r.value in t.messages ? t.messages[r.value] : h), a = m(() => (n, u = {}) => {
22
+ let s = P(n, e.value) ?? P(n, h) ?? "";
23
+ const i = typeof u.n == "number" ? u.n : void 0;
24
+ return s = B(s, i), $(s, u);
25
25
  });
26
26
  return { locale: r, t: a };
27
27
  }, G = (t) => {
28
- E(P, S(t));
29
- }, z = () => {
30
- const t = S();
31
- return C(P, t);
32
- }, L = (t, r) => {
28
+ E(I, V(t));
29
+ }, z = () => C(I, () => V(), !0), P = (t, r) => {
33
30
  const e = t.split(".").reduce((a, n) => !a || typeof a == "string" ? a : a[n], r);
34
31
  return e && typeof e == "string" ? e : void 0;
35
32
  }, B = (t, r) => {
@@ -38,7 +35,7 @@ const D = {
38
35
  return t;
39
36
  let a = 1;
40
37
  return r === 0 && (a = 0), r && (r <= 0 || r > 1) && (a = 2), e.length === 2 ? a === 1 ? e[0] : e[1] : e[a];
41
- }, $ = (t, r) => r ? Object.entries(r).reduce((a, [n, l]) => l === void 0 ? a : a.replace(new RegExp(`{${n}}`, "gi"), l.toString()), t).replace(/\s?{.*}\s?/gi, "") : t, j = (t) => {
38
+ }, $ = (t, r) => r ? Object.entries(r).reduce((a, [n, u]) => u === void 0 ? a : a.replace(new RegExp(`{${n}}`, "gi"), u.toString()), t).replace(/\s?{.*}\s?/gi, "") : t, j = (t) => {
42
39
  if (t.valueMissing)
43
40
  return "valueMissing";
44
41
  const r = Object.entries(
@@ -49,10 +46,10 @@ const D = {
49
46
  return e;
50
47
  }, R = {
51
48
  key: 0,
52
- class: "input__error",
49
+ class: "onyx-input__error",
53
50
  "aria-live": "polite"
54
- }, A = { class: "input__info" }, Y = Object.keys(
55
- g.validations.typeMismatch
51
+ }, A = { class: "onyx-input__info" }, Y = Object.keys(
52
+ h.validations.typeMismatch
56
53
  ), F = /* @__PURE__ */ N({
57
54
  __name: "TestInput",
58
55
  props: {
@@ -70,23 +67,23 @@ const D = {
70
67
  },
71
68
  emits: ["update:modelValue", "change", "validityChange"],
72
69
  setup(t, { emit: r }) {
73
- var h;
74
- const e = t, a = r, { t: n } = z(), l = p(!1), u = p(null), i = p((h = u.value) == null ? void 0 : h.validity), c = m({
70
+ var y;
71
+ const e = t, a = r, { t: n } = z(), u = p(!1), s = p(null), i = p((y = s.value) == null ? void 0 : y.validity), c = m({
75
72
  get: () => e.modelValue,
76
- set: (s) => a("update:modelValue", s)
77
- }), T = m(() => {
73
+ set: (l) => a("update:modelValue", l)
74
+ }), S = m(() => {
78
75
  if (!i.value || i.value.valid)
79
76
  return "";
80
- const s = j(i.value);
81
- if (e.errorMessage || s === "customError")
77
+ const l = j(i.value);
78
+ if (e.errorMessage || l === "customError")
82
79
  return e.errorMessage;
83
- if (!s)
80
+ if (!l)
84
81
  return "";
85
- if (s === "typeMismatch") {
82
+ if (l === "typeMismatch") {
86
83
  const o = Y.includes(e.type) ? e.type : "generic";
87
84
  return n.value(`validations.typeMismatch.${o}`, { value: c.value });
88
85
  }
89
- return n.value(`validations.${s}`, {
86
+ return n.value(`validations.${l}`, {
90
87
  value: c.value,
91
88
  n: c.value.toString().length,
92
89
  minLength: e.minLength,
@@ -95,37 +92,43 @@ const D = {
95
92
  max: e.max,
96
93
  step: e.step
97
94
  });
98
- }), V = (s) => {
99
- const o = s.target;
95
+ }), T = (l) => {
96
+ const o = l.target;
100
97
  a("change", o.value);
101
98
  };
102
- return b([c, u], () => {
103
- u.value && (i.value = u.value.validity);
104
- }), b(
99
+ return d([c, s], () => {
100
+ s.value && (i.value = s.value.validity);
101
+ }), d(
105
102
  i,
106
- (s) => {
107
- s && a("validityChange", s);
103
+ (l) => {
104
+ l && a("validityChange", l);
108
105
  },
109
106
  { deep: !0 }
110
- ), (s, o) => {
111
- var f, y;
112
- return x(), M("label", {
113
- class: I(["input", { "input--touched": l.value }])
107
+ ), d(
108
+ [e.errorMessage, s],
109
+ () => {
110
+ s.value && s.value.setCustomValidity(e.errorMessage || "");
111
+ },
112
+ { immediate: !0 }
113
+ ), (l, o) => {
114
+ var f, x;
115
+ return b(), M("label", {
116
+ class: L(["onyx-input", { "onyx-input--touched": u.value }])
114
117
  }, [
115
- d("span", {
116
- class: I(["input__label", { "input__label--required": e.required }])
118
+ g("span", {
119
+ class: L(["onyx-input__label", { "onyx-input__label--required": e.required }])
117
120
  }, v(e.label), 3),
118
- k(d("input", q(e, {
121
+ q(g("input", U(e, {
119
122
  ref_key: "inputElement",
120
- ref: u,
123
+ ref: s,
121
124
  "onUpdate:modelValue": o[0] || (o[0] = (_) => c.value = _),
122
- onChange: V,
123
- onBlur: o[1] || (o[1] = (_) => l.value = !0)
125
+ onChange: T,
126
+ onBlur: o[1] || (o[1] = (_) => u.value = !0)
124
127
  }), null, 16), [
125
- [U, c.value]
128
+ [k, c.value]
126
129
  ]),
127
- l.value && !((f = i.value) != null && f.valid) ? (x(), M("p", R, v(T.value), 1)) : w("", !0),
128
- d("p", A, 'Model value: "' + v(c.value) + '", is valid: ' + v((y = i.value) == null ? void 0 : y.valid), 1)
130
+ u.value && !((f = i.value) != null && f.valid) ? (b(), M("p", R, v(S.value), 1)) : w("", !0),
131
+ g("p", A, 'Model value: "' + v(c.value) + '", is valid: ' + v((x = i.value) == null ? void 0 : x.valid), 1)
129
132
  ], 2);
130
133
  };
131
134
  }
@@ -134,7 +137,7 @@ const D = {
134
137
  for (const [a, n] of r)
135
138
  e[a] = n;
136
139
  return e;
137
- }, H = /* @__PURE__ */ J(F, [["__scopeId", "data-v-5c77ef30"]]);
140
+ }, H = /* @__PURE__ */ J(F, [["__scopeId", "data-v-b84504d3"]]);
138
141
  export {
139
142
  H as TestInput,
140
143
  G as provideI18n