@mrshmllw/smores-react 13.16.1 → 13.17.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/README.md +10 -8
- package/dist/Table/Table.js +6 -2
- package/dist/Table/Table.js.map +1 -1
- package/dist/Table/components/RowActions.js +10 -3
- package/dist/Table/components/RowActions.js.map +1 -1
- package/dist/Table/components/TableFooter.js +1 -1
- package/dist/Table/components/TableFooter.js.map +1 -1
- package/dist/Table/components/TableRow.js +18 -3
- package/dist/Table/components/TableRow.js.map +1 -1
- package/dist/Table/components/commonComponents.d.ts +2 -3
- package/dist/Table/components/commonComponents.js +14 -15
- package/dist/Table/components/commonComponents.js.map +1 -1
- package/dist/Table/types.d.ts +16 -16
- package/dist/Table/types.js.map +1 -1
- package/dist/ThemeProvider/utils/colourMap.js +1 -1
- package/dist/ThemeProvider/utils/colourMap.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="assets/smores-logo-dark.png">
|
|
4
|
+
<source media="(prefers-color-scheme: light)" srcset="assets/smores-logo-light.png">
|
|
5
|
+
<img alt="Project Logo" src="assets/smores-logo-light.png">
|
|
6
|
+
</picture></p>
|
|
5
7
|
<p align="center">
|
|
6
8
|
<a href="https://www.npmjs.com/package/@mrshmllw/smores-react">
|
|
7
|
-
<img alt="npm-version-badge" src="https://img.shields.io/npm/v/@mrshmllw/smores-react.svg?style=flat-square" /></a>
|
|
9
|
+
<img alt="npm-version-badge" src="https://img.shields.io/npm/v/@mrshmllw/smores-react.svg?style=flat-square&logo=nodedotjs" /></a>
|
|
8
10
|
<a href="https://github.com/marshmallow-insurance/smores-react/blob/master/LICENSE">
|
|
9
|
-
<img alt="licence-badge" src="https://img.shields.io/github/license/marshmallow-insurance/smores-react.svg?style=flat-square" /></a>
|
|
10
|
-
<a href="https://snyk.io
|
|
11
|
-
<img alt="snyk-badge" src="https://
|
|
11
|
+
<img alt="licence-badge" src="https://img.shields.io/github/license/marshmallow-insurance/smores-react.svg?style=flat-square&logo=ReadMe" /></a>
|
|
12
|
+
<a href="https://snyk.io/test/github/marshmallow-insurance/smores-react?targetFile=package.json">
|
|
13
|
+
<img alt="snyk-badge" src="https://snyk.io/test/github/marshmallow-insurance/smores-react/badge.svg?targetFile=package.json&style=flat-square" /></a>
|
|
12
14
|
<a href="https://prettier.io/">
|
|
13
|
-
<img alt="prettier-badge" src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square" /></a>
|
|
15
|
+
<img alt="prettier-badge" src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square&logo=prettier" /></a>
|
|
14
16
|
</p>
|
|
15
17
|
|
|
16
18
|
# Smores React
|
package/dist/Table/Table.js
CHANGED
|
@@ -4,6 +4,8 @@ import { TableHeader } from './components/TableHeader';
|
|
|
4
4
|
import { TableRow } from './components/TableRow';
|
|
5
5
|
import { StyledCell, StyledTable } from './components/commonComponents';
|
|
6
6
|
import { TableFooter } from './components/TableFooter';
|
|
7
|
+
import { useTheme } from 'styled-components';
|
|
8
|
+
import { resolveToThemeColor } from '../ThemeProvider/utils/colourMap';
|
|
7
9
|
/**
|
|
8
10
|
* A table component that displays data with various features such as expandable rows, striped rows, and fixed headers.
|
|
9
11
|
*
|
|
@@ -17,12 +19,14 @@ import { TableFooter } from './components/TableFooter';
|
|
|
17
19
|
* ## Improvements:
|
|
18
20
|
* - It would be nice if we expandable logic inside this component, e.g the presence of certain props would automatically add this
|
|
19
21
|
*/
|
|
20
|
-
export const Table = ({ columns, data, fixedHeader = true, hasKeyline = false, expandable, subTable, subRows, headerHeight, headerColor = '
|
|
22
|
+
export const Table = ({ columns, data, fixedHeader = true, hasKeyline = false, expandable, subTable, subRows, headerHeight, headerColor = 'color.surface.base.200', rowColor = 'color.surface.base.300', footer, stripedColor, rowBorderColor = 'color.illustration.neutral.300', rowActions, clickableRow, rowPadding, columnPadding, noDataContent, roundedTable, hideTableHeader = false, }) => {
|
|
23
|
+
const theme = useTheme();
|
|
24
|
+
const resolvedHeaderColor = resolveToThemeColor(headerColor, theme);
|
|
21
25
|
const showActionsCell = expandable ?? rowActions;
|
|
22
26
|
const expandSubProp = showActionsCell ? columns.length + 1 : columns.length;
|
|
23
27
|
return (React.createElement(StyledTable, { "$roundedTable": roundedTable },
|
|
24
28
|
!hideTableHeader && (React.createElement("thead", null,
|
|
25
|
-
React.createElement(TableHeader, { columns: columns, fixedHeader: fixedHeader, headerHeight: headerHeight, subTable: subTable, headerColor:
|
|
29
|
+
React.createElement(TableHeader, { columns: columns, fixedHeader: fixedHeader, headerHeight: headerHeight, subTable: subTable, headerColor: resolvedHeaderColor, rowActions: rowActions, columnPadding: columnPadding, expandable: expandable, hasKeyline: hasKeyline }))),
|
|
26
30
|
React.createElement("tbody", null,
|
|
27
31
|
data.length === 0 && (React.createElement("tr", null,
|
|
28
32
|
React.createElement(StyledCell, { colSpan: expandSubProp, "$rowPadding": rowPadding, "$columnPadding": columnPadding }, noDataContent ?? React.createElement(Text, { align: "center" }, "No available data")))),
|
package/dist/Table/Table.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Table.js","sourceRoot":"","sources":["../../src/Table/Table.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAA;AAEvE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"Table.js","sour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Header } from './components/TableHeader'\nimport { TableRow } from './components/TableRow'\nimport { StyledCell, StyledTable } from './components/commonComponents'\nimport { TableProps } from './types'\nimport { TableFooter } from './components/TableFooter'\nimport { useTheme } from 'styled-components'\nimport { resolveToThemeColor } from '../ThemeProvider/utils/colourMap'\n\n/**\n * A table component that displays data with various features such as expandable rows, striped rows, and fixed headers.\n *\n * ## Caveats:\n * - `subRows` should always have the same columns as the Parent table\n * - `stripedColor` wont be applied to `subRows` or `subTables`\n * - `rowActions` will always need an `onClick`, this will be automatically passed onto the `ReactNode` you place & will be selectable\n * - Rows will scale depending on the cell content size\n * - Using `clickableRow` with clickable cells, ensure you use `e.stopPropagation` in your cells `onClick`\n *\n * ## Improvements:\n * - It would be nice if we expandable logic inside this component, e.g the presence of certain props would automatically add this\n */\nexport const Table = <T extends object, K extends object>({\n columns,\n data,\n fixedHeader = true,\n hasKeyline = false,\n expandable,\n subTable,\n subRows,\n headerHeight,\n headerColor = 'color.surface.base.200',\n rowColor = 'color.surface.base.300',\n footer,\n stripedColor,\n rowBorderColor = 'color.illustration.neutral.300',\n rowActions,\n clickableRow,\n rowPadding,\n columnPadding,\n noDataContent,\n roundedTable,\n hideTableHeader = false,\n}: TableProps<T, K>) => {\n const theme = useTheme()\n\n const resolvedHeaderColor = resolveToThemeColor(headerColor, theme)\n\n const showActionsCell = expandable ?? rowActions\n const expandSubProp = showActionsCell ? columns.length + 1 : columns.length\n return (\n <StyledTable $roundedTable={roundedTable}>\n {!hideTableHeader && (\n <thead>\n <TableHeader\n columns={columns}\n fixedHeader={fixedHeader}\n headerHeight={headerHeight}\n subTable={subTable}\n headerColor={resolvedHeaderColor}\n rowActions={rowActions}\n columnPadding={columnPadding}\n expandable={expandable}\n hasKeyline={hasKeyline}\n />\n </thead>\n )}\n <tbody>\n {data.length === 0 && (\n <tr>\n <StyledCell\n colSpan={expandSubProp}\n $rowPadding={rowPadding}\n $columnPadding={columnPadding}\n >\n {noDataContent ?? <Text align=\"center\">No available data</Text>}\n </StyledCell>\n </tr>\n )}\n {data.length !== 0 && (\n <>\n {data.map((row, rowIndex) => (\n <TableRow\n key={rowIndex}\n rowData={row}\n rowIndex={rowIndex}\n columns={columns}\n rowActions={rowActions}\n stripedColor={stripedColor}\n subTable={subTable}\n subRows={subRows}\n rowColor={rowColor}\n rowBorderColor={rowBorderColor}\n rowPadding={rowPadding}\n columnPadding={columnPadding}\n expandable={expandable}\n clickableRow={clickableRow}\n hideBorder={\n Boolean(roundedTable) && rowIndex === data.length - 1\n }\n />\n ))}\n\n {footer && (\n <TableFooter columnCount={columns.length} footer={footer} />\n )}\n </>\n )}\n </tbody>\n </StyledTable>\n )\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import styled from 'styled-components';
|
|
2
|
+
import styled, { useTheme } from 'styled-components';
|
|
3
3
|
import { Box } from '../../Box';
|
|
4
4
|
import { Button } from '../../Button';
|
|
5
5
|
import { IconStrict } from '../../IconStrict';
|
|
@@ -7,12 +7,17 @@ import { Tooltip } from '../../Tooltip';
|
|
|
7
7
|
import { focusOutlineStyle } from '../../utils/focusOutline';
|
|
8
8
|
import { isReactElement } from '../../utils/isReactElement';
|
|
9
9
|
import { StyledCell } from './commonComponents';
|
|
10
|
+
import { resolveToThemeColor } from '../../ThemeProvider/utils/colourMap';
|
|
10
11
|
export const RowActions = ({ rowData, rowActions, isExpanded, toggleExpansion, expandable, canExpandRow, }) => {
|
|
11
12
|
const handleAction = async (e, action) => {
|
|
12
13
|
e.stopPropagation();
|
|
13
14
|
await action(rowData);
|
|
14
15
|
};
|
|
15
|
-
|
|
16
|
+
const theme = useTheme();
|
|
17
|
+
const resolvedRowActionBgColor = rowActions?.bgColor
|
|
18
|
+
? resolveToThemeColor(rowActions.bgColor, theme)
|
|
19
|
+
: undefined;
|
|
20
|
+
return (React.createElement(StyledCell, { "$stickyCell": Boolean(rowActions) || Boolean(expandable), "$rowActionsBgColor": resolvedRowActionBgColor },
|
|
16
21
|
React.createElement(Box, { flex: true, alignItems: "center", justifyContent: "flex-end" },
|
|
17
22
|
rowActions?.actions?.map((action, actionIndex) => {
|
|
18
23
|
if (!action.showCondition || action.showCondition(rowData)) {
|
|
@@ -37,7 +42,9 @@ export const RowActions = ({ rowData, rowActions, isExpanded, toggleExpansion, e
|
|
|
37
42
|
canExpandRow && (React.createElement(CaretIcon, { render: "caret", handleClick: (e) => {
|
|
38
43
|
e.stopPropagation();
|
|
39
44
|
toggleExpansion();
|
|
40
|
-
}, size: 24, "$isOpen": isExpanded, iconColor: isExpanded ? '
|
|
45
|
+
}, size: 24, "$isOpen": isExpanded, iconColor: isExpanded ? 'color.surface.base.000' : 'color.icon.base', backgroundColor: isExpanded
|
|
46
|
+
? 'color.surface.base.900'
|
|
47
|
+
: 'color.illustration.neutral.300' })))));
|
|
41
48
|
};
|
|
42
49
|
const Wrapper = styled(Box) `
|
|
43
50
|
white-space: nowrap;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RowActions.js","sourceRoot":"","sources":["../../../src/Table/components/RowActions.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAA;AACxC,OAAO,MAAM,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"RowActions.js","sourceRoot":"","sources":["../../../src/Table/components/RowActions.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAA;AACxC,OAAO,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,EAAE,cAAc,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AI,EAAE,EAAE,aACC,UAAU,EACnB,SAAS,EACP,UAAU,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC,iBAAiB,EAE3D,eAAe,EACb,UAAU;oBACR,CAAC,CAAC,wBAAwB;oBAC1B,CAAC,CAAC,gCAAgC,GAEtC,CACH,CACG,CACK,CACd,CAAA;AACH,CAAC,CAAA;AAED,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;;;;;;;;;;MAUrB,iBAAiB;;CAEtB,CAAA;AAED,MAAM,SAAS,GAAG,MAAM,CAAC,UAAU,CAAC,CAClC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;iBACF,OAAO,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,cAAc;;GAEzD,CACF,CAAA","sourcesContent":["import React, { FormEvent } from 'react'\nimport styled, { useTheme } from 'styled-components'\nimport { Box } from '../../Box'\nimport { Button } from '../../Button'\nimport { IconStrict } from '../../IconStrict'\nimport { Tooltip } from '../../Tooltip'\nimport { focusOutlineStyle } from '../../utils/focusOutline'\nimport { isReactElement } from '../../utils/isReactElement'\nimport { RowActionsProps } from '../types'\nimport { StyledCell } from './commonComponents'\nimport { resolveToThemeColor } from '../../ThemeProvider/utils/colourMap'\n\nexport const RowActions = <T extends object>({\n rowData,\n rowActions,\n isExpanded,\n toggleExpansion,\n expandable,\n canExpandRow,\n}: RowActionsProps<T>) => {\n const handleAction = async (\n e: MouseEvent | FormEvent<HTMLButtonElement>,\n action: (rowData: T) => void | Promise<void>,\n ) => {\n e.stopPropagation()\n await action(rowData)\n }\n\n const theme = useTheme()\n\n const resolvedRowActionBgColor = rowActions?.bgColor\n ? resolveToThemeColor(rowActions.bgColor, theme)\n : undefined\n\n return (\n <StyledCell\n $stickyCell={Boolean(rowActions) || Boolean(expandable)}\n $rowActionsBgColor={resolvedRowActionBgColor}\n >\n <Box flex alignItems=\"center\" justifyContent=\"flex-end\">\n {rowActions?.actions?.map((action, actionIndex) => {\n if (!action.showCondition || action.showCondition(rowData)) {\n return (\n <Wrapper flex key={actionIndex}>\n {'element' in action &&\n isReactElement(action.element) &&\n React.cloneElement(action.element, {\n onClick: async (e: MouseEvent) => {\n await handleAction(e, action.onClick)\n },\n tabIndex: 0,\n className: 'reactElementRowAction',\n })}\n {!('element' in action) && action.genericButton && (\n <Button\n {...action.genericButton}\n handleClick={(e) => void handleAction(e, action.onClick)}\n >\n {action.genericButton.children}\n </Button>\n )}\n {!('element' in action) &&\n action.iconButton &&\n (action.iconButton?.tooltipText ? (\n <Tooltip\n content={action.iconButton.tooltipText}\n position={'bottom'}\n variant=\"bubblegum\"\n >\n <IconStrict\n {...action.iconButton}\n handleClick={(e) =>\n void handleAction(e, action.onClick)\n }\n />\n </Tooltip>\n ) : (\n <IconStrict\n {...action.iconButton}\n handleClick={(e) => void handleAction(e, action.onClick)}\n />\n ))}\n </Wrapper>\n )\n }\n return null\n })}\n {canExpandRow && (\n <CaretIcon\n render=\"caret\"\n handleClick={(e) => {\n e.stopPropagation()\n toggleExpansion()\n }}\n size={24}\n $isOpen={isExpanded}\n iconColor={\n isExpanded ? 'color.surface.base.000' : 'color.icon.base'\n }\n backgroundColor={\n isExpanded\n ? 'color.surface.base.900'\n : 'color.illustration.neutral.300'\n }\n />\n )}\n </Box>\n </StyledCell>\n )\n}\n\nconst Wrapper = styled(Box)`\n white-space: nowrap;\n margin-right: 8px;\n\n &:last-child {\n margin-right: 0px;\n }\n\n .reactElementRowAction {\n cursor: pointer;\n ${focusOutlineStyle}\n }\n`\n\nconst CaretIcon = styled(IconStrict)<{ $isOpen?: boolean }>(\n ({ $isOpen }) => `\n transform: ${$isOpen ? 'rotate(180deg)' : 'rotate(0deg)'};\n transition: transform 0.3s ease;\n `,\n)\n"]}
|
|
@@ -4,7 +4,7 @@ export function TableFooter({ footer, columnCount, }) {
|
|
|
4
4
|
if ('element' in footer) {
|
|
5
5
|
return React.createElement("td", { colSpan: columnCount }, footer.element);
|
|
6
6
|
}
|
|
7
|
-
const { rowColor = '
|
|
7
|
+
const { rowColor = 'color.surface.base.300', data, columns, ...restFooter } = footer;
|
|
8
8
|
return (React.createElement(TableRow, { key: "footer", rowIndex: columns.length - 1, rowColor: rowColor, rowData: data, columns: columns, ...restFooter }));
|
|
9
9
|
}
|
|
10
10
|
//# sourceMappingURL=TableFooter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableFooter.js","sourceRoot":"","sources":["../../../src/Table/components/TableFooter.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAOrC,MAAM,UAAU,WAAW,CAAmB,EAC5C,MAAM,EACN,WAAW,GACF;IACT,IAAI,SAAS,IAAI,MAAM,EAAE,CAAC;QACxB,OAAO,4BAAI,OAAO,EAAE,WAAW,IAAG,MAAM,CAAC,OAAO,CAAM,CAAA;IACxD,CAAC;IAED,MAAM,
|
|
1
|
+
{"version":3,"file":"TableFooter.js","sourceRoot":"","sources":["../../../src/Table/components/TableFooter.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAOrC,MAAM,UAAU,WAAW,CAAmB,EAC5C,MAAM,EACN,WAAW,GACF;IACT,IAAI,SAAS,IAAI,MAAM,EAAE,CAAC;QACxB,OAAO,4BAAI,OAAO,EAAE,WAAW,IAAG,MAAM,CAAC,OAAO,CAAM,CAAA;IACxD,CAAC;IAED,MAAM,EACJ,QAAQ,GAAG,wBAAwB,EACnC,IAAI,EACJ,OAAO,EACP,GAAG,UAAU,EACd,GAAG,MAAM,CAAA;IAEV,OAAO,CACL,oBAAC,QAAQ,IACP,GAAG,EAAC,QAAQ,EACZ,QAAQ,EAAE,OAAO,CAAC,MAAM,GAAG,CAAC,EAC5B,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,IAAI,EACb,OAAO,EAAE,OAAO,KACZ,UAAU,GACd,CACH,CAAA;AACH,CAAC","sourcesContent":["import React from 'react'\nimport type { TableFooter } from '../types'\nimport { TableRow } from './TableRow'\n\ntype Props<K> = {\n footer: TableFooter<K>\n columnCount: number\n}\n\nexport function TableFooter<K extends object>({\n footer,\n columnCount,\n}: Props<K>) {\n if ('element' in footer) {\n return <td colSpan={columnCount}>{footer.element}</td>\n }\n\n const {\n rowColor = 'color.surface.base.300',\n data,\n columns,\n ...restFooter\n } = footer\n\n return (\n <TableRow\n key=\"footer\"\n rowIndex={columns.length - 1}\n rowColor={rowColor}\n rowData={data}\n columns={columns}\n {...restFooter}\n />\n )\n}\n"]}
|
|
@@ -3,8 +3,20 @@ import { isReactElement } from '../../utils/isReactElement';
|
|
|
3
3
|
import { isMappedReactElement } from '../helpers';
|
|
4
4
|
import { RowActions } from './RowActions';
|
|
5
5
|
import { StyledCell, StyledRow, StyledSubTableCell } from './commonComponents';
|
|
6
|
+
import { useTheme } from 'styled-components';
|
|
7
|
+
import { resolveToThemeColor } from '../../ThemeProvider/utils/colourMap';
|
|
6
8
|
export const TableRow = ({ rowData, rowIndex, columns, subRows, subTable, stripedColor, rowActions, rowColor, rowBorderColor, rowPadding, columnPadding, showActions, expandable, clickableRow, hideBorder, }) => {
|
|
9
|
+
const theme = useTheme();
|
|
7
10
|
const [expandedRows, setExpandedRows] = useState([]);
|
|
11
|
+
const resolvedRowColor = rowColor
|
|
12
|
+
? resolveToThemeColor(rowColor, theme)
|
|
13
|
+
: undefined;
|
|
14
|
+
const resolvedStripedColor = stripedColor
|
|
15
|
+
? resolveToThemeColor(stripedColor, theme)
|
|
16
|
+
: undefined;
|
|
17
|
+
const resolvedRowBorderColor = rowBorderColor
|
|
18
|
+
? resolveToThemeColor(rowBorderColor, theme)
|
|
19
|
+
: undefined;
|
|
8
20
|
const toggleRowExpansion = (rowIndex) => {
|
|
9
21
|
setExpandedRows((prevState) => prevState.includes(rowIndex)
|
|
10
22
|
? prevState.filter((index) => index !== rowIndex)
|
|
@@ -16,12 +28,15 @@ export const TableRow = ({ rowData, rowIndex, columns, subRows, subTable, stripe
|
|
|
16
28
|
const subRowsData = subRows?.rows(rowData);
|
|
17
29
|
const subTableData = subTable?.table(rowData);
|
|
18
30
|
const subPadding = subTable?.padding ?? subRows?.padding;
|
|
19
|
-
const subBgColor = subTable?.bgColor
|
|
31
|
+
const subBgColor = subTable?.bgColor || subRows?.bgColor;
|
|
32
|
+
const resolvedSubBgColor = subBgColor
|
|
33
|
+
? resolveToThemeColor(subBgColor, theme)
|
|
34
|
+
: undefined;
|
|
20
35
|
const showActionsCell = expandable ?? rowActions;
|
|
21
36
|
const expandSubProp = showActionsCell ? columns.length + 1 : columns.length;
|
|
22
37
|
const isExpandedRow = expandedRows.includes(rowIndex);
|
|
23
38
|
return (React.createElement(React.Fragment, null,
|
|
24
|
-
React.createElement(StyledRow, { "$stripedColor":
|
|
39
|
+
React.createElement(StyledRow, { "$stripedColor": resolvedStripedColor, "$rowColor": resolvedRowColor, "$rowBorderColor": resolvedRowBorderColor, "$clickableRow": !!clickableRow, "$noRowBorderColor": isExpandedRow || hideBorder, onClick: () => clickableRow?.(rowData), tabIndex: clickableRow && 0 },
|
|
25
40
|
columns.map((column, columnIndex) => {
|
|
26
41
|
let cellContent;
|
|
27
42
|
if (column.cell) {
|
|
@@ -37,6 +52,6 @@ export const TableRow = ({ rowData, rowIndex, columns, subRows, subTable, stripe
|
|
|
37
52
|
subRowsData &&
|
|
38
53
|
isMappedReactElement(subRowsData) &&
|
|
39
54
|
subRowsData.map((row) => cloneElement(row, { rowPadding, showActions: showActionsCell })),
|
|
40
|
-
subTableData && (React.createElement(StyledSubTableCell, { "$rowBorderColor":
|
|
55
|
+
subTableData && (React.createElement(StyledSubTableCell, { "$rowBorderColor": resolvedRowBorderColor, colSpan: expandSubProp, "$bgColor": resolvedSubBgColor, "$padding": subPadding }, cloneElement(subTableData, { rowPadding, columnPadding })))))));
|
|
41
56
|
};
|
|
42
57
|
//# sourceMappingURL=TableRow.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableRow.js","sourceRoot":"","sources":["../../../src/Table/components/TableRow.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,YAAY,EAAa,QAAQ,EAAE,MAAM,OAAO,CAAA;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAEjD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"TableRow.js","sourceRoot":"","sources":["../../../src/Table/components/TableRow.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,YAAY,EAAa,QAAQ,EAAE,MAAM,OAAO,CAAA;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAEjD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAC9E,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAA;AAEzE,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAmB,EACzC,OAAO,EACP,QAAQ,EACR,OAAO,EACP,OAAO,EACP,QAAQ,EACR,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,cAAc,EACd,UAAU,EACV,aAAa,EACb,WAAW,EACX,UAAU,EACV,YAAY,EACZ,UAAU,GACO,EAAE,EAAE;IACrB,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAA;I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AAa,EACzB,eAAe,EAAE,GAAG,EAAE,CAAC,kBAAkB,CAAC,QAAQ,CAAC,GACnD,CACH,CACS;QASX,aAAa,IAAI,CAChB;YACG,WAAW;gBACV,cAAc,CAAC,WAAW,CAAC;gBAC3B,YAAY,CAAC,WAAW,EAAE,EAAE,UAAU,EAAE,aAAa,EAAE,CAAC;YAEzD,WAAW;gBACV,oBAAoB,CAAC,WAAW,CAAC;gBACjC,WAAW,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CACtB,YAAY,CAAC,GAAG,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,CAAC,CAChE;YAEF,YAAY,IAAI,CACf,oBAAC,kBAAkB,uBACA,sBAAsB,EACvC,OAAO,EAAE,aAAa,cACZ,kBAAkB,cAClB,UAAU,IAEnB,YAAY,CAAC,YAAY,EAAE,EAAE,UAAU,EAAE,aAAa,EAAE,CAAC,CACvC,CACtB,CACA,CACJ,CACA,CACJ,CAAA;AACH,CAAC,CAAA","sourcesContent":["import React, { cloneElement, ReactNode, useState } from 'react'\nimport { isReactElement } from '../../utils/isReactElement'\nimport { isMappedReactElement } from '../helpers'\nimport { TableRowProps } from '../types'\nimport { RowActions } from './RowActions'\nimport { StyledCell, StyledRow, StyledSubTableCell } from './commonComponents'\nimport { useTheme } from 'styled-components'\nimport { resolveToThemeColor } from '../../ThemeProvider/utils/colourMap'\n\nexport const TableRow = <T extends object>({\n rowData,\n rowIndex,\n columns,\n subRows,\n subTable,\n stripedColor,\n rowActions,\n rowColor,\n rowBorderColor,\n rowPadding,\n columnPadding,\n showActions,\n expandable,\n clickableRow,\n hideBorder,\n}: TableRowProps<T>) => {\n const theme = useTheme()\n const [expandedRows, setExpandedRows] = useState<number[]>([])\n\n const resolvedRowColor = rowColor\n ? resolveToThemeColor(rowColor, theme)\n : undefined\n const resolvedStripedColor = stripedColor\n ? resolveToThemeColor(stripedColor, theme)\n : undefined\n const resolvedRowBorderColor = rowBorderColor\n ? resolveToThemeColor(rowBorderColor, theme)\n : undefined\n\n const toggleRowExpansion = (rowIndex: number) => {\n setExpandedRows((prevState) =>\n prevState.includes(rowIndex)\n ? prevState.filter((index) => index !== rowIndex)\n : [...prevState, rowIndex],\n )\n }\n\n const canExpandRow =\n expandable !== undefined\n ? expandable?.(rowData)\n : Boolean(subTable?.table ?? subRows?.rows)\n\n const subRowsData = subRows?.rows(rowData)\n const subTableData = subTable?.table(rowData)\n\n const subPadding = subTable?.padding ?? subRows?.padding\n const subBgColor = subTable?.bgColor || subRows?.bgColor\n const resolvedSubBgColor = subBgColor\n ? resolveToThemeColor(subBgColor, theme)\n : undefined\n\n const showActionsCell = expandable ?? rowActions\n const expandSubProp = showActionsCell ? columns.length + 1 : columns.length\n\n const isExpandedRow = expandedRows.includes(rowIndex)\n\n return (\n <>\n <StyledRow\n $stripedColor={resolvedStripedColor}\n $rowColor={resolvedRowColor}\n $rowBorderColor={resolvedRowBorderColor}\n $clickableRow={!!clickableRow}\n $noRowBorderColor={isExpandedRow || hideBorder}\n onClick={() => clickableRow?.(rowData)}\n tabIndex={clickableRow && 0}\n >\n {columns.map((column, columnIndex) => {\n let cellContent: ReactNode\n if (column.cell) {\n cellContent = column.cell(rowData, rowIndex, column, rowIndex)\n }\n\n return (\n <StyledCell\n key={columnIndex}\n $rowPadding={rowPadding}\n $columnPadding={columnPadding}\n $minWidth={column.minWidth}\n $maxWidth={column.maxWidth}\n $noWrapContent={column.noWrapContent}\n $truncateContent={column.truncateContent}\n $hideOverflow={column.hideOverflow}\n >\n {cellContent}\n </StyledCell>\n )\n })}\n\n {(showActionsCell ?? showActions) && (\n <RowActions\n canExpandRow={canExpandRow}\n rowActions={rowActions}\n rowData={rowData}\n isExpanded={isExpandedRow}\n toggleExpansion={() => toggleRowExpansion(rowIndex)}\n />\n )}\n </StyledRow>\n {/**\n * Rendering subTable and/or subRows\n *\n * This could be extracted out and cleaned up\n * this section is for expanded rows only\n * Items rendered here wont show unless expanded\n */}\n\n {isExpandedRow && (\n <>\n {subRowsData &&\n isReactElement(subRowsData) &&\n cloneElement(subRowsData, { rowPadding, columnPadding })}\n\n {subRowsData &&\n isMappedReactElement(subRowsData) &&\n subRowsData.map((row) =>\n cloneElement(row, { rowPadding, showActions: showActionsCell }),\n )}\n\n {subTableData && (\n <StyledSubTableCell\n $rowBorderColor={resolvedRowBorderColor}\n colSpan={expandSubProp}\n $bgColor={resolvedSubBgColor}\n $padding={subPadding}\n >\n {cloneElement(subTableData, { rowPadding, columnPadding })}\n </StyledSubTableCell>\n )}\n </>\n )}\n </>\n )\n}\n"]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { TransientProps } from 'utils/utilTypes';
|
|
2
|
-
import { type Color } from '../../theme';
|
|
3
2
|
import { TableStylesProps, type TableProps } from '../types';
|
|
4
3
|
type StyledTableProps = {
|
|
5
4
|
$roundedTable: TableProps<unknown>['roundedTable'];
|
|
@@ -9,9 +8,9 @@ export declare const StyledHeaderCell: import("styled-components/dist/types").IS
|
|
|
9
8
|
export declare const StyledCell: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").TdHTMLAttributes<HTMLTableDataCellElement>, HTMLTableDataCellElement>, TransientProps<TableStylesProps>>> & string;
|
|
10
9
|
export declare const StyledRow: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLTableRowElement>, HTMLTableRowElement>, TransientProps<TableStylesProps>>> & string;
|
|
11
10
|
type StyledSubTableCellProps = {
|
|
12
|
-
$bgColor?:
|
|
11
|
+
$bgColor?: string;
|
|
13
12
|
$padding?: string | undefined;
|
|
14
|
-
$rowBorderColor?:
|
|
13
|
+
$rowBorderColor?: string;
|
|
15
14
|
};
|
|
16
15
|
type StyledSubInnerCellProps = {
|
|
17
16
|
$padding?: string | undefined;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { darken } from 'polished';
|
|
2
2
|
import styled, { css } from 'styled-components';
|
|
3
3
|
import { fontStyleMapping } from '../../Text/fontMapping';
|
|
4
|
-
import { theme } from '../../theme';
|
|
5
4
|
import { focusOutlineStyle } from '../../utils/focusOutline';
|
|
6
5
|
const isString = (value) => typeof value === 'string';
|
|
7
6
|
export const StyledTable = styled.table `
|
|
@@ -9,7 +8,7 @@ export const StyledTable = styled.table `
|
|
|
9
8
|
height: 100%;
|
|
10
9
|
border-collapse: collapse;
|
|
11
10
|
overflow: auto;
|
|
12
|
-
background: ${theme.
|
|
11
|
+
background: ${({ theme }) => theme.color.surface.base[100]};
|
|
13
12
|
border-spacing: 30px;
|
|
14
13
|
|
|
15
14
|
${({ $roundedTable }) => $roundedTable &&
|
|
@@ -19,8 +18,8 @@ export const StyledTable = styled.table `
|
|
|
19
18
|
`}
|
|
20
19
|
`;
|
|
21
20
|
export const StyledHeaderCell = styled.th `
|
|
22
|
-
background: ${theme.
|
|
23
|
-
border-bottom: ${({ $hasKeyline }) => $hasKeyline ? `1px solid ${theme.
|
|
21
|
+
background: ${({ theme }) => theme.color.surface.base[100]};
|
|
22
|
+
border-bottom: ${({ $hasKeyline, theme }) => $hasKeyline ? `1px solid ${theme.color.surface.base[900]}` : 'none'};
|
|
24
23
|
position: ${({ $fixedHeader }) => ($fixedHeader ? 'sticky' : 'auto')};
|
|
25
24
|
top: 0;
|
|
26
25
|
z-index: 2;
|
|
@@ -34,7 +33,7 @@ export const StyledHeaderCell = styled.th `
|
|
|
34
33
|
|
|
35
34
|
${({ $headerColor }) => $headerColor &&
|
|
36
35
|
css `
|
|
37
|
-
background: ${
|
|
36
|
+
background: ${$headerColor};
|
|
38
37
|
`}
|
|
39
38
|
|
|
40
39
|
${({ $headerHeight }) => $headerHeight &&
|
|
@@ -95,39 +94,39 @@ export const StyledCell = styled.td `
|
|
|
95
94
|
|
|
96
95
|
${({ $rowActionsBgColor }) => $rowActionsBgColor &&
|
|
97
96
|
css `
|
|
98
|
-
background: ${
|
|
97
|
+
background: ${$rowActionsBgColor};
|
|
99
98
|
`}
|
|
100
99
|
`;
|
|
101
100
|
export const StyledRow = styled.tr `
|
|
102
|
-
background: ${theme.
|
|
101
|
+
background: ${({ theme }) => theme.color.surface.base[300]};
|
|
103
102
|
|
|
104
103
|
${({ $rowBorderColor, $noRowBorderColor }) => $rowBorderColor &&
|
|
105
104
|
!$noRowBorderColor &&
|
|
106
105
|
css `
|
|
107
|
-
border-bottom: 1px solid ${
|
|
106
|
+
border-bottom: 1px solid ${$rowBorderColor};
|
|
108
107
|
`}
|
|
109
108
|
|
|
110
109
|
${({ $rowColor }) => $rowColor &&
|
|
111
110
|
css `
|
|
112
|
-
background: ${
|
|
111
|
+
background: ${$rowColor};
|
|
113
112
|
`}
|
|
114
113
|
|
|
115
114
|
${({ $stripedColor }) => $stripedColor &&
|
|
116
115
|
css `
|
|
117
116
|
&:nth-child(even) {
|
|
118
|
-
background: ${
|
|
117
|
+
background: ${$stripedColor};
|
|
119
118
|
}
|
|
120
119
|
`}
|
|
121
120
|
|
|
122
|
-
${({ $clickableRow, $rowColor }) => $clickableRow &&
|
|
121
|
+
${({ $clickableRow, $rowColor, theme }) => $clickableRow &&
|
|
123
122
|
css `
|
|
124
123
|
cursor: pointer;
|
|
125
124
|
&:hover {
|
|
126
|
-
background: ${darken(0.1,
|
|
125
|
+
background: ${darken(0.1, $rowColor ?? theme.color.surface.base[300])};
|
|
127
126
|
}
|
|
128
127
|
&:focus-visible {
|
|
129
128
|
${focusOutlineStyle}
|
|
130
|
-
background: ${darken(0.1,
|
|
129
|
+
background: ${darken(0.1, $rowColor ?? theme.color.surface.base[300])};
|
|
131
130
|
}
|
|
132
131
|
`}
|
|
133
132
|
`;
|
|
@@ -136,10 +135,10 @@ export const StyledSubTableCell = styled.td `
|
|
|
136
135
|
|
|
137
136
|
${({ $rowBorderColor }) => $rowBorderColor &&
|
|
138
137
|
css `
|
|
139
|
-
border-bottom: 1px solid ${
|
|
138
|
+
border-bottom: 1px solid ${$rowBorderColor};
|
|
140
139
|
`}
|
|
141
140
|
|
|
142
|
-
${({ $bgColor }) => $bgColor && `background-color: ${
|
|
141
|
+
${({ $bgColor }) => $bgColor && `background-color: ${$bgColor};`}
|
|
143
142
|
`;
|
|
144
143
|
export const StyledSubInnerCell = styled.div `
|
|
145
144
|
padding: ${({ $padding }) => $padding ?? '12px 0'};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commonComponents.js","sourceRoot":"","sources":["../../../src/Table/components/commonComponents.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AAE/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AACzD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"commonComponents.js","sourceRoot":"","sources":["../../../src/Table/components/commonComponents.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AAE/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAO5D,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAA;AAE/E,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAkB;;;;;gBAKzC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;;;IAGxD,CAAC,EAAE,aAAa,EAAE,EAAE,EAAE,CACtB,aAAa;IACb,GAAG,CAAA;uBACgB,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,aAA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A;;;sBAGe,MAAM,CAAC,GAAG,EAAE,SAAS,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;;;UAGnE,iBAAiB;sBACL,MAAM,CAAC,GAAG,EAAE,SAAS,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;;KAExE;CACJ,CAAA;AAYD,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,EAAE,CAAyB;aACvD,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,QAAQ,IAAI,QAAQ;;IAE/C,CAAC,EAAE,eAAe,EAAE,EAAE,EAAE,CACxB,eAAe;IACf,GAAG,CAAA;iCAC0B,eAAe;KAC3C;;IAED,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,QAAQ,IAAI,qBAAqB,QAAQ,GAAG;CACjE,CAAA;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAyB;aACxD,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,QAAQ,IAAI,QAAQ;CAClD,CAAA","sourcesContent":["import { darken } from 'polished'\nimport styled, { css } from 'styled-components'\nimport { TransientProps } from 'utils/utilTypes'\nimport { fontStyleMapping } from '../../Text/fontMapping'\nimport { focusOutlineStyle } from '../../utils/focusOutline'\nimport { TableStylesProps, type TableProps } from '../types'\n\ntype StyledTableProps = {\n $roundedTable: TableProps<unknown>['roundedTable']\n}\n\nconst isString = (value: unknown): value is string => typeof value === 'string'\n\nexport const StyledTable = styled.table<StyledTableProps>`\n width: 100%;\n height: 100%;\n border-collapse: collapse;\n overflow: auto;\n background: ${({ theme }) => theme.color.surface.base[100]};\n border-spacing: 30px;\n\n ${({ $roundedTable }) =>\n $roundedTable &&\n css`\n border-radius: ${isString($roundedTable) ? $roundedTable : '16px'};\n overflow: hidden;\n `}\n`\n\nexport const StyledHeaderCell = styled.th<TransientProps<TableStylesProps>>`\n background: ${({ theme }) => theme.color.surface.base[100]};\n border-bottom: ${({ $hasKeyline, theme }) =>\n $hasKeyline ? `1px solid ${theme.color.surface.base[900]}` : 'none'};\n position: ${({ $fixedHeader }) => ($fixedHeader ? 'sticky' : 'auto')};\n top: 0;\n z-index: 2;\n text-align: left;\n vertical-align: bottom;\n ${fontStyleMapping.label};\n padding-left: 8px;\n padding-right: 8px;\n padding-top: 8px;\n padding-bottom: 8px;\n\n ${({ $headerColor }) =>\n $headerColor &&\n css`\n background: ${$headerColor};\n `}\n\n ${({ $headerHeight }) =>\n $headerHeight &&\n css`\n height: ${$headerHeight};\n `}\n\n ${({ $maxWidth }) =>\n $maxWidth &&\n css`\n max-width: ${$maxWidth};\n `}\n\n ${({ $minWidth }) =>\n $minWidth &&\n css`\n min-width: ${$minWidth};\n `}\n \n ${({ $columnPadding }) =>\n $columnPadding &&\n css`\n padding-left: ${$columnPadding};\n padding-right: ${$columnPadding};\n `};\n`\n\nexport const StyledCell = styled.td<TransientProps<TableStylesProps>>`\n vertical-align: middle;\n padding-left: ${({ $columnPadding }) => $columnPadding ?? '8px'};\n padding-right: ${({ $columnPadding }) => $columnPadding ?? '8px'};\n padding-top: ${({ $rowPadding }) => $rowPadding ?? '8px'};\n padding-bottom: ${({ $rowPadding }) => $rowPadding ?? '8px'};\n\n ${({ $hideOverflow }) =>\n $hideOverflow &&\n css`\n overflow: hidden;\n `};\n\n ${({ $noWrapContent }) =>\n $noWrapContent &&\n css`\n white-space: nowrap;\n `};\n\n ${({ $truncateContent }) =>\n $truncateContent &&\n css`\n overflow: hidden;\n white-space: nowrap;\n text-overflow: ellipsis;\n `};\n\n ${({ $stickyCell }) =>\n $stickyCell &&\n css`\n position: sticky;\n right: 0;\n `};\n\n ${({ $maxWidth }) =>\n $maxWidth &&\n css`\n max-width: ${$maxWidth};\n `}\n\n ${({ $rowActionsBgColor }) =>\n $rowActionsBgColor &&\n css`\n background: ${$rowActionsBgColor};\n `}\n`\n\nexport const StyledRow = styled.tr<TransientProps<TableStylesProps>>`\n background: ${({ theme }) => theme.color.surface.base[300]};\n\n ${({ $rowBorderColor, $noRowBorderColor }) =>\n $rowBorderColor &&\n !$noRowBorderColor &&\n css`\n border-bottom: 1px solid ${$rowBorderColor};\n `}\n\n ${({ $rowColor }) =>\n $rowColor &&\n css`\n background: ${$rowColor};\n `}\n\n ${({ $stripedColor }) =>\n $stripedColor &&\n css`\n &:nth-child(even) {\n background: ${$stripedColor};\n }\n `}\n\n ${({ $clickableRow, $rowColor, theme }) =>\n $clickableRow &&\n css`\n cursor: pointer;\n &:hover {\n background: ${darken(0.1, $rowColor ?? theme.color.surface.base[300])};\n }\n &:focus-visible {\n ${focusOutlineStyle}\n background: ${darken(0.1, $rowColor ?? theme.color.surface.base[300])};\n }\n `}\n`\n\ntype StyledSubTableCellProps = {\n $bgColor?: string\n $padding?: string | undefined\n $rowBorderColor?: string\n}\n\ntype StyledSubInnerCellProps = {\n $padding?: string | undefined\n}\n\nexport const StyledSubTableCell = styled.td<StyledSubTableCellProps>`\n padding: ${({ $padding }) => $padding ?? '12px 0'};\n\n ${({ $rowBorderColor }) =>\n $rowBorderColor &&\n css`\n border-bottom: 1px solid ${$rowBorderColor};\n `}\n\n ${({ $bgColor }) => $bgColor && `background-color: ${$bgColor};`}\n`\n\nexport const StyledSubInnerCell = styled.div<StyledSubInnerCellProps>`\n padding: ${({ $padding }) => $padding ?? '12px 0'};\n`\n"]}
|
package/dist/Table/types.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import React, { ReactElement, ReactNode } from 'react';
|
|
2
2
|
import { ButtonProps } from '../Button/Button';
|
|
3
3
|
import { IconStrictProps } from '../IconStrict';
|
|
4
|
-
import { Color } from '../theme';
|
|
5
4
|
import type { BoxSpacing, SingleSpacing } from './helper.types';
|
|
5
|
+
import { ColorTypes } from '../ThemeProvider/utils/colourMap';
|
|
6
6
|
export type TableStylesProps = {
|
|
7
7
|
hasKeyline?: boolean;
|
|
8
8
|
fixedHeader?: boolean;
|
|
9
9
|
headerHeight?: string;
|
|
10
|
-
stripedColor?:
|
|
10
|
+
stripedColor?: string;
|
|
11
11
|
stickyCell?: boolean;
|
|
12
|
-
headerColor?:
|
|
13
|
-
rowColor?:
|
|
14
|
-
rowBorderColor?:
|
|
15
|
-
rowActionsBgColor?:
|
|
12
|
+
headerColor?: string;
|
|
13
|
+
rowColor?: string;
|
|
14
|
+
rowBorderColor?: string;
|
|
15
|
+
rowActionsBgColor?: string;
|
|
16
16
|
minWidth?: string;
|
|
17
17
|
maxWidth?: string;
|
|
18
18
|
noWrapContent?: boolean;
|
|
@@ -41,7 +41,7 @@ export type RowActionElementOverride<T> = {
|
|
|
41
41
|
export type RowActions<T> = {
|
|
42
42
|
actions: RowAction<T>[];
|
|
43
43
|
minWidth?: string;
|
|
44
|
-
bgColor?:
|
|
44
|
+
bgColor?: ColorTypes;
|
|
45
45
|
};
|
|
46
46
|
type RowCellRenderer<T> = (row: T, rowIndex: number, column: TableColumn<T>, id: string | number) => React.ReactNode;
|
|
47
47
|
export interface TableColumn<T> {
|
|
@@ -54,12 +54,12 @@ export interface TableColumn<T> {
|
|
|
54
54
|
cell?: RowCellRenderer<T>;
|
|
55
55
|
}
|
|
56
56
|
type SubElementProps = {
|
|
57
|
-
bgColor?:
|
|
57
|
+
bgColor?: ColorTypes;
|
|
58
58
|
padding?: BoxSpacing;
|
|
59
59
|
margin?: BoxSpacing;
|
|
60
60
|
};
|
|
61
61
|
/** @template T - The type of data the table displays. */
|
|
62
|
-
interface CommonTableProps<T> {
|
|
62
|
+
interface CommonTableProps<T, ColorT = ColorTypes> {
|
|
63
63
|
/** Array of columns to display in the table. */
|
|
64
64
|
columns: TableColumn<T>[];
|
|
65
65
|
/** Sets the height of the header. */
|
|
@@ -69,15 +69,15 @@ interface CommonTableProps<T> {
|
|
|
69
69
|
/** If true, the table header will have a key line. */
|
|
70
70
|
hasKeyline?: boolean;
|
|
71
71
|
/** If present, the table rows will have alternating colors. */
|
|
72
|
-
stripedColor?:
|
|
72
|
+
stripedColor?: ColorT;
|
|
73
73
|
/** A function to determine if a row is expandable. */
|
|
74
74
|
expandable?: (rowData: T) => boolean;
|
|
75
75
|
/** The color for the table header. */
|
|
76
|
-
headerColor?:
|
|
76
|
+
headerColor?: ColorT;
|
|
77
77
|
/** The default color for each table row. */
|
|
78
|
-
rowColor?:
|
|
78
|
+
rowColor?: ColorT;
|
|
79
79
|
/** The default color for each table row border. */
|
|
80
|
-
rowBorderColor?:
|
|
80
|
+
rowBorderColor?: ColorT;
|
|
81
81
|
/** If true, the table will have rounded corners */
|
|
82
82
|
roundedTable?: true;
|
|
83
83
|
/** A React element to show when a row is expanded. */
|
|
@@ -121,7 +121,7 @@ export interface TableRowProps<T> extends CommonTableProps<T> {
|
|
|
121
121
|
showActions?: boolean;
|
|
122
122
|
hideBorder?: boolean;
|
|
123
123
|
}
|
|
124
|
-
export interface RowActionsProps<T> extends Pick<CommonTableProps<T>, 'expandable' | 'rowActions'> {
|
|
124
|
+
export interface RowActionsProps<T> extends Pick<CommonTableProps<T, string>, 'expandable' | 'rowActions'> {
|
|
125
125
|
rowData: T;
|
|
126
126
|
canExpandRow: boolean;
|
|
127
127
|
toggleExpansion: () => void;
|
|
@@ -136,11 +136,11 @@ type TableFooterColumnsProps<K> = {
|
|
|
136
136
|
*
|
|
137
137
|
* @default 'custard'
|
|
138
138
|
*/
|
|
139
|
-
rowColor?:
|
|
139
|
+
rowColor?: ColorTypes;
|
|
140
140
|
rowPadding?: SingleSpacing;
|
|
141
141
|
columnPadding?: SingleSpacing;
|
|
142
142
|
columns: TableColumn<K>[];
|
|
143
143
|
data: K;
|
|
144
144
|
};
|
|
145
|
-
export type TableHeaderProps<T> = CommonTableProps<T>;
|
|
145
|
+
export type TableHeaderProps<T> = CommonTableProps<T, string>;
|
|
146
146
|
export {};
|
package/dist/Table/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/Table/types.ts"],"names":[],"mappings":"","sourcesContent":["import React, { ReactElement, ReactNode } from 'react'\nimport { ButtonProps } from '../Button/Button'\nimport { IconStrictProps } from '../IconStrict'\nimport {
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/Table/types.ts"],"names":[],"mappings":"","sourcesContent":["import React, { ReactElement, ReactNode } from 'react'\nimport { ButtonProps } from '../Button/Button'\nimport { IconStrictProps } from '../IconStrict'\nimport type { BoxSpacing, SingleSpacing } from './helper.types'\nimport { ColorTypes } from '../ThemeProvider/utils/colourMap'\n\nexport type TableStylesProps = {\n hasKeyline?: boolean\n fixedHeader?: boolean\n headerHeight?: string\n stripedColor?: string\n stickyCell?: boolean\n headerColor?: string\n rowColor?: string\n rowBorderColor?: string\n rowActionsBgColor?: string\n minWidth?: string\n maxWidth?: string\n noWrapContent?: boolean\n truncateContent?: boolean\n rowPadding?: string\n columnPadding?: string\n hideOverflow?: boolean\n clickableRow?: boolean\n noRowBorderColor?: boolean\n}\n\nexport type Primitive = string | number | boolean | bigint\n\nexport type BaseRowAction<T> = {\n onClick: (rowData: T) => void\n showCondition?: (rowData: T) => boolean\n}\n\nexport type RowAction<T> =\n | RowActionButtonDefault<T>\n | RowActionElementOverride<T>\n\nexport type RowActionButtonDefault<T> = {\n iconButton?: Pick<\n IconStrictProps,\n 'size' | 'render' | 'iconColor' | 'backgroundColor' | 'id' | 'title'\n > & { tooltipText?: string }\n genericButton?: Pick<\n ButtonProps,\n | 'children'\n | 'loading'\n | 'disabled'\n | 'primary'\n | 'secondary'\n | 'fallbackStyle'\n | 'textBtn'\n | 'smallButton'\n | 'id'\n >\n} & BaseRowAction<T>\n\nexport type RowActionElementOverride<T> = {\n element: ReactElement<any>\n} & BaseRowAction<T>\n\nexport type RowActions<T> = {\n actions: RowAction<T>[]\n minWidth?: string\n bgColor?: ColorTypes\n}\n\ntype RowCellRenderer<T> = (\n row: T,\n rowIndex: number,\n column: TableColumn<T>,\n id: string | number,\n) => React.ReactNode\n\nexport interface TableColumn<T> {\n name?: string | number | React.ReactNode\n minWidth?: string\n maxWidth?: string\n noWrapContent?: boolean\n truncateContent?: boolean\n hideOverflow?: boolean\n cell?: RowCellRenderer<T>\n}\n\ntype SubElementProps = {\n bgColor?: ColorTypes\n padding?: BoxSpacing\n margin?: BoxSpacing\n}\n\n/** @template T - The type of data the table displays. */\ninterface CommonTableProps<T, ColorT = ColorTypes> {\n /** Array of columns to display in the table. */\n columns: TableColumn<T>[]\n /** Sets the height of the header. */\n headerHeight?: string\n /** If true, the table header will be fixed/sticky. */\n fixedHeader?: boolean\n /** If true, the table header will have a key line. */\n hasKeyline?: boolean\n /** If present, the table rows will have alternating colors. */\n stripedColor?: ColorT\n /** A function to determine if a row is expandable. */\n expandable?: (rowData: T) => boolean\n /** The color for the table header. */\n headerColor?: ColorT\n /** The default color for each table row. */\n rowColor?: ColorT\n /** The default color for each table row border. */\n rowBorderColor?: ColorT\n /** If true, the table will have rounded corners */\n roundedTable?: true\n /** A React element to show when a row is expanded. */\n subTable?: SubElementProps & {\n table: (rowData: T) => ReactElement<any>\n }\n /** Settings for sub rows. */\n subRows?: SubElementProps & {\n /** Function that returns a React element for the sub row. */\n rows: (rowData: T) => ReactElement<any> | ReactElement<any>[]\n }\n /** Function to apply to a row, to make the entire row clickable, useful for navigation. */\n clickableRow?: (rowData: T) => void\n /** Array of actions that can be performed on each row. */\n rowActions?: RowActions<T>\n /** The Y padding for each row. */\n rowPadding?: SingleSpacing\n /** The X padding for each row. */\n columnPadding?: SingleSpacing\n /** Hides the table header. Table defaults to always showing the header. */\n hideTableHeader?: boolean\n}\n\nexport interface TableProps<T, K = undefined> extends CommonTableProps<T> {\n /** Array of data to be displayed in the table. */\n data: T[]\n\n footer?: TableFooter<K>\n\n /** The text to show when there is no available data to map through. */\n noDataContent?: ReactNode\n}\n\n/**\n * The type of the footer prop in the Table component.\n * It can either be an array of columns and data, or a React element.\n *\n * For columns, the columns and data will be passed to each column.cell component to generate the footer.\n * For a React element, it will render that as the table footer.\n */\nexport type TableFooter<K> =\n | TableFooterColumnsProps<K>\n | TableFooterElementProps<K>\n\nexport interface TableRowProps<T> extends CommonTableProps<T> {\n rowData: T\n rowIndex: number\n showActions?: boolean\n hideBorder?: boolean\n}\n\nexport interface RowActionsProps<T>\n extends Pick<CommonTableProps<T, string>, 'expandable' | 'rowActions'> {\n rowData: T\n canExpandRow: boolean\n toggleExpansion: () => void\n isExpanded?: boolean\n}\n\ntype TableFooterElementProps<K> = {\n element: ReactElement<K>\n}\n\ntype TableFooterColumnsProps<K> = {\n /**\n * Row color of the footer.\n *\n * @default 'custard'\n */\n rowColor?: ColorTypes\n rowPadding?: SingleSpacing\n columnPadding?: SingleSpacing\n columns: TableColumn<K>[]\n data: K\n}\n\nexport type TableHeaderProps<T> = CommonTableProps<T, string>\n"]}
|
|
@@ -50,7 +50,7 @@ export const legacyColorMap = {
|
|
|
50
50
|
liquorice: 'color.text.base', // palette.secondary.100
|
|
51
51
|
boba: 'color.text.contrast', // palette.secondary.120
|
|
52
52
|
// Core Tertiary
|
|
53
|
-
cream:
|
|
53
|
+
cream: 'color.surface.base.000', // palette.neutral.000
|
|
54
54
|
coconut: 'color.surface.base.100', // palette.neutral.010
|
|
55
55
|
mascarpone: 'color.surface.base.200', // palette.neutral.020
|
|
56
56
|
custard: 'color.surface.base.300', // palette.neutral.040
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"colourMap.js","sourceRoot":"","sources":["../../../src/ThemeProvider/utils/colourMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,uDAAuD,CAAA;AAGrF,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAkBzD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,KAAiB,EACjB,KAAY,EACJ,EAAE;IACV,MAAM,UAAU,GAAG,YAAY,CAAC,KAAK,CAAC,CAAA;IACtC,OAA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AAuB;IAClE,UAAU,EAAE,6BAA6B,EAAE,uBAAuB;IAClE,KAAK,EAAE,6BAA6B,EAAE,uBAAuB;IAC7D,IAAI,EAAE,6BAA6B,EAAE,uBAAuB;IAC5D,KAAK,EAAE,2BAA2B,EAAE,qBAAqB;IACzD,QAAQ,EAAE,2BAA2B,EAAE,qBAAqB;IAC5D,SAAS,EAAE,eAAe,EAAE,gBAAgB;IAE5C,4BAA4B;IAC5B,gBAAgB,EAAE,6BAA6B;IAC/C,QAAQ,EAAE,wBAAwB;IAClC,MAAM,EAAE,mBAAmB;IAC3B,CAAC,EAAE,oBAAoB,EAAE,6CAA6C;IACtE,QAAQ,EAAE,qBAAqB;IAC/B,QAAQ,EAAE,qBAAqB;IAC/B,IAAI,EAAE,qBAAqB,EAAE,gDAAgD;IAC7E,MAAM,EAAE,mBAAmB;IAC3B,QAAQ,EAAE,qBAAqB;IAC/B,OAAO,EAAE,oBAAoB;IAC7B,GAAG,EAAE,gBAAgB;IACrB,QAAQ,EAAE,qBAAqB;CACvB,CAAA","sourcesContent":["import * as designTokens from '@mrshmllw/smores-foundations/build/web/variables.json'\nimport { Color } from '../../theme'\nimport { Theme } from '../ThemeProvider'\nimport { getFromObject } from '../../utils/getFromObject'\n\ntype Flatten<T, Prefix extends string = ''> = {\n [K in keyof T & string]: T[K] extends Record<string, any>\n ? Flatten<T[K], `${Prefix}${K}.`>\n : `${Prefix}${K}`\n}[keyof T & string]\n\ntype Prettify<T> = {\n [K in keyof T]: T[K]\n} & {}\n\nexport type NewColor = Prettify<\n Flatten<Pick<typeof designTokens, 'color' | 'extended1' | 'thirdParty'>>\n>\n\nexport type ColorTypes = Color | NewColor\n\nexport const resolveToThemeColor = (\n color: ColorTypes,\n theme: Theme,\n): string => {\n const colourPath = getColorPath(color)\n return getFromObject({\n obj: theme,\n path: colourPath,\n })\n}\n\n// a function that returns a flattened dot notation string path to access the color value\nexport const getColorPath = (color: ColorTypes) => {\n return color in legacyColorMap\n ? legacyColorMap[color as keyof typeof legacyColorMap]\n : color\n}\n\n// a function that returns the design token color paths as a comma-separated string\nexport const formatDesignTokenColor = (): string => {\n const { color, extended1, thirdParty } = designTokens\n const colors = { color, extended1, thirdParty }\n\n if (colors === null) {\n return ''\n }\n\n const result: string[] = []\n const destructureNestedObject = (obj: any, currentPath: string) => {\n for (const key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n const value = obj[key]\n const newPath = currentPath ? `${currentPath}.${key}` : key\n if (typeof value === 'object' && value !== null) {\n destructureNestedObject(value, newPath)\n } else {\n result.push(newPath)\n }\n }\n }\n }\n destructureNestedObject(colors, '')\n return result.join(', ')\n}\n\n// old colour name → new colour path // base token value\nexport const legacyColorMap: Record<Color, NewColor> = {\n fairyFloss: 'color.surface.brand.100', // palette.primary.040\n bubblegum: 'color.surface.brand.200', // palette.primary.060\n marshmallowPink: 'color.surface.brand.300', // palette.primary.100\n lollipop: 'color.surface.brand.400', // palatte.primary.120\n\n // Core Secondary\n chia: 'color.feedback.inactive.100', // palette.secondary.040\n sesame: 'color.text.subtle', // palette.secondary.060\n liquorice: 'color.text.base', // palette.secondary.100\n boba: 'color.text.contrast', // palette.secondary.120\n\n // Core Tertiary\n cream:
|
|
1
|
+
{"version":3,"file":"colourMap.js","sourceRoot":"","sources":["../../../src/ThemeProvider/utils/colourMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,uDAAuD,CAAA;AAGrF,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAkBzD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,KAAiB,EACjB,KAAY,EACJ,EAAE;IACV,MAAM,UAAU,GAAG,YAAY,CAAC,KAAK,CAAC,CAAA;IACtC,OAAO,aAAa,CAAC;QACnB,GAAG,EAAE,KAAK;QACV,IAAI,EAAE,UAAU;KACjB,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,yFAAyF;AACzF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC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AA2B,EAAE,qBAAqB;IACzD,QAAQ,EAAE,2BAA2B,EAAE,qBAAqB;IAC5D,SAAS,EAAE,eAAe,EAAE,gBAAgB;IAE5C,4BAA4B;IAC5B,gBAAgB,EAAE,6BAA6B;IAC/C,QAAQ,EAAE,wBAAwB;IAClC,MAAM,EAAE,mBAAmB;IAC3B,CAAC,EAAE,oBAAoB,EAAE,6CAA6C;IACtE,QAAQ,EAAE,qBAAqB;IAC/B,QAAQ,EAAE,qBAAqB;IAC/B,IAAI,EAAE,qBAAqB,EAAE,gDAAgD;IAC7E,MAAM,EAAE,mBAAmB;IAC3B,QAAQ,EAAE,qBAAqB;IAC/B,OAAO,EAAE,oBAAoB;IAC7B,GAAG,EAAE,gBAAgB;IACrB,QAAQ,EAAE,qBAAqB;CACvB,CAAA","sourcesContent":["import * as designTokens from '@mrshmllw/smores-foundations/build/web/variables.json'\nimport { Color } from '../../theme'\nimport { Theme } from '../ThemeProvider'\nimport { getFromObject } from '../../utils/getFromObject'\n\ntype Flatten<T, Prefix extends string = ''> = {\n [K in keyof T & string]: T[K] extends Record<string, any>\n ? Flatten<T[K], `${Prefix}${K}.`>\n : `${Prefix}${K}`\n}[keyof T & string]\n\ntype Prettify<T> = {\n [K in keyof T]: T[K]\n} & {}\n\nexport type NewColor = Prettify<\n Flatten<Pick<typeof designTokens, 'color' | 'extended1' | 'thirdParty'>>\n>\n\nexport type ColorTypes = Color | NewColor\n\nexport const resolveToThemeColor = (\n color: ColorTypes,\n theme: Theme,\n): string => {\n const colourPath = getColorPath(color)\n return getFromObject({\n obj: theme,\n path: colourPath,\n })\n}\n\n// a function that returns a flattened dot notation string path to access the color value\nexport const getColorPath = (color: ColorTypes) => {\n return color in legacyColorMap\n ? legacyColorMap[color as keyof typeof legacyColorMap]\n : color\n}\n\n// a function that returns the design token color paths as a comma-separated string\nexport const formatDesignTokenColor = (): string => {\n const { color, extended1, thirdParty } = designTokens\n const colors = { color, extended1, thirdParty }\n\n if (colors === null) {\n return ''\n }\n\n const result: string[] = []\n const destructureNestedObject = (obj: any, currentPath: string) => {\n for (const key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n const value = obj[key]\n const newPath = currentPath ? `${currentPath}.${key}` : key\n if (typeof value === 'object' && value !== null) {\n destructureNestedObject(value, newPath)\n } else {\n result.push(newPath)\n }\n }\n }\n }\n destructureNestedObject(colors, '')\n return result.join(', ')\n}\n\n// old colour name → new colour path // base token value\nexport const legacyColorMap: Record<Color, NewColor> = {\n fairyFloss: 'color.surface.brand.100', // palette.primary.040\n bubblegum: 'color.surface.brand.200', // palette.primary.060\n marshmallowPink: 'color.surface.brand.300', // palette.primary.100\n lollipop: 'color.surface.brand.400', // palatte.primary.120\n\n // Core Secondary\n chia: 'color.feedback.inactive.100', // palette.secondary.040\n sesame: 'color.text.subtle', // palette.secondary.060\n liquorice: 'color.text.base', // palette.secondary.100\n boba: 'color.text.contrast', // palette.secondary.120\n\n // Core Tertiary\n cream: 'color.surface.base.000', // palette.neutral.000\n coconut: 'color.surface.base.100', // palette.neutral.010\n mascarpone: 'color.surface.base.200', // palette.neutral.020\n custard: 'color.surface.base.300', // palette.neutral.040\n\n // Brand Secondary\n feijoa: 'color.illustration.accent1.100', // palette.brand1.060\n spearmint: 'color.illustration.accent1.200', // palette.brand1.100\n macaroon: 'color.illustration.accent2.100', // palette.brand2.060\n blueberry: 'color.illustration.accent2.200', // palette.brand2.100\n pistachio: 'color.illustration.accent3.200', // palette.brand3.100\n matcha: 'color.illustration.accent3.100', // palette.brand3.060\n caramel: 'color.illustration.accent4.200', // palette.brand4.100\n peanut: 'color.illustration.accent4.100', // palette.brand4.060\n marzipan: 'color.illustration.neutral.400', // palette.neutral.100\n oatmeal: 'color.illustration.neutral.300', // palette.neutral.060\n satsuma: 'extended1.20', // extended1.020\n\n // Traffic light\n watermelon: 'color.feedback.negative.100', // palette.negative.020\n strawberry: 'color.feedback.negative.200', // palette.negative.100\n apple: 'color.feedback.positive.200', // palette.positive.100\n mint: 'color.feedback.positive.100', // palette.positive.020\n lemon: 'color.feedback.notice.200', // palette.notice.100\n sherbert: 'color.feedback.notice.100', // palette.notice.020\n tangerine: 'extended1.100', // extended1.100\n\n // Third-party brand colours\n compareTheMarket: 'thirdParty.compareTheMarket',\n confused: 'thirdParty.confusedCom',\n onfido: 'thirdParty.onfido',\n x: 'thirdParty.twitter', // x rebrand not yet reflected in foundations\n premfina: 'thirdParty.premfina',\n checkout: 'thirdParty.checkout',\n meta: 'thirdParty.facebook', // Meta rebrand not yet reflected in foundations\n stripe: 'thirdParty.stripe',\n intercom: 'thirdParty.intercom',\n ravelin: 'thirdParty.ravelin',\n rac: 'thirdParty.rac',\n hometree: 'thirdParty.hometree',\n} as const\n"]}
|