@ledgerhq/lumen-utils-shared 0.1.7 → 0.1.8

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/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export * from './lib/cn';
6
6
  export * from './lib/isTextChildren';
7
7
  export * from './lib/useMergeRef';
8
8
  export * from './lib/getObjectPath';
9
+ export * from './lib/resolveProps';
9
10
  export * from './lib/components';
10
11
  export * from './lib/throttle';
11
12
  export * from './lib/debounce';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,mCAAmC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,mCAAmC,CAAC"}
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { jsx as F } from "react/jsx-runtime";
2
- import { createContext as W, useRef as v, useContext as w, useMemo as C } from "react";
3
- import { clsx as B } from "clsx";
4
- import { twMerge as R } from "tailwind-merge";
1
+ import { jsx as v } from "react/jsx-runtime";
2
+ import { createContext as F, useRef as R, useContext as W, useMemo as C } from "react";
3
+ import { clsx as w } from "clsx";
4
+ import { twMerge as B } from "tailwind-merge";
5
5
  function et(t) {
6
6
  return t ? t.split(/[-_ ]+/).map((e) => e.charAt(0).toUpperCase() + e.slice(1).toLowerCase()).join("") : "";
7
7
  }
@@ -43,16 +43,16 @@ function H(t, e) {
43
43
  );
44
44
  }
45
45
  function U(t, e) {
46
- const r = W(e), n = ({ children: s, value: o }) => {
47
- const c = v(o);
48
- return H(c.current, o) || (c.current = o), /* @__PURE__ */ F(r.Provider, { value: c.current, children: s });
46
+ const r = F(e), n = ({ children: s, value: o }) => {
47
+ const c = R(o);
48
+ return H(c.current, o) || (c.current = o), /* @__PURE__ */ v(r.Provider, { value: c.current, children: s });
49
49
  };
50
50
  n.displayName = t + "Provider";
51
51
  function i({
52
52
  consumerName: s,
53
53
  contextRequired: o
54
54
  }) {
55
- const c = w(r);
55
+ const c = W(r);
56
56
  if (c)
57
57
  return c;
58
58
  if (o)
@@ -75,7 +75,7 @@ const [ot, Y] = U("Disabled", { disabled: !1 }), it = ({
75
75
  return !!(r?.disabled || n.disabled);
76
76
  };
77
77
  function st(...t) {
78
- return R(B(t));
78
+ return B(w(t));
79
79
  }
80
80
  const O = (t) => typeof t == "string" || typeof t == "number", ct = (t) => Array.isArray(t) ? t.every(O) : O(t);
81
81
  function S(t, e) {
@@ -110,7 +110,13 @@ const at = (t, e) => {
110
110
  r = r[n];
111
111
  }
112
112
  return r;
113
- }, ut = ({
113
+ };
114
+ function ut(t) {
115
+ return function(r, n) {
116
+ return t[r][n];
117
+ };
118
+ }
119
+ const ft = ({
114
120
  currentStep: t,
115
121
  totalSteps: e,
116
122
  size: r,
@@ -118,7 +124,7 @@ const at = (t, e) => {
118
124
  strokeWidth: i = 4,
119
125
  arcPercentage: s = 0.75
120
126
  }) => {
121
- const o = Math.min(Math.max(t, 0), e), c = n ?? `${o}/${e}`, a = e <= 0 ? 0 : o / e, d = (r - i) / 2, g = r / 2, p = r / 2, u = 2 * Math.PI * d, m = u * s, b = m * (1 - a), h = o <= 0, D = `${m} ${u}`, P = h ? m - 2 : b;
127
+ const o = Math.min(Math.max(t, 0), e), c = n ?? `${o}/${e}`, a = e <= 0 ? 0 : o / e, d = (r - i) / 2, g = r / 2, p = r / 2, u = 2 * Math.PI * d, m = u * s, P = m * (1 - a), h = o <= 0, D = `${m} ${u}`, b = h ? m - 2 : P;
122
128
  return {
123
129
  displayLabel: c,
124
130
  progress: a,
@@ -129,10 +135,10 @@ const at = (t, e) => {
129
135
  trackArcLength: m,
130
136
  trackDashArray: `${m} ${u}`,
131
137
  progressDashArray: D,
132
- progressDashOffset: P,
138
+ progressDashOffset: b,
133
139
  showMinimalDot: h
134
140
  };
135
- }, ft = (t) => C(
141
+ }, dt = (t) => C(
136
142
  () => ({
137
143
  integerPart: Array.from(t.integerPart, (e) => ({
138
144
  value: e,
@@ -144,7 +150,7 @@ const at = (t, e) => {
144
150
  })) : []
145
151
  }),
146
152
  [t.integerPart, t.decimalPart]
147
- ), dt = (t, e, r) => {
153
+ ), mt = (t, e, r) => {
148
154
  if (e) return r;
149
155
  const n = t.decimalPart ? `${t.decimalSeparator}${t.decimalPart}` : "", i = `${t.integerPart}${n}`;
150
156
  return t.currencyPosition === "end" ? `${i} ${t.currencyText}` : `${t.currencyText} ${i}`;
@@ -152,19 +158,19 @@ const at = (t, e) => {
152
158
  function J(t, e, r = {}) {
153
159
  const { leading: n = !1, trailing: i = !0, maxWait: s } = r;
154
160
  let o = null, c = null, a = null, d = 0, g = null, p = null, u;
155
- const m = s !== void 0, b = m ? Math.max(s, e) : 0, h = (l) => {
161
+ const m = s !== void 0, P = m ? Math.max(s, e) : 0, h = (l) => {
156
162
  d = l;
157
163
  const f = g, x = p;
158
164
  return g = null, p = null, u = t.apply(x, f), u;
159
165
  }, D = (l) => {
160
166
  const f = a ? l - a : 0;
161
167
  return e - f;
162
- }, P = (l) => {
168
+ }, b = (l) => {
163
169
  const f = a ? l - a : e, x = l - d;
164
- return a === null || f >= e || f < 0 || m && x >= b;
170
+ return a === null || f >= e || f < 0 || m && x >= P;
165
171
  }, $ = (l) => (o = null, i && g ? h(l) : (g = null, p = null, u)), y = () => {
166
172
  const l = Date.now();
167
- if (P(l)) {
173
+ if (b(l)) {
168
174
  $(l);
169
175
  return;
170
176
  }
@@ -172,10 +178,10 @@ function J(t, e, r = {}) {
172
178
  }, M = () => {
173
179
  const l = Date.now();
174
180
  c = null, g && (h(l), o !== null && (clearTimeout(o), o = setTimeout(y, e)));
175
- }, E = (l) => (d = l, o = setTimeout(y, e), m && (c = setTimeout(M, b)), n ? h(l) : u), L = () => {
181
+ }, E = (l) => (d = l, o = setTimeout(y, e), m && (c = setTimeout(M, P)), n ? h(l) : u), L = () => {
176
182
  o !== null && clearTimeout(o), c !== null && clearTimeout(c), d = 0, g = null, p = null, a = null, o = null, c = null;
177
183
  }, j = () => o === null && c === null ? u : $(Date.now()), k = () => o !== null || c !== null, A = function(...l) {
178
- const f = Date.now(), x = P(f);
184
+ const f = Date.now(), x = b(f);
179
185
  if (g = l, p = this, a = f, x) {
180
186
  if (o === null)
181
187
  return E(f);
@@ -186,7 +192,7 @@ function J(t, e, r = {}) {
186
192
  };
187
193
  return A.cancel = L, A.flush = j, A.pending = k, A;
188
194
  }
189
- function mt(t, e, r = {}) {
195
+ function gt(t, e, r = {}) {
190
196
  const { leading: n = !0, trailing: i = !0 } = r;
191
197
  return J(t, e, {
192
198
  leading: n,
@@ -194,7 +200,7 @@ function mt(t, e, r = {}) {
194
200
  maxWait: e
195
201
  });
196
202
  }
197
- const gt = ({
203
+ const pt = ({
198
204
  onClick: t,
199
205
  disabled: e
200
206
  }) => t ? e ? {
@@ -208,7 +214,7 @@ const gt = ({
208
214
  (n.key === "Enter" || n.key === " ") && (n.preventDefault(), t?.(n));
209
215
  },
210
216
  onClick: t
211
- } : void 0, I = " ", pt = ({
217
+ } : void 0, I = " ", ht = ({
212
218
  label: t,
213
219
  placeholder: e
214
220
  }) => {
@@ -224,23 +230,24 @@ const gt = ({
224
230
  export {
225
231
  ot as DisabledProvider,
226
232
  S as assignRef,
227
- dt as buildAriaLabel,
233
+ mt as buildAriaLabel,
228
234
  st as cn,
235
+ ut as createPropsResolver,
229
236
  U as createSafeContext,
230
237
  J as debounce,
231
238
  z as formatThousands,
232
- gt as getButtonA11yProps,
239
+ pt as getButtonA11yProps,
233
240
  nt as getFontSize,
234
241
  at as getObjectPath,
235
- ut as getStepperCalculations,
242
+ ft as getStepperCalculations,
236
243
  ct as isTextChildren,
237
244
  G as mergeRefs,
238
- pt as resolveBaseInputPlaceholder,
245
+ ht as resolveBaseInputPlaceholder,
239
246
  H as shallowEqual,
240
247
  rt as textFormatter,
241
- mt as throttle,
248
+ gt as throttle,
242
249
  et as toPascalCase,
243
250
  it as useDisabledContext,
244
251
  lt as useMergedRef,
245
- ft as useSplitText
252
+ dt as useSplitText
246
253
  };
@@ -0,0 +1,2 @@
1
+ export * from './resolveProps';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/resolveProps/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export type PropsMap<Variant extends string, Props> = Record<Variant, Props>;
2
+ export type ContextPropsMap = Record<string, PropsMap<string, unknown>>;
3
+ export declare function createPropsResolver<T extends ContextPropsMap>(config: T): <Context extends keyof T, Variant extends keyof T[Context]>(context: Context, variant: Variant) => T[Context][Variant];
4
+ //# sourceMappingURL=resolveProps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveProps.d.ts","sourceRoot":"","sources":["../../../src/lib/resolveProps/resolveProps.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,CAAC,OAAO,SAAS,MAAM,EAAE,KAAK,IAAI,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AAC7E,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAExE,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,eAAe,EAAE,MAAM,EAAE,CAAC,IAEpE,OAAO,SAAS,MAAM,CAAC,EACvB,OAAO,SAAS,MAAM,CAAC,CAAC,OAAO,CAAC,EAChC,SAAS,OAAO,EAAE,SAAS,OAAO,yBAGrC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ledgerhq/lumen-utils-shared",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
package/src/index.ts CHANGED
@@ -6,6 +6,7 @@ export * from './lib/cn';
6
6
  export * from './lib/isTextChildren';
7
7
  export * from './lib/useMergeRef';
8
8
  export * from './lib/getObjectPath';
9
+ export * from './lib/resolveProps';
9
10
  export * from './lib/components';
10
11
  export * from './lib/throttle';
11
12
  export * from './lib/debounce';
@@ -0,0 +1 @@
1
+ export * from './resolveProps';
@@ -0,0 +1,22 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { createPropsResolver } from './resolveProps';
3
+
4
+ describe('createPropsResolver', () => {
5
+ const resolveProps = createPropsResolver({
6
+ avatar: {
7
+ sm: { size: 'lg', appearance: 'red' },
8
+ md: { size: 'xl', appearance: 'red' },
9
+ },
10
+ });
11
+
12
+ it('resolves the config for a given context and size', () => {
13
+ expect(resolveProps('avatar', 'sm')).toEqual({
14
+ size: 'lg',
15
+ appearance: 'red',
16
+ });
17
+ expect(resolveProps('avatar', 'md')).toEqual({
18
+ size: 'xl',
19
+ appearance: 'red',
20
+ });
21
+ });
22
+ });
@@ -0,0 +1,11 @@
1
+ export type PropsMap<Variant extends string, Props> = Record<Variant, Props>;
2
+ export type ContextPropsMap = Record<string, PropsMap<string, unknown>>;
3
+
4
+ export function createPropsResolver<T extends ContextPropsMap>(config: T) {
5
+ return function resolveProps<
6
+ Context extends keyof T,
7
+ Variant extends keyof T[Context],
8
+ >(context: Context, variant: Variant) {
9
+ return config[context][variant];
10
+ };
11
+ }