@loadsmart/loadsmart-ui 8.0.6 → 8.0.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/tools.js ADDED
@@ -0,0 +1,98 @@
1
+ import { get_default } from "./themes.js";
2
+ import { getToken } from "./theming/index.js";
3
+ import { toArray } from "./toArray.js";
4
+ import { isFunction } from "@loadsmart/utils-function";
5
+ import { isObject } from "@loadsmart/utils-object";
6
+ //#region src/tools/conditional.ts
7
+ /**
8
+ * Utility to generate style/class name conditions based on a components props.
9
+ * Expected prop values can be a single value, an array of values or a function/callback.
10
+ * @example
11
+ * ```jsx
12
+ * whenProps({
13
+ * 'prop-a': true, // checks `props['prop-a']` === true`
14
+ * 'prop-b': [1, 2], // checks `toArray([1, 2]).includes(props['prop-b'])`
15
+ * 'prop-c': (value) => value + 1 // checks `Boolean(callback(props['prop-c']))`
16
+ * 'prop-d': Boolean // checks `Boolean(Boolean(props['prop-d']))`
17
+ * })
18
+ * ```
19
+ * @param conditions
20
+ * @returns Returns function that consumes component props.
21
+ */
22
+ function whenProps(conditions) {
23
+ return function(props) {
24
+ return toArray(conditions).some((condition) => {
25
+ return Object.keys(condition).every((key) => {
26
+ const propValue = get_default(props, key);
27
+ const conditionValue = condition[key];
28
+ if (Array.isArray(conditionValue)) return toArray(conditionValue).includes(propValue);
29
+ if (isFunction(conditionValue)) return Boolean(conditionValue(propValue));
30
+ return conditionValue === propValue;
31
+ });
32
+ });
33
+ };
34
+ }
35
+ function handleConditionObject(condition, props) {
36
+ return Object.keys(condition).reduce((acc, key) => {
37
+ let value = condition[key];
38
+ if (isFunction(value)) value = value(props);
39
+ if (value) {
40
+ const result = getToken(key, props) ?? key;
41
+ return [...acc, result];
42
+ }
43
+ return acc;
44
+ }, []).join(" ");
45
+ }
46
+ /**
47
+ * Concatenate style properties or class names conditionally.
48
+ * Conditions can be functions that consume components props,
49
+ * objects, strings, or numbers (that will be coerced to strings).
50
+ * @example
51
+ * ```jsx
52
+ * conditional(1, 'some-class', {
53
+ * 'class-a': true,
54
+ * 'class-b': (props) => props.showClassB,
55
+ * }, (props) => props.className)
56
+ * ```
57
+ * @param conditions
58
+ * @returns Returns function that consumes component props.
59
+ */
60
+ function conditional(...conditions) {
61
+ return function(props) {
62
+ let classes = [];
63
+ for (let i = 0; i < conditions.length; i++) {
64
+ const condition = conditions[i];
65
+ if (isFunction(condition)) classes.push(condition(props));
66
+ else if (isObject(condition)) classes = classes.concat(handleConditionObject(condition, props));
67
+ else if (condition) classes.push(String(condition));
68
+ }
69
+ return classes.join(" ");
70
+ };
71
+ }
72
+ //#endregion
73
+ //#region src/tools/prop.ts
74
+ function compare(...args) {
75
+ const [value, defaultValue] = args;
76
+ if (value == null || value === false || Number.isNaN(value)) return defaultValue || value;
77
+ if (typeof value === "string" && value.length === 0) return defaultValue || value;
78
+ return value;
79
+ }
80
+ /**
81
+ * Retrieve the key value from the props object
82
+ * @example
83
+ * ```jsx
84
+ * -transform: scaleY(${(props) => props.$height || 1});
85
+ * +transform: scaleY(${prop('$height', 1)});
86
+ * ```
87
+ * @param name a valid property name from the object
88
+ * @param defaultValue a fallback value in case the property value is invalid
89
+ * @param comparatorFn a function to be used to decide between value or defaultValue
90
+ * @returns Returns function that consumes component props.
91
+ */
92
+ function prop(name, defaultValue, comparatorFn = compare) {
93
+ return (props) => comparatorFn(props[name], defaultValue);
94
+ }
95
+ //#endregion
96
+ export { conditional, prop, whenProps };
97
+
98
+ //# sourceMappingURL=tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.js","names":["isObject","isFunction","F","getToken","ThemeToken","ThemedProps","get","toArray","WhenProps","K","value","When","P","Key","whenProps","conditions","Narrow","props","safeConditions","some","condition","keys","Object","every","key","propValue","conditionValue","Array","isArray","includes","Boolean","ConditionObject","Record","handleConditionObject","res","reduce","acc","tokenKey","result","join","Condition","conditional","classes","i","length","push","concat","String","compare","args","value","defaultValue","Number","isNaN","length","prop","P","name","K","NonNullable","comparatorFn","props"],"sources":["../src/tools/conditional.ts","../src/tools/prop.ts"],"sourcesContent":["import { isObject } from '@loadsmart/utils-object'\nimport { isFunction } from '@loadsmart/utils-function'\nimport type { F } from 'ts-toolbelt'\n\nimport { getToken } from 'theming'\nimport type { ThemeToken, ThemedProps } from 'theming'\nimport get from 'utils/toolset/get'\nimport toArray from 'utils/toolset/toArray'\n\ntype WhenProps<K> = K | undefined | ((value: K) => boolean | undefined)\n\nexport type When<P> = {\n [Key in keyof P]?: WhenProps<P[Key]> | WhenProps<P[Key]>[] | undefined\n}\n\n/**\n * Utility to generate style/class name conditions based on a components props.\n * Expected prop values can be a single value, an array of values or a function/callback.\n * @example\n * ```jsx\n * whenProps({\n * 'prop-a': true, // checks `props['prop-a']` === true`\n * 'prop-b': [1, 2], // checks `toArray([1, 2]).includes(props['prop-b'])`\n * 'prop-c': (value) => value + 1 // checks `Boolean(callback(props['prop-c']))`\n * 'prop-d': Boolean // checks `Boolean(Boolean(props['prop-d']))`\n * })\n * ```\n * @param conditions\n * @returns Returns function that consumes component props.\n */\nexport function whenProps<P>(conditions: When<F.Narrow<P>> | When<F.Narrow<P>>[]) {\n return function (props: P): boolean {\n const safeConditions = toArray(conditions)\n\n return safeConditions.some((condition) => {\n const keys = Object.keys(condition)\n\n return keys.every((key) => {\n const propValue = get(props, key) as P[keyof P]\n const conditionValue = condition[key as keyof typeof condition]\n\n if (Array.isArray(conditionValue)) {\n return toArray(conditionValue).includes(propValue)\n }\n if (isFunction(conditionValue)) {\n return Boolean(conditionValue(propValue))\n }\n return (conditionValue as unknown) === propValue\n })\n })\n }\n}\n\ntype ConditionObject<P> = Record<\n string,\n string | number | boolean | ((props: P) => boolean) | undefined\n>\n\nfunction handleConditionObject<P>(condition: ConditionObject<P>, props: P): string {\n const keys = Object.keys(condition)\n\n const res = keys.reduce<string[]>((acc, key) => {\n let value = condition[key]\n\n if (isFunction(value)) {\n value = value(props)\n }\n\n if (value) {\n const tokenKey = key as ThemeToken\n\n const result = (getToken(tokenKey, props as unknown as ThemedProps) ?? key) as string\n return [...acc, result]\n }\n\n return acc\n }, [])\n\n return res.join(' ')\n}\n\ntype Condition<P> = number | string | ConditionObject<P> | ((props: P) => string)\n\n/**\n * Concatenate style properties or class names conditionally.\n * Conditions can be functions that consume components props,\n * objects, strings, or numbers (that will be coerced to strings).\n * @example\n * ```jsx\n * conditional(1, 'some-class', {\n * 'class-a': true,\n * 'class-b': (props) => props.showClassB,\n * }, (props) => props.className)\n * ```\n * @param conditions\n * @returns Returns function that consumes component props.\n */\nfunction conditional<P>(...conditions: Condition<P>[]) {\n return function (props: P): string {\n let classes: string[] = []\n\n for (let i = 0; i < conditions.length; i++) {\n const condition = conditions[i]\n\n if (isFunction(condition)) {\n classes.push(condition(props))\n } else if (isObject(condition)) {\n classes = classes.concat(handleConditionObject(condition, props))\n } else if (condition) {\n classes.push(String(condition))\n }\n }\n\n return classes.join(' ')\n }\n}\n\nexport default conditional\n","function compare(...args: any[]): unknown {\n const [value, defaultValue] = args\n\n if (value == null || value === false || Number.isNaN(value)) {\n return defaultValue || value\n }\n\n if (typeof value === 'string' && value.length === 0) {\n return defaultValue || value\n }\n\n return value\n}\n\n/**\n * Retrieve the key value from the props object\n * @example\n * ```jsx\n * -transform: scaleY(${(props) => props.$height || 1});\n * +transform: scaleY(${prop('$height', 1)});\n * ```\n * @param name a valid property name from the object\n * @param defaultValue a fallback value in case the property value is invalid\n * @param comparatorFn a function to be used to decide between value or defaultValue\n * @returns Returns function that consumes component props.\n */\nfunction prop<P, K extends keyof P = keyof P>(\n name: K,\n defaultValue?: NonNullable<P[K]>,\n comparatorFn = compare\n) {\n return (props: P): P[K] => comparatorFn(props[name], defaultValue) as P[K]\n}\n\nexport default prop\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA8BA,SAAgBc,UAAaC,YAAqD;AAChF,QAAO,SAAUE,OAAmB;AAGlC,SAFuBV,QAAQQ,WAAW,CAEpBI,MAAMC,cAAc;AAGxC,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OC,MAAMH,MAAM,CACzD,QAAOC,gBAAgBD;AAGzB,KAAI,OAAOA,UAAU,YAAYA,MAAMI,WAAW,EAChD,QAAOH,gBAAgBD;AAGzB,QAAOA;;;;;;;;;;;;;;AAeT,SAASK,KACPE,MACAN,cACAS,eAAeZ,SACf;AACA,SAAQa,UAAmBD,aAAaC,MAAMJ,OAAON,aAAa"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loadsmart/loadsmart-ui",
3
- "version": "8.0.6",
3
+ "version": "8.0.8",
4
4
  "description": "Miranda UI, a React UI library",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -39,7 +39,8 @@
39
39
  "devDependencies": {
40
40
  "@commitlint/cli": "^20.5.0",
41
41
  "@commitlint/config-conventional": "^20.5.0",
42
- "@loadsmart/miranda-tokens": "^4.26.0",
42
+ "@loadsmart/miranda-tokens": "^4.26.1",
43
+ "@rolldown/plugin-babel": "^0.2.2",
43
44
  "@storybook/addon-a11y": "^10.3.3",
44
45
  "@storybook/addon-docs": "^10.3.3",
45
46
  "@storybook/addon-links": "^10.3.3",
@@ -58,7 +59,7 @@
58
59
  "@types/react": "^18.3.28",
59
60
  "@types/react-dom": "^18.3.7",
60
61
  "@types/styled-components": "^5.1.36",
61
- "@vitejs/plugin-react": "^5.2.0",
62
+ "@vitejs/plugin-react": "^6.0.1",
62
63
  "babel-plugin-styled-components": "^2.1.4",
63
64
  "chance": "^1.1.13",
64
65
  "commitizen": "^4.3.1",
@@ -74,7 +75,7 @@
74
75
  "eslint-plugin-react-hooks": "^7.0.1",
75
76
  "eslint-plugin-storybook": "^10.3.3",
76
77
  "eslint-plugin-testing-library": "^7.16.2",
77
- "eslint-plugin-unicorn": "^63.0.0",
78
+ "eslint-plugin-unicorn": "^64.0.0",
78
79
  "gh-pages": "^6.3.0",
79
80
  "husky": "^9.1.7",
80
81
  "jest": "^30.3.0",
@@ -96,9 +97,9 @@
96
97
  "ts-toolbelt": "^9.6.0",
97
98
  "typescript": "^6.0.2",
98
99
  "typescript-eslint": "^8.57.2",
99
- "vite": "^7.3.1",
100
+ "vite": "^8.0.3",
100
101
  "vite-plugin-dts": "^4.5.4",
101
- "vite-plugin-svgr": "^4.5.0"
102
+ "vite-plugin-svgr": "^5.0.0"
102
103
  },
103
104
  "peerDependencies": {
104
105
  "@loadsmart/miranda-tokens": ">=1.3.0",
@@ -1,33 +0,0 @@
1
- import React__default, { createContext, useCallback, useMemo, useContext } from "react";
2
- const DragDropFileContext = createContext(void 0);
3
- const DragDropFileProvider = ({
4
- fileList,
5
- onFilesAdded,
6
- onFileRemoved,
7
- onRetryUpload,
8
- children
9
- }) => {
10
- const onRemoveFile = useCallback((removedItem, index) => {
11
- onFileRemoved([...fileList.slice(0, index), ...fileList.slice(index + 1)], removedItem, index);
12
- }, [fileList]);
13
- const contextValue = useMemo(() => ({
14
- fileList,
15
- onFilesAdded,
16
- onRemoveFile,
17
- onRetryUpload
18
- }), [fileList, onFilesAdded, onRemoveFile, onRetryUpload]);
19
- return /* @__PURE__ */ React__default.createElement(DragDropFileContext.Provider, { value: contextValue }, children);
20
- };
21
- const useDragDropFileContext = () => {
22
- const context = useContext(DragDropFileContext);
23
- if (!context) {
24
- throw new Error("useDragDropFileContext must be used within an DragDropFileProvider");
25
- }
26
- return context;
27
- };
28
- export {
29
- DragDropFileContext as D,
30
- DragDropFileProvider as a,
31
- useDragDropFileContext as u
32
- };
33
- //# sourceMappingURL=DragDropFile.context-oKnUu6d3.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DragDropFile.context-oKnUu6d3.js","sources":["../src/components/DragDropFile/DragDropFile.context.tsx"],"sourcesContent":["import React, { createContext, useContext, useCallback, useMemo } from 'react'\n\nimport type { DragDropFileContextValue, DragDropFileProviderProps, FileWithStatus } from './types'\n\nexport const DragDropFileContext = createContext<DragDropFileContextValue | undefined>(undefined)\n\nexport const DragDropFileProvider = ({\n fileList,\n onFilesAdded,\n onFileRemoved,\n onRetryUpload,\n children,\n}: DragDropFileProviderProps) => {\n const onRemoveFile = useCallback(\n (removedItem: FileWithStatus, index: number) => {\n onFileRemoved([...fileList.slice(0, index), ...fileList.slice(index + 1)], removedItem, index)\n },\n [fileList]\n )\n\n const contextValue = useMemo(\n () => ({ fileList, onFilesAdded, onRemoveFile, onRetryUpload }),\n [fileList, onFilesAdded, onRemoveFile, onRetryUpload]\n )\n\n return (\n <DragDropFileContext.Provider value={contextValue}>{children}</DragDropFileContext.Provider>\n )\n}\n\nexport const useDragDropFileContext = (): DragDropFileContextValue => {\n const context = useContext(DragDropFileContext)\n\n if (!context) {\n throw new Error('useDragDropFileContext must be used within an DragDropFileProvider')\n }\n\n return context\n}\n"],"names":["DragDropFileContext","createContext","undefined","DragDropFileProvider","fileList","onFilesAdded","onFileRemoved","onRetryUpload","children","onRemoveFile","useCallback","removedItem","index","slice","contextValue","useMemo","useDragDropFileContext","context","useContext","Error"],"mappings":";AAIO,MAAMA,sBAAsBC,cAAoDC,MAAS;AAEzF,MAAMC,uBAAuBA,CAAC;AAAA,EACnCC;AAAAA,EACAC;AAAAA,EACAC;AAAAA,EACAC;AAAAA,EACAC;AACyB,MAAM;AAC/B,QAAMC,eAAeC,YACnB,CAACC,aAA6BC,UAAkB;AAC9CN,kBAAc,CAAC,GAAGF,SAASS,MAAM,GAAGD,KAAK,GAAG,GAAGR,SAASS,MAAMD,QAAQ,CAAC,CAAC,GAAGD,aAAaC,KAAK;AAAA,EAC/F,GACA,CAACR,QAAQ,CACX;AAEA,QAAMU,eAAeC,QACnB,OAAO;AAAA,IAAEX;AAAAA,IAAUC;AAAAA,IAAcI;AAAAA,IAAcF;AAAAA,EAAAA,IAC/C,CAACH,UAAUC,cAAcI,cAAcF,aAAa,CACtD;AAEA,sDACG,oBAAoB,UAApB,EAA6B,OAAOO,gBAAeN,QAAS;AAEjE;AAEO,MAAMQ,yBAAyBA,MAAgC;AACpE,QAAMC,UAAUC,WAAWlB,mBAAmB;AAE9C,MAAI,CAACiB,SAAS;AACZ,UAAM,IAAIE,MAAM,oEAAoE;AAAA,EACtF;AAEA,SAAOF;AACT;"}