@loadsmart/loadsmart-ui 6.4.0 → 7.0.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/components/Table/Table.d.ts +4 -12
- package/dist/components/Table/Table.types.d.ts +0 -4
- package/dist/index.js +71 -96
- package/dist/index.js.map +1 -1
- package/dist/{miranda-compatibility.theme-22a9ce26.js → miranda-compatibility.theme-bb671a80.js} +2 -2
- package/dist/{miranda-compatibility.theme-22a9ce26.js.map → miranda-compatibility.theme-bb671a80.js.map} +1 -1
- package/dist/prop-e569d46a.js +2 -0
- package/dist/{prop-201ffe28.js.map → prop-e569d46a.js.map} +1 -1
- package/dist/testing/index.js +1 -1
- package/dist/theming/index.js +1 -1
- package/dist/tools/index.js +1 -1
- package/package.json +1 -1
- package/src/components/Table/Table.stories.tsx +27 -27
- package/src/components/Table/Table.test.tsx +10 -10
- package/src/components/Table/Table.tsx +35 -90
- package/src/components/Table/Table.types.ts +0 -5
- package/src/theming/themes/miranda-compatibility.theme.ts +1 -1
- package/dist/prop-201ffe28.js +0 -2
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var t=require("./toArray-b56541b4.js"),n=require("./miranda-compatibility.theme-bb671a80.js"),r=require("./theming/index.js");function e(t,e){return Object.keys(t||{}).reduce(((o,i)=>{var u;let s=t[i];if(n.isFunction(s)&&(s=s(e)),s){const t=i,n=null!==(u=r.getToken(t,e))&&void 0!==u?u:i;return[...o,n]}return o}),[]).join(" ")}function o(...t){const[n,r]=t;return null==n||!1===n||Number.isNaN(n)?r||n:"string"==typeof n&&0===n.length&&r||n}exports.conditional=function(...r){return function(o){let i=[];for(let u=0;u<r.length;u++){const s=r[u];n.isFunction(s)?i.push(s(o)):t.isObject(s)?i=i.concat(e(s,o)):s&&i.push(String(s))}return i.join(" ")}},exports.prop=function(t,n,r=o){return e=>r(e[t],n)},exports.whenProps=function(r){return function(e){const o=t.toArray(r);let i=!1;for(let r=0;r<o.length;r++){const u=o[r],s=Object.keys(u);let c=!0;for(let r=0;r<s.length&&c;r++){const o=s[r],i=n.lodash_get(e,o),l=u[o];c=Array.isArray(l)?c&&t.toArray(l).includes(i):n.isFunction(l)?c&&Boolean(l(i)):c&&l===i}i=i||c}return i}};
|
|
2
|
+
//# sourceMappingURL=prop-e569d46a.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prop-
|
|
1
|
+
{"version":3,"file":"prop-e569d46a.js","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 {...Object} conditions\n * @returns {(props: Object}) => boolean} 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 let res = false\n\n for (let i = 0; i < safeConditions.length; i++) {\n const condition = safeConditions[i]\n const keys = Object.keys(condition)\n\n let temp = true\n\n for (let j = 0; j < keys.length && temp; j++) {\n const key = keys[j]\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 temp = temp && toArray(conditionValue).includes(propValue)\n } else if (isFunction(conditionValue)) {\n temp = temp && Boolean(conditionValue(propValue))\n } else {\n temp = temp && (conditionValue as unknown) === propValue\n }\n }\n\n res = res || temp\n }\n\n return res\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((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 const result = (getToken(tokenKey, props as unknown as ThemedProps) ?? key) as string\n return [...acc, result]\n }\n\n return acc\n }, [] as string[])\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 {(props: ThemedProps) => string} 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<P>(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 // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\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 {(props: ThemedProps) => string} 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"],"names":["handleConditionObject","condition","props","Object","keys","reduce","acc","key","value","isFunction","tokenKey","result","_a","getToken","join","compare","args","defaultValue","Number","isNaN","length","conditions","classes","i","push","isObject","concat","String","name","comparatorFn","safeConditions","toArray","res","temp","j","propValue","get","conditionValue","Array","isArray","includes","Boolean"],"mappings":"2IAoEA,SAASA,EAAyBC,EAA+BC,GAmB/D,OAlBaC,OAAOC,KAAKH,GAAa,CAAE,GAEvBI,QAAO,CAACC,EAAKC,WAC5B,IAAIC,EAAQP,EAAUM,GAMtB,GAJIE,EAAAA,WAAWD,KACbA,EAAQA,EAAMN,IAGZM,EAAO,CACT,MAAME,EAAWH,EACXI,EAAiE,QAAvDC,EAAAC,EAAQA,SAACH,EAAUR,UAAoC,IAAAU,EAAAA,EAAAL,EACvE,MAAO,IAAID,EAAKK,EACjB,CAED,OAAOL,CAAG,GACT,IAEQQ,KAAK,IAClB,CCxFA,SAASC,KAAWC,GAElB,MAAOR,EAAOS,GAAgBD,EAE9B,OAAa,MAATR,IAA2B,IAAVA,GAAmBU,OAAOC,MAAMX,GAC5CS,GAAgBT,EAGJ,iBAAVA,GAAuC,IAAjBA,EAAMY,QAC9BH,GAGFT,CACT,qBD6FA,YAA2Ba,GACzB,OAAO,SAAUnB,GACf,IAAIoB,EAAoB,GAExB,IAAK,IAAIC,EAAI,EAAGA,EAAIF,EAAWD,OAAQG,IAAK,CAC1C,MAAMtB,EAAYoB,EAAWE,GAEzBd,EAAAA,WAAWR,GACbqB,EAAQE,KAAKvB,EAAUC,IACduB,EAAAA,SAASxB,GAClBqB,EAAUA,EAAQI,OAAO1B,EAAyBC,EAAWC,IACpDD,GACTqB,EAAQE,KAAKG,OAAO1B,GAEvB,CAED,OAAOqB,EAAQR,KAAK,IACtB,CACF,eCjGA,SACEc,EACAX,EACAY,EAAed,GAEf,OAAQb,GAAmB2B,EAAa3B,EAAM0B,GAAOX,EACvD,oBDHM,SAAuBI,GAC3B,OAAO,SAAUnB,GACf,MAAM4B,EAAiBC,UAAQV,GAE/B,IAAIW,GAAM,EAEV,IAAK,IAAIT,EAAI,EAAGA,EAAIO,EAAeV,OAAQG,IAAK,CAC9C,MAAMtB,EAAY6B,EAAeP,GAC3BnB,EAAOD,OAAOC,KAAKH,GAEzB,IAAIgC,GAAO,EAEX,IAAK,IAAIC,EAAI,EAAGA,EAAI9B,EAAKgB,QAAUa,EAAMC,IAAK,CAC5C,MAAM3B,EAAMH,EAAK8B,GACXC,EAAYC,EAAAA,WAAIlC,EAAOK,GACvB8B,EAAiBpC,EAAUM,GAG/B0B,EADEK,MAAMC,QAAQF,GACTJ,GAAQF,EAAOA,QAACM,GAAgBG,SAASL,GACvC1B,EAAAA,WAAW4B,GACbJ,GAAQQ,QAAQJ,EAAeF,IAE/BF,GAASI,IAA+BF,CAElD,CAEDH,EAAMA,GAAOC,CACd,CAED,OAAOD,CACT,CACF"}
|
package/dist/testing/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../DragDropFile.context-bbb7d631.js"),t=require("@testing-library/react"),i=require("../toArray-b56541b4.js"),n=require("../miranda-compatibility.theme-
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../DragDropFile.context-bbb7d631.js"),t=require("@testing-library/react"),i=require("../toArray-b56541b4.js"),n=require("../miranda-compatibility.theme-bb671a80.js"),r=require("react");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("@loadsmart/miranda-tokens");var c=o(r);function a(e){return e.parentNode.parentNode.parentNode.parentNode}function d(i){return e.__awaiter(this,void 0,void 0,(function*(){const n=a(i);t.queries.queryByRole(n,"menu")||(yield t.act((()=>e.__awaiter(this,void 0,void 0,(function*(){t.fireEvent.click(i),expect(yield t.queries.findByRole(n,"menu")).toBeInTheDocument()})))))}))}function u(i){return e.__awaiter(this,void 0,void 0,(function*(){const n=a(i);t.queries.queryByRole(n,"menu")&&(yield t.act((()=>e.__awaiter(this,void 0,void 0,(function*(){t.fireEvent.click(t.queries.getByText(n,"Close")),yield t.waitForElementToBeRemoved((()=>t.queries.queryByRole(n,"menu")))})))))}))}const l={getContainer:a,expand:d,collapse:u,pick:function(i,n){return e.__awaiter(this,void 0,void 0,(function*(){const r=a(n);yield d(n),yield t.act((()=>e.__awaiter(this,void 0,void 0,(function*(){n.focus();const e=t.queries.getByLabelText(r,i);e&&"false"==e.getAttribute("aria-checked")&&t.fireEvent.click(e)})))),yield u(n)}))},clear:function(i){return e.__awaiter(this,void 0,void 0,(function*(){const n=a(i);yield t.act((()=>e.__awaiter(this,void 0,void 0,(function*(){const e=t.queries.getByLabelText(n,"Clear selection");t.fireEvent.click(e)})))),yield u(i)}))},getSelectedDates:function(i){return e.__awaiter(this,void 0,void 0,(function*(){const e=a(i);yield d(i);const n=t.queries.queryAllByRole(e,"checkbox",{checked:!0});return yield u(i),n}))}};function s(t){return e.__awaiter(this,void 0,void 0,(function*(){yield l.expand(t)}))}function f(t){return e.__awaiter(this,void 0,void 0,(function*(){yield l.collapse(t)}))}const v={getContainer:l.getContainer,expand:s,collapse:f,pick:function(i,n){return e.__awaiter(this,void 0,void 0,(function*(){const e=l.getContainer(n);yield s(n);const[r,o]=i;if(null!=r){const i=t.queries.getByTestId(e,"input-date-range-start");yield l.pick(r,i)}if(null!=o){const i=t.queries.getByTestId(e,"input-date-range-end");yield l.pick(o,i)}yield f(n)}))},clear:function(t){return e.__awaiter(this,void 0,void 0,(function*(){yield l.clear(t)}))},getSelectedDates:function(t){return e.__awaiter(this,void 0,void 0,(function*(){return l.getSelectedDates(t)}))}},y=e=>e.parentNode,p={dragOver:e=>{const i=y(e),n=t.createEvent.dragOver(i);t.fireEvent(i,n)},dragLeave:e=>{const i=y(e),n=t.createEvent.dragLeave(i);t.fireEvent(i,n)},dropFiles:(e,n)=>{const r=y(e),o=t.createEvent.drop(r);Object.defineProperty(o,"dataTransfer",{value:{files:i.toArray(n)}}),t.fireEvent(r,o)}};function _(e){return e.parentNode.parentNode.parentNode}function h(e){return e.parentNode.parentNode.nextSibling}function g(e){return e.parentNode.nextSibling.nextSibling}function w(e){return e.parentNode}function b(e){return 3===_(e).children.length}function x(i){return e.__awaiter(this,void 0,void 0,(function*(){const e=w(i);t.within(e).queryByTestId("select-trigger-loading")&&(yield t.waitForElementToBeRemoved((()=>t.within(e).queryByTestId("select-trigger-loading")),{timeout:2500}))}))}function E(i){return e.__awaiter(this,void 0,void 0,(function*(){if(yield x(i),b(i))return;const n=g(i);yield t.waitFor((()=>{expect(n).toBeEnabled()})),t.act((()=>{i.dispatchEvent(new MouseEvent("click",{bubbles:!0}))})),yield t.waitFor((()=>e.__awaiter(this,void 0,void 0,(function*(){expect(yield t.within(_(i)).findByRole("listbox")).toBeInTheDocument()}))))}))}function B(i){return e.__awaiter(this,void 0,void 0,(function*(){if(!b(i))return;const e=g(i);t.fireEvent.click(e),yield t.waitFor((()=>{expect(t.within(_(i)).queryByRole("listbox")).not.toBeInTheDocument()}))}))}const q={select:function(i,n){return e.__awaiter(this,void 0,void 0,(function*(){yield E(n);const e=h(n),r=yield t.within(e).findByLabelText(i);r&&"false"==r.getAttribute("aria-selected")&&(t.fireEvent.mouseDown(r),t.act((()=>{r.focus()})),t.fireEvent.mouseUp(r),t.fireEvent.click(r)),yield B(n)}))},unselect:function(i,n){return e.__awaiter(this,void 0,void 0,(function*(){yield E(n);const e=h(n),r=yield t.within(e).findByLabelText(i);r&&"true"===r.getAttribute("aria-selected")&&t.fireEvent.click(r),yield B(n)}))},clear:function(i){return e.__awaiter(this,void 0,void 0,(function*(){yield x(i);const e=w(i),n=t.within(e).getByTestId("select-trigger-clear");n&&t.fireEvent.click(n)}))},search:function(i,n){return e.__awaiter(this,void 0,void 0,(function*(){t.fireEvent.change(n,{target:{value:i}}),yield x(n);const e=h(n);yield t.within(e).findAllByRole("option")}))},expand:E,collapse:B,getOptions:function(i){return e.__awaiter(this,void 0,void 0,(function*(){yield E(i);const e=h(i),n=t.within(e).queryAllByRole("option");return yield B(i),n}))},getSelectedOptions:function(i){return e.__awaiter(this,void 0,void 0,(function*(){yield E(i);const e=h(i);let n=[];try{n=yield t.within(e).findAllByRole("option",{selected:!0})}catch(e){n=[]}return yield B(i),n}))},isMenuExpanded:b};const m={fileList:[],onFilesAdded:jest.fn(),onRetryUpload:jest.fn(),onRemoveFile:jest.fn()};exports.DatePickerEvent=l,exports.DateRangePickerEvent=v,exports.DragDropFileEvent=p,exports.SelectEvent=q,exports.getInterpolatedStyles=function(e){return i.toArray(e).map((e=>{for(;n.isFunction(e);)e=e({theme:n.alice});return e})).join("")},exports.renderWithDragDropFileProvider=(i,n)=>{const r=Object.assign(Object.assign({},m),n);return t.render((o=i,c.default.createElement(e.DragDropFileContext.Provider,{value:r},o)));var o};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/theming/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../miranda-compatibility.theme-
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../miranda-compatibility.theme-bb671a80.js");require("@loadsmart/miranda-tokens");var t=Object.freeze({__proto__:null,Alice:e.alice,Loadsmart:e.loadsmart,Miranda:e.mirandaCompatibility});function r(t,r){const a=e.isFunction(t)?t(r):t;return r.theme[a]}exports.Themes=t,exports.getToken=function(e,t){return void 0===t?t=>r(e,t):r(e,t)};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/tools/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../prop-
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../prop-e569d46a.js");require("../toArray-b56541b4.js"),require("../miranda-compatibility.theme-bb671a80.js"),require("@loadsmart/miranda-tokens"),require("../theming/index.js"),exports.conditional=e.conditional,exports.prop=e.prop,exports.whenProps=e.whenProps;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -518,45 +518,45 @@ export function WithExpandableRow(args: TableProps): JSX.Element {
|
|
|
518
518
|
|
|
519
519
|
return (
|
|
520
520
|
<div className="p-4 bg-neutral-white">
|
|
521
|
-
<Table
|
|
522
|
-
<Table.
|
|
521
|
+
<Table {...args}>
|
|
522
|
+
<Table.Head>
|
|
523
523
|
<Table.Row>
|
|
524
|
-
<Table.
|
|
525
|
-
<Table.
|
|
526
|
-
<Table.
|
|
527
|
-
<Table.
|
|
524
|
+
<Table.HeadCell />
|
|
525
|
+
<Table.HeadCell>reference</Table.HeadCell>
|
|
526
|
+
<Table.HeadCell>product</Table.HeadCell>
|
|
527
|
+
<Table.HeadCell>price</Table.HeadCell>
|
|
528
528
|
</Table.Row>
|
|
529
|
-
</Table.
|
|
529
|
+
</Table.Head>
|
|
530
530
|
|
|
531
531
|
<Table.Body>
|
|
532
|
-
<Table.
|
|
532
|
+
<Table.ExpandableRow
|
|
533
533
|
leading={leading}
|
|
534
534
|
expandableContent={<div>Forced expanded with custom leading</div>}
|
|
535
535
|
expanded
|
|
536
536
|
>
|
|
537
|
-
<Table.
|
|
538
|
-
<Table.
|
|
539
|
-
<Table.
|
|
540
|
-
</Table.
|
|
541
|
-
<Table.
|
|
537
|
+
<Table.Cell>123456</Table.Cell>
|
|
538
|
+
<Table.Cell>Body 1</Table.Cell>
|
|
539
|
+
<Table.Cell>12345</Table.Cell>
|
|
540
|
+
</Table.ExpandableRow>
|
|
541
|
+
<Table.ExpandableRow
|
|
542
542
|
leading={leading}
|
|
543
543
|
expandableContent={<div>Initial expanded row with custom leading</div>}
|
|
544
544
|
initialExpanded
|
|
545
545
|
>
|
|
546
|
-
<Table.
|
|
547
|
-
<Table.
|
|
548
|
-
<Table.
|
|
549
|
-
</Table.
|
|
550
|
-
<Table.
|
|
551
|
-
<Table.
|
|
552
|
-
<Table.
|
|
553
|
-
<Table.
|
|
554
|
-
</Table.
|
|
555
|
-
<Table.
|
|
556
|
-
<Table.
|
|
557
|
-
<Table.
|
|
558
|
-
<Table.
|
|
559
|
-
</Table.
|
|
546
|
+
<Table.Cell>123456</Table.Cell>
|
|
547
|
+
<Table.Cell>Body 2</Table.Cell>
|
|
548
|
+
<Table.Cell>12345</Table.Cell>
|
|
549
|
+
</Table.ExpandableRow>
|
|
550
|
+
<Table.ExpandableRow expandableContent={<div>Expandable row</div>}>
|
|
551
|
+
<Table.Cell>123456</Table.Cell>
|
|
552
|
+
<Table.Cell>Body 3</Table.Cell>
|
|
553
|
+
<Table.Cell>12345</Table.Cell>
|
|
554
|
+
</Table.ExpandableRow>
|
|
555
|
+
<Table.ExpandableRow expanded>
|
|
556
|
+
<Table.Cell>123456</Table.Cell>
|
|
557
|
+
<Table.Cell>Body 5</Table.Cell>
|
|
558
|
+
<Table.Cell>12345</Table.Cell>
|
|
559
|
+
</Table.ExpandableRow>
|
|
560
560
|
</Table.Body>
|
|
561
561
|
</Table>
|
|
562
562
|
</div>
|
|
@@ -183,21 +183,21 @@ describe('<Table />', () => {
|
|
|
183
183
|
expect(checkboxes[1]).toBeChecked()
|
|
184
184
|
})
|
|
185
185
|
|
|
186
|
-
it('Table.
|
|
186
|
+
it('Table.ExpandableRow renders correclty', () => {
|
|
187
187
|
const onExpandedChange = jest.fn()
|
|
188
188
|
|
|
189
189
|
const expandableTable = ({ controlledExpanded4 }: { controlledExpanded4: boolean }) => (
|
|
190
190
|
<React.Fragment>
|
|
191
191
|
<Table.Head>
|
|
192
192
|
<Table.Row>
|
|
193
|
-
<Table.
|
|
193
|
+
<Table.HeadCell />
|
|
194
194
|
<Table.HeadCell># Number</Table.HeadCell>
|
|
195
195
|
<Table.HeadCell>Company</Table.HeadCell>
|
|
196
196
|
<Table.HeadCell alignment="right">Price $</Table.HeadCell>
|
|
197
197
|
</Table.Row>
|
|
198
198
|
</Table.Head>
|
|
199
199
|
<Table.Body>
|
|
200
|
-
<Table.
|
|
200
|
+
<Table.ExpandableRow
|
|
201
201
|
expandableContent={<div>This is an expandable content on index 0</div>}
|
|
202
202
|
expanded
|
|
203
203
|
>
|
|
@@ -206,15 +206,15 @@ describe('<Table />', () => {
|
|
|
206
206
|
<Table.Cell format="currency" alignment="right">
|
|
207
207
|
$9876,50
|
|
208
208
|
</Table.Cell>
|
|
209
|
-
</Table.
|
|
210
|
-
<Table.
|
|
209
|
+
</Table.ExpandableRow>
|
|
210
|
+
<Table.ExpandableRow>
|
|
211
211
|
<Table.Cell format="number">#000000-2</Table.Cell>
|
|
212
212
|
<Table.Cell>Modal X 21</Table.Cell>
|
|
213
213
|
<Table.Cell format="currency" alignment="right">
|
|
214
214
|
$9876,50
|
|
215
215
|
</Table.Cell>
|
|
216
|
-
</Table.
|
|
217
|
-
<Table.
|
|
216
|
+
</Table.ExpandableRow>
|
|
217
|
+
<Table.ExpandableRow
|
|
218
218
|
expandableContent={<div>This is an expandable content on index 2</div>}
|
|
219
219
|
leading={(expanded) => (expanded ? 'open' : 'closed')}
|
|
220
220
|
onExpandedChange={onExpandedChange}
|
|
@@ -224,8 +224,8 @@ describe('<Table />', () => {
|
|
|
224
224
|
<Table.Cell format="currency" alignment="right">
|
|
225
225
|
$9876,50
|
|
226
226
|
</Table.Cell>
|
|
227
|
-
</Table.
|
|
228
|
-
<Table.
|
|
227
|
+
</Table.ExpandableRow>
|
|
228
|
+
<Table.ExpandableRow
|
|
229
229
|
expandableContent={<div>This is an expandable content on index 3</div>}
|
|
230
230
|
expanded={controlledExpanded4}
|
|
231
231
|
>
|
|
@@ -234,7 +234,7 @@ describe('<Table />', () => {
|
|
|
234
234
|
<Table.Cell format="currency" alignment="right">
|
|
235
235
|
$9876,50
|
|
236
236
|
</Table.Cell>
|
|
237
|
-
</Table.
|
|
237
|
+
</Table.ExpandableRow>
|
|
238
238
|
</Table.Body>
|
|
239
239
|
</React.Fragment>
|
|
240
240
|
)
|
|
@@ -36,7 +36,6 @@ import type {
|
|
|
36
36
|
TablePickerItemProps,
|
|
37
37
|
TablePickerProps,
|
|
38
38
|
ExpandableTableRowProps,
|
|
39
|
-
TableHeadCellProps,
|
|
40
39
|
} from './Table.types'
|
|
41
40
|
|
|
42
41
|
const StyledTableBody = styled.tbody`
|
|
@@ -83,7 +82,6 @@ const StyledTableCell = styled.td<{ alignment?: string; format?: string }>`
|
|
|
83
82
|
const StyledTableHeadCell = styled.th<{
|
|
84
83
|
alignment?: string
|
|
85
84
|
clickable: boolean
|
|
86
|
-
capitalized?: boolean
|
|
87
85
|
}>`
|
|
88
86
|
${StyledCell}
|
|
89
87
|
|
|
@@ -91,10 +89,7 @@ const StyledTableHeadCell = styled.th<{
|
|
|
91
89
|
|
|
92
90
|
font-weight: ${token('font-weight-bold')};
|
|
93
91
|
|
|
94
|
-
text-transform:
|
|
95
|
-
uppercase: whenProps({ capitalized: false }),
|
|
96
|
-
capitalize: whenProps({ capitalized: true }),
|
|
97
|
-
})};
|
|
92
|
+
text-transform: capitalize;
|
|
98
93
|
|
|
99
94
|
cursor: ${conditional({
|
|
100
95
|
pointer: whenProps({ clickable: true }),
|
|
@@ -103,17 +98,6 @@ const StyledTableHeadCell = styled.th<{
|
|
|
103
98
|
`
|
|
104
99
|
|
|
105
100
|
const StyledTableHead = styled.thead`
|
|
106
|
-
box-shadow: 0 1px 0 ${token('color-neutral')};
|
|
107
|
-
|
|
108
|
-
${StyledTableCell} {
|
|
109
|
-
padding: ${token('space-s')};
|
|
110
|
-
|
|
111
|
-
font-weight: ${token('font-weight-bold')};
|
|
112
|
-
text-transform: uppercase;
|
|
113
|
-
}
|
|
114
|
-
`
|
|
115
|
-
|
|
116
|
-
const StyledExpandableTableHead = styled.thead`
|
|
117
101
|
border: 1px solid ${token('color-neutral-lighter')};
|
|
118
102
|
|
|
119
103
|
${StyledTableCell} {
|
|
@@ -124,43 +108,24 @@ const StyledExpandableTableHead = styled.thead`
|
|
|
124
108
|
}
|
|
125
109
|
`
|
|
126
110
|
|
|
127
|
-
const
|
|
111
|
+
const StyledTableRow = styled.tr<{ selected: boolean; isExpanded: boolean }>`
|
|
128
112
|
${StyledTableHead} > & {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
background-color: ${token('color-neutral-white')};
|
|
113
|
+
background-color: ${token('color-neutral-lightest')};
|
|
132
114
|
}
|
|
133
115
|
|
|
134
|
-
${
|
|
135
|
-
${
|
|
136
|
-
outline: 1px solid ${token('color-accent')};
|
|
137
|
-
`}
|
|
138
|
-
|
|
139
|
-
${focusable`
|
|
140
|
-
box-shadow: inset ${token('shadow-glow-primary')};
|
|
141
|
-
`}
|
|
116
|
+
${StyledTableFoot} > & {
|
|
117
|
+
background-color: ${token('color-neutral-lightest')};
|
|
142
118
|
}
|
|
143
|
-
`
|
|
144
119
|
|
|
145
|
-
const StyledTableRow = styled(BaseStyledTableRow)<{ selected?: boolean }>`
|
|
146
120
|
background-color: ${conditional({
|
|
147
121
|
'table-row-selected-color': whenProps({ selected: true }),
|
|
148
|
-
'color-
|
|
122
|
+
'color-neutral-white': whenProps({ selected: false }),
|
|
149
123
|
})};
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
&:nth-child(even) ${StyledTableCell} {
|
|
157
|
-
background: ${token('color-transparent')};
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
`
|
|
161
|
-
|
|
162
|
-
const StyledExpandableTableRow = styled.tr<{ $isExpanded: boolean }>`
|
|
163
|
-
background-color: ${token('color-neutral-white')};
|
|
124
|
+
${hoverable`
|
|
125
|
+
background-color: ${conditional({
|
|
126
|
+
'table-row-selected-color': whenProps({ selected: true }),
|
|
127
|
+
})} !important;
|
|
128
|
+
`}
|
|
164
129
|
|
|
165
130
|
border-color: ${token('color-neutral-lighter')};
|
|
166
131
|
border-width: 1px;
|
|
@@ -168,22 +133,24 @@ const StyledExpandableTableRow = styled.tr<{ $isExpanded: boolean }>`
|
|
|
168
133
|
border-right-style: solid;
|
|
169
134
|
border-left-style: solid;
|
|
170
135
|
border-bottom-style: ${conditional({
|
|
171
|
-
solid: whenProps({
|
|
172
|
-
hidden: whenProps({
|
|
136
|
+
solid: whenProps({ isExpanded: false }),
|
|
137
|
+
hidden: whenProps({ isExpanded: true }),
|
|
173
138
|
})};
|
|
174
139
|
|
|
175
140
|
box-shadow: ${conditional({
|
|
176
|
-
'0px 3px 3px 0px #C1CED9': whenProps({
|
|
177
|
-
none: whenProps({
|
|
141
|
+
'0px 3px 3px 0px #C1CED9': whenProps({ isExpanded: true }),
|
|
142
|
+
none: whenProps({ isExpanded: false }),
|
|
178
143
|
})};
|
|
179
144
|
|
|
180
|
-
${
|
|
181
|
-
|
|
182
|
-
|
|
145
|
+
${StyledTableBody} > & {
|
|
146
|
+
${hoverable`
|
|
147
|
+
background-color: ${token('color-neutral-lighter')};
|
|
148
|
+
`}
|
|
183
149
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
150
|
+
${focusable`
|
|
151
|
+
box-shadow: inset ${token('shadow-glow-primary')};
|
|
152
|
+
`}
|
|
153
|
+
}
|
|
187
154
|
`
|
|
188
155
|
|
|
189
156
|
const StyledExpandableContentRow = styled.tr`
|
|
@@ -195,20 +162,16 @@ const StyledExpandableContentRow = styled.tr`
|
|
|
195
162
|
border-bottom-style: solid;
|
|
196
163
|
`
|
|
197
164
|
|
|
198
|
-
const StyledTable = styled.table<{ scale?: string
|
|
165
|
+
const StyledTable = styled.table<{ scale?: string }>`
|
|
199
166
|
width: 100%;
|
|
200
167
|
|
|
201
168
|
white-space: nowrap;
|
|
202
169
|
|
|
203
|
-
background-color: ${
|
|
204
|
-
'color-neutral-lightest': whenProps({ withExpandableRows: true }),
|
|
205
|
-
'color-neutral-white': whenProps({ withExpandableRows: false }),
|
|
206
|
-
})};
|
|
170
|
+
background-color: ${token('color-neutral-lightest')};
|
|
207
171
|
|
|
208
172
|
border-collapse: collapse;
|
|
209
173
|
|
|
210
|
-
${StyledTableBody} ${StyledTableRow}
|
|
211
|
-
${StyledTableBody} ${StyledExpandableTableRow} {
|
|
174
|
+
${StyledTableBody} ${StyledTableRow} {
|
|
212
175
|
height: ${conditional({
|
|
213
176
|
'24px': whenProps({ scale: 'small' }),
|
|
214
177
|
'48px': whenProps({ scale: 'default' }),
|
|
@@ -240,14 +203,13 @@ function Table<T>({
|
|
|
240
203
|
children,
|
|
241
204
|
selection,
|
|
242
205
|
scale = 'default',
|
|
243
|
-
withExpandableRows,
|
|
244
206
|
...others
|
|
245
207
|
}: TableProps<T>): JSX.Element {
|
|
246
208
|
return (
|
|
247
209
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
248
210
|
// @ts-ignore
|
|
249
211
|
<TableSelectionProvider selection={selection}>
|
|
250
|
-
<StyledTable scale={scale}
|
|
212
|
+
<StyledTable scale={scale} {...others}>
|
|
251
213
|
{children}
|
|
252
214
|
</StyledTable>
|
|
253
215
|
</TableSelectionProvider>
|
|
@@ -273,10 +235,6 @@ function TableHead({ children, ...others }: TableSectionProps): JSX.Element {
|
|
|
273
235
|
return <StyledTableHead {...others}>{children}</StyledTableHead>
|
|
274
236
|
}
|
|
275
237
|
|
|
276
|
-
function ExpandableTableHead({ children, ...others }: TableSectionProps): JSX.Element {
|
|
277
|
-
return <StyledExpandableTableHead {...others}>{children}</StyledExpandableTableHead>
|
|
278
|
-
}
|
|
279
|
-
|
|
280
238
|
function TableBody({ children, ...others }: TableSectionProps): JSX.Element {
|
|
281
239
|
return <StyledTableBody {...others}>{children}</StyledTableBody>
|
|
282
240
|
}
|
|
@@ -344,19 +302,11 @@ function SelectionHeadCell<T>(props: SelectionCellProps<T>): JSX.Element {
|
|
|
344
302
|
)
|
|
345
303
|
}
|
|
346
304
|
|
|
347
|
-
function ExpandableHeadCell(props: TableHeadCellProps): JSX.Element {
|
|
348
|
-
return <TableHeadCell capitalized {...props} />
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
function ExpandableCell(props: TableCellProps): JSX.Element {
|
|
352
|
-
return <TableCell {...props} />
|
|
353
|
-
}
|
|
354
|
-
|
|
355
305
|
function TableRow({ children, ...others }: TableRowProps): JSX.Element {
|
|
356
306
|
const selected = useIsRowSelected(children)
|
|
357
307
|
|
|
358
308
|
return (
|
|
359
|
-
<StyledTableRow {...others} selected={selected}>
|
|
309
|
+
<StyledTableRow {...others} selected={selected} isExpanded={false}>
|
|
360
310
|
{children}
|
|
361
311
|
</StyledTableRow>
|
|
362
312
|
)
|
|
@@ -373,6 +323,8 @@ function ExpandableTableRow({
|
|
|
373
323
|
}: ExpandableTableRowProps): JSX.Element {
|
|
374
324
|
const [openState, setOpenState] = useState(initialExpanded)
|
|
375
325
|
|
|
326
|
+
const selected = useIsRowSelected(children)
|
|
327
|
+
|
|
376
328
|
const open = expanded ?? openState
|
|
377
329
|
const isExpanded = Boolean(open && expandableContent)
|
|
378
330
|
const colSpan = Array.isArray(children) ? children.length + 1 : 1
|
|
@@ -391,10 +343,10 @@ function ExpandableTableRow({
|
|
|
391
343
|
|
|
392
344
|
return (
|
|
393
345
|
<>
|
|
394
|
-
<
|
|
395
|
-
<
|
|
346
|
+
<StyledTableRow {...others} onClick={toggle} isExpanded={isExpanded} selected={selected}>
|
|
347
|
+
<TableCell>{expandableContent && leading}</TableCell>
|
|
396
348
|
{children}
|
|
397
|
-
</
|
|
349
|
+
</StyledTableRow>
|
|
398
350
|
{isExpanded && (
|
|
399
351
|
<StyledExpandableContentRow>
|
|
400
352
|
<StyledTableCell colSpan={colSpan}>{expandableContent}</StyledTableCell>
|
|
@@ -408,15 +360,13 @@ function TableHeadCell({
|
|
|
408
360
|
alignment = 'left',
|
|
409
361
|
children,
|
|
410
362
|
onClick,
|
|
411
|
-
capitalized = false,
|
|
412
363
|
...others
|
|
413
|
-
}:
|
|
364
|
+
}: TableCellProps): JSX.Element {
|
|
414
365
|
return (
|
|
415
366
|
<StyledTableHeadCell
|
|
416
367
|
clickable={onClick != null}
|
|
417
368
|
alignment={alignment}
|
|
418
369
|
onClick={onClick}
|
|
419
|
-
capitalized={capitalized}
|
|
420
370
|
{...others}
|
|
421
371
|
>
|
|
422
372
|
<Layout.Group space="xs" align="center">
|
|
@@ -563,12 +513,7 @@ Table.Selection = {
|
|
|
563
513
|
Cell: SelectionCell,
|
|
564
514
|
HeadCell: SelectionHeadCell,
|
|
565
515
|
}
|
|
566
|
-
Table.
|
|
567
|
-
Head: ExpandableTableHead,
|
|
568
|
-
HeadCell: ExpandableHeadCell,
|
|
569
|
-
Cell: ExpandableCell,
|
|
570
|
-
Row: ExpandableTableRow,
|
|
571
|
-
}
|
|
516
|
+
Table.ExpandableRow = ExpandableTableRow
|
|
572
517
|
Table.SortHandle = TableSortHandle
|
|
573
518
|
TablePicker.Item = TablePickerItem
|
|
574
519
|
Table.Picker = TablePicker
|
|
@@ -17,7 +17,6 @@ export interface TableProps<T extends Selectable = TableSelectableRow>
|
|
|
17
17
|
extends HTMLAttributes<HTMLTableElement> {
|
|
18
18
|
scale?: Scale
|
|
19
19
|
selection?: TableSelectionConfig<T>
|
|
20
|
-
withExpandableRows?: boolean
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
export interface TableCaptionProps extends HTMLAttributes<HTMLTableCaptionElement> {
|
|
@@ -57,10 +56,6 @@ export interface TableCellProps extends HTMLAttributes<HTMLTableCellElement> {
|
|
|
57
56
|
selected?: boolean
|
|
58
57
|
}
|
|
59
58
|
|
|
60
|
-
export interface TableHeadCellProps extends TableCellProps {
|
|
61
|
-
capitalized?: boolean
|
|
62
|
-
}
|
|
63
|
-
|
|
64
59
|
export type TableColumn<T = Record<string, unknown>> = {
|
|
65
60
|
/**
|
|
66
61
|
* The accessor of you entry interface
|
|
@@ -872,7 +872,7 @@ const mirandaCompatibility = {
|
|
|
872
872
|
// Table
|
|
873
873
|
'table-row-default-color': color('neutral-white'),
|
|
874
874
|
'table-row-variant-color': toCSSValue('color-neutral-40', 0.2),
|
|
875
|
-
'table-row-selected-color': toCSSValue('color-primary-
|
|
875
|
+
'table-row-selected-color': toCSSValue('color-primary-20'),
|
|
876
876
|
|
|
877
877
|
// Top Navigation
|
|
878
878
|
'top-navigation-height': rem('60px'),
|
package/dist/prop-201ffe28.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var t=require("./toArray-b56541b4.js"),n=require("./miranda-compatibility.theme-22a9ce26.js"),e=require("./theming/index.js");function r(t,r){return Object.keys(t||{}).reduce(((o,i)=>{var u;let s=t[i];if(n.isFunction(s)&&(s=s(r)),s){const t=i,n=null!==(u=e.getToken(t,r))&&void 0!==u?u:i;return[...o,n]}return o}),[]).join(" ")}function o(...t){const[n,e]=t;return null==n||!1===n||Number.isNaN(n)?e||n:"string"==typeof n&&0===n.length&&e||n}exports.conditional=function(...e){return function(o){let i=[];for(let u=0;u<e.length;u++){const s=e[u];n.isFunction(s)?i.push(s(o)):t.isObject(s)?i=i.concat(r(s,o)):s&&i.push(String(s))}return i.join(" ")}},exports.prop=function(t,n,e=o){return r=>e(r[t],n)},exports.whenProps=function(e){return function(r){const o=t.toArray(e);let i=!1;for(let e=0;e<o.length;e++){const u=o[e],s=Object.keys(u);let c=!0;for(let e=0;e<s.length&&c;e++){const o=s[e],i=n.lodash_get(r,o),l=u[o];c=Array.isArray(l)?c&&t.toArray(l).includes(i):n.isFunction(l)?c&&Boolean(l(i)):c&&l===i}i=i||c}return i}};
|
|
2
|
-
//# sourceMappingURL=prop-201ffe28.js.map
|