@accelint/design-toolkit 8.0.0 → 8.1.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/catalog-info.yaml +2 -2
- package/dist/components/flashcard/index.d.ts +57 -0
- package/dist/components/flashcard/index.js +4 -0
- package/dist/components/flashcard/index.js.map +1 -0
- package/dist/components/flashcard/styles.module.css +60 -0
- package/dist/components/flashcard/types.d.ts +13 -0
- package/dist/components/flashcard/types.js +2 -0
- package/dist/components/flashcard/types.js.map +1 -0
- package/dist/components/table/cell.js +1 -1
- package/dist/components/table/cell.js.map +1 -1
- package/dist/components/table/header-cell.js +1 -1
- package/dist/components/table/header-cell.js.map +1 -1
- package/dist/components/table/index.d.ts +1 -1
- package/dist/components/table/index.js +1 -1
- package/dist/components/table/index.js.map +1 -1
- package/dist/components/table/styles.module.css +6 -3
- package/dist/components/table/types.d.ts +32 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -1
- package/dist/metafile-esm.json +1 -1
- package/package.json +5 -4
package/catalog-info.yaml
CHANGED
|
@@ -13,14 +13,14 @@ metadata:
|
|
|
13
13
|
|
|
14
14
|
accelint_biome-config@1.0.2, accelint_bus@3.0.0,
|
|
15
15
|
accelint_constellation-tracker@1.0.1, accelint_core@0.5.0,
|
|
16
|
-
accelint_design-foundation@1.0.0, accelint_geo@0.
|
|
16
|
+
accelint_design-foundation@1.0.0, accelint_geo@0.4.0, accelint_icons@2.1.0,
|
|
17
17
|
accelint_logger@0.1.2, accelint_prettier-config@0.2.0,
|
|
18
18
|
accelint_temporal@0.1.2, accelint_typescript-config@0.1.4,
|
|
19
19
|
accelint_vitest-config@0.1.5
|
|
20
20
|
annotations:
|
|
21
21
|
backstage.io/edit-url: https://github.com/gohypergiant/standard-toolkit/blob/main/packages/design-toolkit/catalog-info.yaml
|
|
22
22
|
backstage.io/techdocs-ref: dir:.
|
|
23
|
-
package/version: 8.
|
|
23
|
+
package/version: 8.1.0
|
|
24
24
|
github.com/project-slug: gohypergiant/standard-toolkit
|
|
25
25
|
links:
|
|
26
26
|
- url: https://github.com/gohypergiant/standard-toolkit/tree/main/packages/design-toolkit
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as react from 'react';
|
|
3
|
+
import { FlashcardProps, FlashcardComponentProps, FlashcardDetailsListProps } from './types.js';
|
|
4
|
+
import '../details-list/types.js';
|
|
5
|
+
import 'react-aria-components';
|
|
6
|
+
|
|
7
|
+
declare const FlashcardContext: react.Context<FlashcardProps>;
|
|
8
|
+
/**
|
|
9
|
+
* Example usage.
|
|
10
|
+
*
|
|
11
|
+
* ```tsx
|
|
12
|
+
* <Flashcard isLoading={isLoading} header="Identifier" subheader="DATA">
|
|
13
|
+
* <FlashcardHero />
|
|
14
|
+
* <FlashcardAdditionalData>
|
|
15
|
+
* {secondaryData}
|
|
16
|
+
* </FlashcardAdditionalData>
|
|
17
|
+
* <FlashcardDetailsList>
|
|
18
|
+
* {detail.map((detail) => (
|
|
19
|
+
* <Fragment key={detail.id}>
|
|
20
|
+
* <FlashcardDetailsLabel>
|
|
21
|
+
* {detail.label}
|
|
22
|
+
* </FlashcardDetailsLabel>
|
|
23
|
+
* <FlashcardDetailsValue>
|
|
24
|
+
* {detail.value}
|
|
25
|
+
* </FlashcardDetailsValue>
|
|
26
|
+
* </Fragment>
|
|
27
|
+
* ))}
|
|
28
|
+
* </FlashcardDetailsList>
|
|
29
|
+
* </Flashcard>
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
declare function Flashcard(props: FlashcardProps): react_jsx_runtime.JSX.Element;
|
|
33
|
+
declare namespace Flashcard {
|
|
34
|
+
var displayName: string;
|
|
35
|
+
}
|
|
36
|
+
declare function FlashcardHero(props: FlashcardComponentProps): react_jsx_runtime.JSX.Element;
|
|
37
|
+
declare namespace FlashcardHero {
|
|
38
|
+
var displayName: string;
|
|
39
|
+
}
|
|
40
|
+
declare function FlashcardAdditionalData(props: FlashcardComponentProps): react_jsx_runtime.JSX.Element | null;
|
|
41
|
+
declare namespace FlashcardAdditionalData {
|
|
42
|
+
var displayName: string;
|
|
43
|
+
}
|
|
44
|
+
declare function FlashcardDetailsList(props: FlashcardDetailsListProps): react_jsx_runtime.JSX.Element;
|
|
45
|
+
declare namespace FlashcardDetailsList {
|
|
46
|
+
var displayName: string;
|
|
47
|
+
}
|
|
48
|
+
declare function FlashcardDetailsLabel(props: FlashcardComponentProps): react_jsx_runtime.JSX.Element;
|
|
49
|
+
declare namespace FlashcardDetailsLabel {
|
|
50
|
+
var displayName: string;
|
|
51
|
+
}
|
|
52
|
+
declare function FlashcardDetailsValue(props: FlashcardComponentProps): react_jsx_runtime.JSX.Element;
|
|
53
|
+
declare namespace FlashcardDetailsValue {
|
|
54
|
+
var displayName: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { Flashcard, FlashcardAdditionalData, FlashcardContext, FlashcardDetailsLabel, FlashcardDetailsList, FlashcardDetailsValue, FlashcardHero };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import {jsx,jsxs}from'react/jsx-runtime';import {clsx}from'@accelint/design-foundation/lib/utils';import'client-only';import {createContext,useContext}from'react';import {Heading,Text}from'react-aria-components';import {DetailsList}from'../details-list/index.js';import {DetailsListLabel}from'../details-list/label.js';import {DetailsListValue}from'../details-list/value.js';import {Skeleton}from'../skeleton/index.js';import a from'./styles.module.css';const d=createContext({isLoading:false,header:"",subheader:""});function v(t){const{isLoading:l,header:s,subheader:e,children:i,className:m,...h}=t;return jsx(d.Provider,{value:{isLoading:l,header:s,subheader:e},children:jsx("div",{...h,className:clsx(a.container,m),children:i})})}v.displayName="Flashcard";function x(t){const{children:l,className:s,...e}=t,{isLoading:i,header:m,subheader:h}=useContext(d);return i?jsxs("div",{...e,className:clsx(a.hero,s,"gap-s"),children:[jsx(Skeleton,{className:a.skeleton,"data-testid":"hero-skeleton"}),jsx(Skeleton,{className:clsx(a.skeleton,a.half)})]}):jsxs("div",{...e,className:clsx(a.hero,s),children:[jsx(P,{className:a.header,children:m}),jsx(b,{className:a.subheader,children:h})]})}x.displayName="FlashcardHero";const P=Heading,b=Text;function y(t){const{children:l,className:s,...e}=t,{isLoading:i}=useContext(d);return i?null:jsx("div",{...e,className:clsx(a.data,s),children:l})}y.displayName="FlashcardAdditionalData";function g(t){const{children:l,className:s,...e}=t;return jsx(DetailsList,{...e,align:"justify",classNames:{list:clsx(a["details-list"],s)},children:l})}g.displayName="FlashcardDetailsList";function C(t){const{isLoading:l}=useContext(d),{className:s,children:e,...i}=t;return jsx(DetailsListLabel,{...i,className:clsx(a["details-label"],s),children:l?jsx(Skeleton,{className:clsx(a.skeleton,a.smaller)}):e})}C.displayName="FlashcardDetailsLabel";function k(t){const{isLoading:l}=useContext(d),{className:s,children:e,...i}=t;return jsx(DetailsListValue,{...i,className:clsx(a["details-value"],s),children:l?jsx(Skeleton,{className:clsx(a.skeleton,a.smaller)}):e})}k.displayName="FlashcardDetailsValue";export{v as Flashcard,y as FlashcardAdditionalData,d as FlashcardContext,C as FlashcardDetailsLabel,g as FlashcardDetailsList,k as FlashcardDetailsValue,x as FlashcardHero};//# sourceMappingURL=index.js.map
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/flashcard/index.tsx"],"names":["u","Flashcard","props","header","rest","jsx","FlashcardContext","isLoading","r","className","o","children","jsxs","c","styles","p","Skeleton","n","clsx","FlashcardHero","Text","F","N","DetailsList","f","DetailsListLabel","L","FlashcardDetailsLabel","DetailsListValue","D","FlashcardDetailsValue"],"mappings":"scA+BE,MAAA,CAAA,CAAAA,aAAA,CAAA,CAAA,SA2BK,aAASC,CAAUC,EAAuB,CAC/C,wBAAmB,CAAAC,EAAQ,CAAA,CAAA,KAAA,CAAA,kBAAqB,CAAA,CAAA,CAAA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CAAA,CAAA,CAAA,CAAA,WAE7B,CAAA,iCAEC,CAAE,CAAA,CAAA,CAAA,CAAA,KAAA,CAAAlB,WAAWE,CAAAA,CAAUE,UAAA,CAAA,CAAGT,CAAK,CAAA,CAAIF,SAEvCG,CAAAA,CAACuB,CAAAA,QAEC,CAAA,CAAA,CAAA,GAAA,CAAA,CAAA,CAAWV,EAAKJ,OAAON,GAAA,CAAAqB,gBAAA,CAAA,CAAA,GAAA,CAAA,CAAe,iBAErCtB,eACW,CAAA,CAAWW,EAAKJ,CAAAA,QAAO,CAAA,CAAUA,IAAO,CAAAG,QAAA,CAAA,CAAA,SAItD,CAEJP,IACAoB,CAAAA,CAAsB,CAAA,QAAA,CAAA,CAAA,CAAc,OAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,WAAA,CAAA,uBAAA","file":"index.js","sourcesContent":["/*\n * Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n'use client';\nimport { clsx } from '@accelint/design-foundation/lib/utils';\nimport 'client-only';\nimport { createContext, useContext } from 'react';\nimport { Heading, Text } from 'react-aria-components';\nimport { DetailsList } from '../details-list';\nimport { DetailsListLabel } from '../details-list/label';\nimport { DetailsListValue } from '../details-list/value';\nimport { Skeleton } from '../skeleton';\nimport styles from './styles.module.css';\nimport type {\n FlashcardComponentProps,\n FlashcardDetailsListProps,\n FlashcardProps,\n} from './types';\n\nexport const FlashcardContext = createContext<FlashcardProps>({\n isLoading: false,\n header: '',\n subheader: '',\n});\n\n/**\n * Example usage.\n *\n * ```tsx\n * <Flashcard isLoading={isLoading} header=\"Identifier\" subheader=\"DATA\">\n * <FlashcardHero />\n * <FlashcardAdditionalData>\n * {secondaryData}\n * </FlashcardAdditionalData>\n * <FlashcardDetailsList>\n * {detail.map((detail) => (\n * <Fragment key={detail.id}>\n * <FlashcardDetailsLabel>\n * {detail.label}\n * </FlashcardDetailsLabel>\n * <FlashcardDetailsValue>\n * {detail.value}\n * </FlashcardDetailsValue>\n * </Fragment>\n * ))}\n * </FlashcardDetailsList>\n * </Flashcard>\n * ```\n */\nexport function Flashcard(props: FlashcardProps) {\n const { isLoading, header, subheader, children, className, ...rest } = props;\n\n return (\n <FlashcardContext.Provider value={{ isLoading, header, subheader }}>\n <div {...rest} className={clsx(styles.container, className)}>\n {children}\n </div>\n </FlashcardContext.Provider>\n );\n}\nFlashcard.displayName = 'Flashcard';\n\nexport function FlashcardHero(props: FlashcardComponentProps) {\n const { children, className, ...rest } = props;\n const { isLoading, header, subheader } = useContext(FlashcardContext);\n\n if (isLoading) {\n return (\n <div {...rest} className={clsx(styles.hero, className, 'gap-s')}>\n <Skeleton className={styles.skeleton} data-testid='hero-skeleton' />\n <Skeleton className={clsx(styles.skeleton, styles.half)} />\n </div>\n );\n }\n\n return (\n <div {...rest} className={clsx(styles.hero, className)}>\n <FlashcardHeader className={styles.header}>{header}</FlashcardHeader>\n <FlashcardSubheader className={styles.subheader}>\n {subheader}\n </FlashcardSubheader>\n </div>\n );\n}\nFlashcardHero.displayName = 'FlashcardHero';\n\nconst FlashcardHeader = Heading;\nconst FlashcardSubheader = Text;\n\nexport function FlashcardAdditionalData(props: FlashcardComponentProps) {\n const { children, className, ...rest } = props;\n const { isLoading } = useContext(FlashcardContext);\n\n // While loading, don't display.\n if (isLoading) {\n return null;\n }\n\n return (\n <div {...rest} className={clsx(styles.data, className)}>\n {children}\n </div>\n );\n}\nFlashcardAdditionalData.displayName = 'FlashcardAdditionalData';\n\nexport function FlashcardDetailsList(props: FlashcardDetailsListProps) {\n const { children, className, ...rest } = props;\n return (\n <DetailsList\n {...rest}\n align='justify'\n classNames={{ list: clsx(styles['details-list'], className) }}\n >\n {children}\n </DetailsList>\n );\n}\nFlashcardDetailsList.displayName = 'FlashcardDetailsList';\n\nexport function FlashcardDetailsLabel(props: FlashcardComponentProps) {\n const { isLoading } = useContext(FlashcardContext);\n const { className, children, ...rest } = props;\n return (\n <DetailsListLabel\n {...rest}\n className={clsx(styles['details-label'], className)}\n >\n {isLoading ? (\n <Skeleton className={clsx(styles.skeleton, styles.smaller)} />\n ) : (\n children\n )}\n </DetailsListLabel>\n );\n}\nFlashcardDetailsLabel.displayName = 'FlashcardDetailsLabel';\n\nexport function FlashcardDetailsValue(props: FlashcardComponentProps) {\n const { isLoading } = useContext(FlashcardContext);\n const { className, children, ...rest } = props;\n return (\n <DetailsListValue\n {...rest}\n className={clsx(styles['details-value'], className)}\n >\n {isLoading ? (\n <Skeleton className={clsx(styles.skeleton, styles.smaller)} />\n ) : (\n children\n )}\n </DetailsListValue>\n );\n}\nFlashcardDetailsValue.displayName = 'FlashcardDetailsValue';\n"]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at https://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
@reference '../../index.module.css';
|
|
14
|
+
|
|
15
|
+
@layer components.l1 {
|
|
16
|
+
.container {
|
|
17
|
+
@apply rounded-medium font-display outline-interactive-hover outline;
|
|
18
|
+
|
|
19
|
+
min-width: 128px;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.hero {
|
|
23
|
+
@apply mb-s bg-surface-muted p-s flex flex-col;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.header {
|
|
27
|
+
@apply fg-primary-bold text-body-m;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.subheader {
|
|
31
|
+
@apply fg-primary-muted text-body-xs;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.data {
|
|
35
|
+
@apply fg-primary-muted px-s text-body-xs;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.details-list {
|
|
39
|
+
@apply p-s pb-s text-body-xs;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.details-label {
|
|
43
|
+
@apply fg-primary-muted nth-of-type-[n+6]:hidden;
|
|
44
|
+
}
|
|
45
|
+
.details-value {
|
|
46
|
+
@apply fg-primary-bold nth-of-type-[n+6]:hidden;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.skeleton {
|
|
50
|
+
@apply min-h-[8px] py-0;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.half {
|
|
54
|
+
@apply max-w-1/2;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.smaller {
|
|
58
|
+
@apply my-xxs;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PropsWithChildren, ComponentPropsWithRef } from 'react';
|
|
2
|
+
import { DetailsListProps } from '../details-list/types.js';
|
|
3
|
+
import 'react-aria-components';
|
|
4
|
+
|
|
5
|
+
type FlashcardComponentProps = PropsWithChildren & ComponentPropsWithRef<'div'>;
|
|
6
|
+
type FlashcardProps = FlashcardComponentProps & {
|
|
7
|
+
isLoading?: boolean;
|
|
8
|
+
header: string;
|
|
9
|
+
subheader: string;
|
|
10
|
+
};
|
|
11
|
+
type FlashcardDetailsListProps = FlashcardComponentProps & Partial<DetailsListProps>;
|
|
12
|
+
|
|
13
|
+
export type { FlashcardComponentProps, FlashcardDetailsListProps, FlashcardProps };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"types.js"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {jsx}from'react/jsx-runtime';import {clsx}from'@accelint/design-foundation/lib/utils';import {flexRender}from'@tanstack/react-table';import {useContext}from'react';import {HeaderColumnAction}from'./constants/table.js';import {TableContext}from'./context.js';import
|
|
1
|
+
import {jsx}from'react/jsx-runtime';import {clsx}from'@accelint/design-foundation/lib/utils';import {flexRender}from'@tanstack/react-table';import {useContext}from'react';import {HeaderColumnAction}from'./constants/table.js';import {TableContext}from'./context.js';import o from'./styles.module.css';function S({children:t,ref:m,className:r,cell:e,...l}){const{columnSelection:n,persistNumerals:s}=useContext(TableContext),i=e?.column.id===HeaderColumnAction.NUMERAL,c=e?.column.id===n,p=i&&!s;return jsx("td",{...l,ref:m,className:clsx(o.cell,p&&o.hideInRow,r),"data-selected":c||null,style:{width:e?.column.getSize()},children:t||e&&flexRender(e.column.columnDef.cell,e.getContext())})}export{S as TableCell};//# sourceMappingURL=cell.js.map
|
|
2
2
|
//# sourceMappingURL=cell.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/table/cell.tsx"],"names":["TableCell","children","
|
|
1
|
+
{"version":3,"sources":["../../../src/components/table/cell.tsx"],"names":["TableCell","children","cell","isNumeral","isSelected","notPersistNums","persistNumerals","jsx","T","rest","ref","styles","d"],"mappings":"4SAqBgBA,YACdC,QAEA,CAAA,CAAA,CAAA,GAAA,CAAA,CAAA,CAAA,SACAC,CACA,CAAA,CAAA,IACoB,CACpB,CAAA,CAAA,GAAM,CAAE,CAAA,CAAA,CAAA,KAAA,CAAA,eAAiB,CAAA,CAAA,CAAA,eACnBC,CAAAA,CAAYD,CAAAA,CAAAA,UAAM,kBAAO,EAAA,8BACzBE,CAAAA,WAA0B,EAAA,MAC1BC,CAAiBF,EAAAA,GAAcG,CAErC,OACEC,CAAAA,CAAC,OACEC,GAAA,CAAGC,IACJ,CAAA,CAAKC,oBAEI,CACPL,IAAAA,CAAAA,CAAkBM,CAAAA,IAAO,CAAA,CAAA,EAAA,CAAA,CAAA,SAG3B,CAAA,CAAA,CAAA,CAAA,eACA,CAAA,CAAA,EAAA,IAAS,CAAA,KAAOT,CAAAA,CAAM,KAAA,CAAA,CAAO,EAAA,MAAQ,CAAE,WAEtCD,QACqBC,CAAAA,CAAK,EAAA,CAAA,EAAAU,UAAA,CAAO,CAAA,CAAA,MAAA,CAAA,SAAqB,CAAA,IAAA,CAAA,CAAA,CAAA,UAG7D,EAAA,CAAA,CAAA,CAAA","file":"cell.js","sourcesContent":["// __private-exports\n/*\n * Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport { clsx } from '@accelint/design-foundation/lib/utils';\nimport { flexRender } from '@tanstack/react-table';\nimport { useContext } from 'react';\nimport { HeaderColumnAction } from './constants/table';\nimport { TableContext } from './context';\nimport styles from './styles.module.css';\nimport type { TableCellProps } from './types';\n\nexport function TableCell<T>({\n children,\n ref,\n className,\n cell,\n ...rest\n}: TableCellProps<T>) {\n const { columnSelection, persistNumerals } = useContext(TableContext);\n const isNumeral = cell?.column.id === HeaderColumnAction.NUMERAL;\n const isSelected = cell?.column.id === columnSelection;\n const notPersistNums = isNumeral && !persistNumerals;\n\n return (\n <td\n {...rest}\n ref={ref}\n className={clsx(\n styles.cell,\n notPersistNums && styles.hideInRow,\n className,\n )}\n data-selected={isSelected || null}\n style={{ width: cell?.column.getSize() }}\n >\n {children ||\n (cell && flexRender(cell.column.columnDef.cell, cell.getContext()))}\n </td>\n );\n}\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {clsx}from'@accelint/design-foundation/lib/utils';import {Kebab,ArrowDown,ArrowUp}from'@accelint/icons';import {flexRender}from'@tanstack/react-table';import {useContext,useState}from'react';import {Button}from'../button/index.js';import {Icon}from'../icon/index.js';import {Menu}from'../menu/index.js';import {MenuItem}from'../menu/item.js';import {MenuSeparator}from'../menu/separator.js';import {MenuTrigger}from'../menu/trigger.js';import {SortDirection,HeaderColumnAction,headerColumnActionValues}from'./constants/table.js';import {TableContext}from'./context.js';import M from'./styles.module.css';function N({header:e}){const{enableColumnReordering:m,enableSorting:u,moveColumnLeft:n,moveColumnRight:d,persistHeaderKebabMenu:g,setColumnSelection:a,manualSorting:c,handleSortChange:C,handleColumnReordering:
|
|
1
|
+
import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {clsx}from'@accelint/design-foundation/lib/utils';import {Kebab,ArrowDown,ArrowUp}from'@accelint/icons';import {flexRender}from'@tanstack/react-table';import {useContext,useState}from'react';import {Button}from'../button/index.js';import {Icon}from'../icon/index.js';import {Menu}from'../menu/index.js';import {MenuItem}from'../menu/item.js';import {MenuSeparator}from'../menu/separator.js';import {MenuTrigger}from'../menu/trigger.js';import {SortDirection,HeaderColumnAction,headerColumnActionValues}from'./constants/table.js';import {TableContext}from'./context.js';import M from'./styles.module.css';function N({header:e}){const{enableColumnReordering:m,enableSorting:u,moveColumnLeft:n,moveColumnRight:d,persistHeaderKebabMenu:g,setColumnSelection:a,manualSorting:c,handleSortChange:C,handleColumnReordering:f}=useContext(TableContext),[p,D]=useState(false),v=!g;if(headerColumnActionValues.includes(e.column.id)||!(u||m))return null;const r=e.column.getIsSorted();return jsx("div",{className:clsx(v&&M.hideInHeader),children:jsxs(MenuTrigger,{onOpenChange:l=>a(l?e.column.id:null),children:[jsx(Button,{variant:"icon","aria-label":"Menu",onHoverChange:D,children:jsxs(Icon,{children:[(!r||p)&&jsx(Kebab,{}),!p&&r===SortDirection.DESC&&jsx(ArrowDown,{}),!p&&r===SortDirection.ASC&&jsx(ArrowUp,{})]})}),jsxs(Menu,{children:[m&&jsxs(Fragment,{children:[jsx(MenuItem,{onAction:()=>{const l=e.column.getIndex();n(l),f?.(l);},isDisabled:e.column.getIsFirstColumn("center"),children:"Move Column Left"}),jsx(MenuItem,{onAction:()=>{const l=e.column.getIndex();d(l),f?.(l);},isDisabled:e.column.getIsLastColumn("center"),children:"Move Column Right"})]}),m&&u&&jsx(MenuSeparator,{}),u&&jsxs(Fragment,{children:[jsx(MenuItem,{onAction:()=>{c?C?.(e.column.id,SortDirection.ASC):e.column.toggleSorting(false);},isDisabled:r===SortDirection.ASC,children:"Sort Ascending"}),jsx(MenuItem,{onAction:()=>{c?C?.(e.column.id,SortDirection.DESC):e.column.toggleSorting(true);},isDisabled:r===SortDirection.DESC,children:"Sort Descending"}),jsx(MenuItem,{onAction:()=>{c?C?.(e.column.id,null):e.column.clearSorting();},isDisabled:!r,children:"Clear Sort"})]})]})]})})}function _({ref:e,children:m,className:u,header:n,...d}){const{columnSelection:g}=useContext(TableContext),a=n?.getContext(),c=n?.column.getIsSorted()===SortDirection.ASC?"ascending":n?.column.getIsSorted()===SortDirection.DESC?"descending":void 0;return jsx("th",{...d,"aria-sort":c,ref:e,style:{width:n?.getSize()},children:jsx("div",{className:clsx("group/header-cell",M.headerCell,u),"data-selected":n?.column.id===g||null,children:m||n&&jsxs(Fragment,{children:[n.column.id!==HeaderColumnAction.KEBAB&&a&&flexRender(n.column.columnDef.header,a),jsx(N,{header:n})]})})})}export{_ as TableHeaderCell};//# sourceMappingURL=header-cell.js.map
|
|
2
2
|
//# sourceMappingURL=header-cell.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/table/header-cell.tsx"],"names":["enableSorting","moveColumnRight","hoveredArrow","headerColumnActionValues","A","enableColumnReordering","
|
|
1
|
+
{"version":3,"sources":["../../../src/components/table/header-cell.tsx"],"names":["enableSorting","moveColumnRight","hoveredArrow","headerColumnActionValues","A","enableColumnReordering","y","sort","header","jsx","clsx","hideHeaderKebab","MenuTrigger","isOpen","setColumnSelection","i","Button","o","E","setHoveredArrow","Kebab","SortDirection","ArrowDown","R","x","jsxs","Menu","t","Fragment","MenuItem","B","index","handleColumnReordering","manualSorting","handleSortChange","K","s","ref","className","columnSelection","sortLabel","I","rest","styles","children","HeaderColumnAction","S","HeaderCellMenu","P","w"],"mappings":"qpBAkCI,SACA,CAAA,CAAA,CAAA,MAAAA,CACA,CAAA,CAAA,CAAA,CAAA,KAAA,CAAA,sBACA,CAAAC,CAAAA,CACA,aAAA,CAAA,CAAA,CAAA,cACA,CAAA,CAAA,CAAA,wCAEA,CAAA,CAAA,CAAA,kBACA,CAAA,CAAA,CAAA,aACyB,CAAA,CAErB,CAACC,gBAGP,CAAA,CAAA,CACEC,sBAEA,CAAA,CAAA,CACA,CAAAC,UAAEJ,CAAAA,YAAAA,CAAiBK,GAEnB,CAAA,CAAA,CAAA,CAAAC,QAAA,CAAA,KAAO,CAAA,CAAA,CAAA,CAGT,CAAA,CAAA,CAAA,GAAMC,wBAAAA,CAAOC,QAAO,CAAO,YAAY,EAEvC,EAAA,CAAA,EAAA,CAAA,CACEC,CAAAA,OAAC,IAAI,CAAA,MAAWC,CAAAA,CAAKC,QAA0B,CAAA,WAC7C,EAAA,CAAA,OAACC,GAAAA,CAAA,KACC,CAAA,CAAA,SAAeC,CACbC,IAAAA,CAAmBD,CAAAA,EAASL,CAAO,CAAA,YAAY,CAAI,CAAA,QAGrD,CAAAO,IAAA,CAAAN,WAAAA,CAACO,CAAAA,YACS,CAAA,CAAA,EAAA,CACR,CAAA,CAAA,CAAA,CAAA,CAAA,MAAA,CAAA,EAAW,CAAA,IAA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AA,IAAQ,CAAE,CAAA,GAElC,CAAA,CAAA,WAAC,CAAA,CAAA,CACC,WAAWP,CAAK,CAAA,KAAA,CAAA,CAAA,EAAA,OAAA,EAAA,CAAqBiC,CAAAA,QAAO,CAAA1B,GAAA,CAAA,yCACY,CAAA,CAAA,CAAA,UAEvD,CAAA2B,GACEpC,eAEI,CAAA,CAAA,EAAAA,SAAc,GAAA,CAAOqC,EAAmB,IAAA,CAAA,QAE5BrC,CAAO,UAAO,CAAAsC,QAAA,CAAA,CAAA,QAAU,CAAA,CAAA,CAAA,CAAA,MACpCC,CAAAA,EAAe,GAAAC,kBAAA,CAAA,KAAgB,EAClC,CAAA,EAENC,UACF,CAEJ,CAAA,CAAA,MAAA,CAAA,SAAA,CAAA,MAAA,CAAA,CAAA,CAAA,CAAAhC,GAAA,CAAA,CAAA,CAAA,CAAA,MAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA","file":"header-cell.js","sourcesContent":["// __private-exports\n/*\n * Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport { clsx } from '@accelint/design-foundation/lib/utils';\nimport { ArrowDown, ArrowUp, Kebab } from '@accelint/icons';\nimport { flexRender, type Header } from '@tanstack/react-table';\nimport { useContext, useState } from 'react';\nimport { Button } from '../button';\nimport { Icon } from '../icon';\nimport { Menu } from '../menu';\nimport { MenuItem } from '../menu/item';\nimport { MenuSeparator } from '../menu/separator';\nimport { MenuTrigger } from '../menu/trigger';\nimport {\n HeaderColumnAction,\n headerColumnActionValues,\n SortDirection,\n} from './constants/table';\nimport { TableContext } from './context';\nimport styles from './styles.module.css';\nimport type { TableHeaderCellProps } from './types';\n\nfunction HeaderCellMenu<T>({ header }: { header: Header<T, unknown> }) {\n const {\n enableColumnReordering,\n enableSorting,\n moveColumnLeft,\n moveColumnRight,\n persistHeaderKebabMenu,\n setColumnSelection,\n manualSorting,\n handleSortChange,\n handleColumnReordering,\n } = useContext(TableContext);\n\n const [hoveredArrow, setHoveredArrow] = useState(false);\n const hideHeaderKebab = !persistHeaderKebabMenu;\n\n if (\n headerColumnActionValues.includes(\n header.column.id as 'numeral' | 'kebab' | 'selection',\n ) ||\n !(enableSorting || enableColumnReordering)\n ) {\n return null;\n }\n\n const sort = header.column.getIsSorted();\n\n return (\n <div className={clsx(hideHeaderKebab && styles.hideInHeader)}>\n <MenuTrigger\n onOpenChange={(isOpen) =>\n setColumnSelection(isOpen ? header.column.id : null)\n }\n >\n <Button\n variant='icon'\n aria-label='Menu'\n onHoverChange={setHoveredArrow}\n >\n <Icon>\n {(!sort || hoveredArrow) && <Kebab />}\n {!hoveredArrow && sort === SortDirection.DESC && <ArrowDown />}\n {!hoveredArrow && sort === SortDirection.ASC && <ArrowUp />}\n </Icon>\n </Button>\n <Menu>\n {enableColumnReordering && (\n <>\n <MenuItem\n onAction={() => {\n const index = header.column.getIndex();\n moveColumnLeft(index);\n handleColumnReordering?.(index);\n }}\n isDisabled={header.column.getIsFirstColumn('center')}\n >\n Move Column Left\n </MenuItem>\n <MenuItem\n onAction={() => {\n const index = header.column.getIndex();\n moveColumnRight(index);\n handleColumnReordering?.(index);\n }}\n isDisabled={header.column.getIsLastColumn('center')}\n >\n Move Column Right\n </MenuItem>\n </>\n )}\n {enableColumnReordering && enableSorting && <MenuSeparator />}\n {enableSorting && (\n <>\n <MenuItem\n onAction={() => {\n manualSorting\n ? handleSortChange?.(header.column.id, SortDirection.ASC)\n : header.column.toggleSorting(false);\n }}\n isDisabled={sort === SortDirection.ASC}\n >\n Sort Ascending\n </MenuItem>\n <MenuItem\n onAction={() => {\n manualSorting\n ? handleSortChange?.(header.column.id, SortDirection.DESC)\n : header.column.toggleSorting(true);\n }}\n isDisabled={sort === SortDirection.DESC}\n >\n Sort Descending\n </MenuItem>\n <MenuItem\n onAction={() => {\n manualSorting\n ? handleSortChange?.(header.column.id, null)\n : header.column.clearSorting();\n }}\n isDisabled={!sort}\n >\n Clear Sort\n </MenuItem>\n </>\n )}\n </Menu>\n </MenuTrigger>\n </div>\n );\n}\n\nexport function TableHeaderCell<T>({\n ref,\n children,\n className,\n header,\n ...rest\n}: TableHeaderCellProps<T>) {\n const { columnSelection } = useContext(TableContext);\n const renderProps = header?.getContext();\n const sortLabel =\n header?.column.getIsSorted() === SortDirection.ASC\n ? 'ascending'\n : header?.column.getIsSorted() === SortDirection.DESC\n ? 'descending'\n : undefined;\n\n return (\n <th\n {...rest}\n aria-sort={sortLabel}\n ref={ref}\n style={{ width: header?.getSize() }}\n >\n <div\n className={clsx('group/header-cell', styles.headerCell, className)}\n data-selected={header?.column.id === columnSelection || null}\n >\n {children ||\n (header && (\n <>\n {header.column.id !== HeaderColumnAction.KEBAB &&\n renderProps &&\n flexRender(header.column.columnDef.header, renderProps)}\n <HeaderCellMenu header={header} />\n </>\n ))}\n </div>\n </th>\n );\n}\n"]}
|
|
@@ -15,6 +15,6 @@ import 'react';
|
|
|
15
15
|
*/
|
|
16
16
|
declare function Table<T extends {
|
|
17
17
|
id: Key;
|
|
18
|
-
}>({ children, columns: columnsProp, data: dataProp, showCheckbox, kebabPosition, persistRowKebabMenu, persistHeaderKebabMenu, persistNumerals, enableSorting, enableColumnReordering, enableRowActions, manualSorting, onSortChange, onColumnReorderChange, ...rest }: TableProps<T>): react_jsx_runtime.JSX.Element;
|
|
18
|
+
}>({ children, columns: columnsProp, data: dataProp, showCheckbox, rowSelection: rowSelectionProp, kebabPosition, persistRowKebabMenu, persistHeaderKebabMenu, persistNumerals, enableSorting, enableColumnReordering, enableRowActions, manualSorting, onSortChange, onColumnReorderChange, onRowSelectionChange, fullWidth, ...rest }: TableProps<T>): react_jsx_runtime.JSX.Element;
|
|
19
19
|
|
|
20
20
|
export { Table };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import {jsx,jsxs}from'react/jsx-runtime';import {Pin,Kebab}from'@accelint/icons';import {useListData}from'@react-stately/data';import {useReactTable,getSortedRowModel,getCoreRowModel}from'@tanstack/react-table';import'client-only';import {clsx}from'@accelint/design-foundation/lib/utils';import {useState,useCallback,useMemo,useContext}from'react';import {Button}from'../button/index.js';import {Checkbox}from'../checkbox/index.js';import {Icon}from'../icon/index.js';import {Menu}from'../menu/index.js';import {MenuItem}from'../menu/item.js';import {MenuSeparator}from'../menu/separator.js';import {MenuTrigger}from'../menu/trigger.js';import {TableBody}from'./body.js';import {TableContext}from'./context.js';import {TableHeader}from'./header.js';import
|
|
3
|
+
import {jsx,jsxs}from'react/jsx-runtime';import {Pin,Kebab}from'@accelint/icons';import {useListData}from'@react-stately/data';import {useReactTable,getSortedRowModel,getCoreRowModel}from'@tanstack/react-table';import'client-only';import {clsx}from'@accelint/design-foundation/lib/utils';import {useState,useCallback,useMemo,useContext}from'react';import {Button}from'../button/index.js';import {Checkbox}from'../checkbox/index.js';import {Icon}from'../icon/index.js';import {Menu}from'../menu/index.js';import {MenuItem}from'../menu/item.js';import {MenuSeparator}from'../menu/separator.js';import {MenuTrigger}from'../menu/trigger.js';import {TableBody}from'./body.js';import {TableContext}from'./context.js';import {TableHeader}from'./header.js';import be from'./styles.module.css';const v=32;function Me({moveRowsDown:R,moveRowsUp:p,row:s,rows:c}){const{enableRowActions:g,persistRowKebabMenu:u}=useContext(TableContext),m=!!s.getIsPinned();return g&&jsx("div",{className:clsx(!u&&be.hideInRow),children:jsxs(MenuTrigger,{children:[jsx(Button,{variant:"icon","aria-label":`row ${s.index+1} actions`,children:jsx(Icon,{children:jsx(Kebab,{})})}),jsxs(Menu,{children:[jsx(MenuItem,{onAction:()=>s.pin(m?false:"top"),children:m?"Unpin":"Pin"}),jsx(MenuSeparator,{}),jsx(MenuItem,{onAction:()=>p(s,c),isDisabled:m||s.index===0,children:"Move Up"}),jsx(MenuItem,{onAction:()=>R(s,c),isDisabled:m||s.index===c.length-1,children:"Move Down"})]})]})})}function Ge({children:R,columns:p,data:s,showCheckbox:c,rowSelection:g,kebabPosition:u="right",persistRowKebabMenu:m=true,persistHeaderKebabMenu:h=true,persistNumerals:_=false,enableSorting:I=true,enableColumnReordering:E=true,enableRowActions:W=true,manualSorting:P=false,onSortChange:$,onColumnReorderChange:k,onRowSelectionChange:y,fullWidth:q=false,...S}){const{items:F,moveAfter:x,moveBefore:N}=useListData({initialItems:s}),[r,J]=useState(g??{}),[A,Q]=useState(null),[X,Y]=useState({top:[],bottom:[]}),D=useCallback((e,t)=>{const n=r[e.id]?t.filter(({id:a})=>r[a]):[e],l=n[0];if(!l||l.index===0)return;const d=t[l.index-1]?.id;d&&N(d,n.map(({id:a})=>a));},[r,N]),K=useCallback((e,t)=>{const n=r[e.id]?t.filter(({id:a})=>r[a]):[e],l=n[n.length-1];if(!l||l.index===t.length-1)return;const d=t[l.index+1]?.id;d&&x(d,n.map(({id:a})=>a));},[r,x]),T=useMemo(()=>({id:"kebab",cell:({row:e})=>jsx(Me,{moveRowsUp:D,moveRowsDown:K,row:e,rows:ie().rows}),size:v}),[D,K]),U=useMemo(()=>[{id:"numeral",cell:({row:e})=>e.getIsPinned()?jsx(Icon,{size:"small",children:jsx(Pin,{})}):jsx("span",{"data-testid":"numeral",children:e.index+1}),size:v},...c?[{id:"selection",header:({table:e})=>jsx(Checkbox,{isSelected:e.getIsAllRowsSelected(),isIndeterminate:e.getIsSomeRowsSelected(),onChange:e.toggleAllRowsSelected}),cell:({row:e})=>jsx(Checkbox,{isSelected:e.getIsSelected(),isIndeterminate:e.getIsSomeSelected(),onChange:e.toggleSelected}),size:v}]:[],...u==="left"?[T]:[],...p??[],...u==="right"?[T]:[]],[c,p,u,T]),Z=(e,t)=>{$?.(e,t);},j=e=>{k?.(e);},V=useCallback(e=>{J(e),y?.(e);},[y]),{getHeaderGroups:ee,getTopRows:oe,getCenterRows:te,getBottomRows:ne,getRowModel:ie,setColumnOrder:f}=useReactTable({data:F,columns:U,enableSorting:I,initialState:{columnOrder:U.map(({id:e})=>e??""),rowSelection:g??{}},state:{rowSelection:r,rowPinning:X},getRowId:(e,t)=>e.id?e.id.toString():t.toString(),enableRowSelection:true,enableRowPinning:true,manualSorting:P,onRowSelectionChange:V,onRowPinningChange:Y,getCoreRowModel:getCoreRowModel(),getSortedRowModel:getSortedRowModel()}),se=useCallback(e=>{f(t=>{const i=[...t],n=e-1;return n<0?t:([i[e],i[n]]=[i[n],i[e]],i)});},[f]),re=useCallback(e=>{f(t=>{const i=[...t],n=e+1;return n>=t.length?t:([i[e],i[n]]=[i[n],i[e]],i)});},[f]),B=clsx(q&&"w-full table-fixed",S.className);return R?jsx("table",{...S,className:B,children:R}):jsx(TableContext.Provider,{value:{persistRowKebabMenu:m,persistHeaderKebabMenu:h,persistNumerals:_,enableSorting:I,enableColumnReordering:E,enableRowActions:W,columnSelection:A,setColumnSelection:Q,moveColumnLeft:se,moveColumnRight:re,manualSorting:P,handleSortChange:Z,handleColumnReordering:j},children:jsxs("table",{...S,className:B,children:[jsx(TableHeader,{headerGroups:ee(),columnSelection:A}),jsx(TableBody,{rows:[...oe(),...te(),...ne()]})]})})}export{Ge as Table};//# sourceMappingURL=index.js.map
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/table/index.tsx"],"names":["useContext","isPinned","persistRowKebabMenu","styles","le","O","MenuTrigger","jsx","Button","re","v","ue","o","me","Kebab","jsxs","Menu","MenuItem","ee","ae","MenuSeparator","moveRowsUp","row","rows","moveRowsDown","b","Table","children","columnsProp","showCheckbox","enableSorting","enableColumnReordering","enableRowActions","manualSorting","rest","data","dataProp","rowSelection","setRowSelection","setColumnSelection","useState","rowPinning","setRowPinning","te","T","rowsToMove","id","g","firstRowToMove","prevRowId","moveBefore","lastRowToMove","nextRowId","moveAfter","RowActionsMenu","K","columns","useMemo","Icon","U","oe","table","B","kebabPosition","actionColumn","handleSortChange","columnId","sortDirection","index","onColumnReorderChange","getHeaderGroups","getTopRows","getCenterRows","getBottomRows","useReactTable","se","getCoreRowModel","getSortedRowModel","ne","newIndex","ie","newColumnOrder","oldIndex","moveColumnRight","useCallback","setColumnOrder","order","TableContext","persistHeaderKebabMenu","persistNumerals","TableHeader","columnSelection","pe","de"],"mappings":"ixBAsDU,SAAA,EAAA,CAAA,CAAA,YAAkB,CAAA,CAAA,CAAA,UAAoB,CAAIA,CAAAA,CAAAA,GAAuB,CACnEC,CAAAA,CAAW,IAAM,2BAKlB,CAAA,CAAA,CAAA,mBAJiBC,CAImBC,GAAOC,UAAA,CAAAC,YAAA,CAAA,CAAA,CAAA,CAAA,CAAS,CAAA,CACnD,YAACC,EAAA,CACC,OAAA,CAAA,EAAAC,GAAAA,CAACC,KAAO,CAAA,CAAA,SAAQ,CAAAC,IAAO,iBAAY,CAAA,CAAA,SAAmBC,IAAC,CAAAC,WAAA,CAAA,CAAA,QACrD,CAAA,CAAAC,GAAA,CAAAC,MAAA,CAAAN,CAAAA,cACEA,CAACO,YAGLC,CAACC,CAAAA,IACC,EAAA,CAAA,CAAA,KAAAT,CAAAA,CAACU,CAAAA,QAAS,CAAA,CAAA,QAAoB,CAAAL,GAAA,CAAIX,IAAAA,CAAW,SAAa,CACvDW,GAAA,CAAAM,KAAA,CAAA,EAAA,CAAA,CAAAjB,CAAAA,CAAW,CAAA,CAAAS,IAAA,CAAAS,IAAA,CAAA,CAAU,QAExBZ,CAAAA,CAACa,GAAAA,CAAAA,QAAA,EAAc,QAEb,CAAA,IAAA,CAAA,CAAA,GAAU,CAAA,CAAMC,CAAAA,KAAWC,CAAKC,KAChC,CAAA,CAAA,QAAYtB,CAAAA,CAAYqB,QAA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zB,MAIJ,CAAA,CACA,CAACI,GACH,CAEA,OAAI1D,CAAAA,YACa,MAAU,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAAA,CAAAA,CAAS,CAAA,CAIlCpB,CAAAA,CAACgF,EAAa,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAb,CACC,OAAO,CACL,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,OAAA,CAAA,CAAA3E,GAAA,CAAA,OACA,CAAA,CAAA,GAAA,CAAA,CAAA,QAAA,CAAA,CAAA,CAAA,CAAA,CAAAA,GAAA4E,CAAAA,YACA,CAAA,QAAA,CAAA,CAAA,KAAAC,CAAAA,CACA,4CAEA,CAAA,CAAA,CAAA,eACA,CAAA,CAAA,CAAA,aACA,yBACA,CAAA,CAAA,CAAA,gBACA,CAAA,CAAA,CAAA,eACA,CAAA,CAAA,CAAA,kBACA,CAAA,CAAA,CAAA,gDAID,CAAA,CAAA,CAAO,gBACNlF,CAACmF,wBAEC,CAAA,CAAA,CAAA,CAAA,QAAA,CAAiBC,KACnB,OACC,CACC,CAAA,GAAA,CAAM,CAAC,QAAiB,CAAA,CAAGnB,GAAAA,CAAcoB,WAAG,CAAA,CAAA,YAKtD,CAAA,CAAA,EAAA,CAAA,eAAA,CAAA,CAAA,CAAA,CAAA,CAAAhF,GAAA,CAAAiF,SAAA,CAAA,CAAA,IAAA,CAAA,CAAA,GAAA,CAAA,EAAA,CAAA,GAAA,CAAA,EAAA,CAAA,GAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA","file":"index.js","sourcesContent":["/*\n * Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n'use client';\n\nimport { Kebab, Pin } from '@accelint/icons';\nimport { useListData } from '@react-stately/data';\nimport {\n getCoreRowModel,\n getSortedRowModel,\n type Row,\n type RowPinningState,\n type RowSelectionState,\n useReactTable,\n} from '@tanstack/react-table';\nimport type { Key } from '@react-types/shared';\nimport 'client-only';\nimport { clsx } from '@accelint/design-foundation/lib/utils';\nimport { useCallback, useContext, useMemo, useState } from 'react';\nimport { Button } from '../button';\nimport { Checkbox } from '../checkbox';\nimport { Icon } from '../icon';\nimport { Menu } from '../menu';\nimport { MenuItem } from '../menu/item';\nimport { MenuSeparator } from '../menu/separator';\nimport { MenuTrigger } from '../menu/trigger';\nimport { TableBody } from './body';\nimport { TableContext } from './context';\nimport { TableHeader } from './header';\nimport styles from './styles.module.css';\nimport type { TableProps } from './types';\n\ntype RowActionsMenuProps<T> = {\n row: Row<T>;\n rows: Row<T>[];\n moveRowsDown: (row: Row<T>, rows: Row<T>[]) => void;\n moveRowsUp: (row: Row<T>, rows: Row<T>[]) => void;\n};\n\nfunction RowActionsMenu<T>({\n moveRowsDown,\n moveRowsUp,\n row,\n rows,\n}: RowActionsMenuProps<T>) {\n const { enableRowActions, persistRowKebabMenu } = useContext(TableContext);\n const isPinned = !!row.getIsPinned();\n const hideRowKebab = !persistRowKebabMenu;\n\n return (\n enableRowActions && (\n <div className={clsx(hideRowKebab && styles.hideInRow)}>\n <MenuTrigger>\n <Button variant='icon' aria-label={`row ${row.index + 1} actions`}>\n <Icon>\n <Kebab />\n </Icon>\n </Button>\n <Menu>\n <MenuItem onAction={() => row.pin(isPinned ? false : 'top')}>\n {isPinned ? 'Unpin' : 'Pin'}\n </MenuItem>\n <MenuSeparator />\n <MenuItem\n onAction={() => moveRowsUp(row, rows)}\n isDisabled={isPinned || row.index === 0}\n >\n Move Up\n </MenuItem>\n <MenuItem\n onAction={() => moveRowsDown(row, rows)}\n isDisabled={isPinned || row.index === rows.length - 1}\n >\n Move Down\n </MenuItem>\n </Menu>\n </MenuTrigger>\n </div>\n )\n );\n}\n\n/**\n * Table - Configurable data table with sorting and row actions\n *\n * Standardizes table behavior (sorting, selection, row actions) and can be\n * used with column definitions from TanStack React Table.\n *\n * @example\n * <Table columns={columns} data={data} />\n */\nexport function Table<T extends { id: Key }>({\n children,\n columns: columnsProp,\n data: dataProp,\n showCheckbox,\n kebabPosition = 'right',\n persistRowKebabMenu = true,\n persistHeaderKebabMenu = true,\n persistNumerals = false,\n enableSorting = true,\n enableColumnReordering = true,\n enableRowActions = true,\n manualSorting = false,\n onSortChange,\n onColumnReorderChange,\n ...rest\n}: TableProps<T>) {\n const {\n items: data,\n moveAfter,\n moveBefore,\n } = useListData({\n initialItems: dataProp,\n });\n const [rowSelection, setRowSelection] = useState<RowSelectionState>({});\n const [columnSelection, setColumnSelection] = useState<string | null>(null);\n const [rowPinning, setRowPinning] = useState<RowPinningState>({\n top: [],\n bottom: [],\n });\n /**\n * moveUpSelectedRows moves the selected rows up in the table.\n * It finds the first selected row, determines its index,\n * and moves it before the previous row if it exists.\n */\n const moveRowsUp = useCallback(\n (row: Row<T>, rows: Row<T>[]) => {\n const isSelected = rowSelection[row.id];\n const rowsToMove = isSelected\n ? rows.filter(({ id }) => rowSelection[id])\n : [row];\n const firstRowToMove = rowsToMove[0];\n\n if (!firstRowToMove || firstRowToMove.index === 0) {\n return;\n }\n\n const prevRowId = rows[firstRowToMove.index - 1]?.id;\n\n if (!prevRowId) {\n return;\n }\n\n moveBefore(\n prevRowId,\n rowsToMove.map(({ id }) => id),\n );\n },\n [rowSelection, moveBefore],\n );\n\n /**\n * moveDownRows moves the selected or active rows down in the table.\n * It finds the last selected row, determines its index,\n * and moves it after the next row if it exists.\n */\n const moveRowsDown = useCallback(\n (row: Row<T>, rows: Row<T>[]) => {\n const isSelected = rowSelection[row.id];\n const rowsToMove = isSelected\n ? rows.filter(({ id }) => rowSelection[id])\n : [row];\n const lastRowToMove = rowsToMove[rowsToMove.length - 1];\n\n if (!lastRowToMove || lastRowToMove.index === rows.length - 1) {\n return;\n }\n\n const nextRowId = rows[lastRowToMove.index + 1]?.id;\n\n if (!nextRowId) {\n return;\n }\n\n moveAfter(\n nextRowId,\n rowsToMove.map(({ id }) => id),\n );\n },\n [rowSelection, moveAfter],\n );\n\n /**\n * actionColumn defines the actions available in the kebab menu for each row.\n * It includes options to move the row up or down in the table.\n */\n // biome-ignore lint/correctness/useExhaustiveDependencies: can of worms to fix ticket added\n const actionColumn: NonNullable<typeof columnsProp>[number] = useMemo(\n () => ({\n id: 'kebab',\n cell: ({ row }) => (\n <RowActionsMenu\n moveRowsUp={moveRowsUp}\n moveRowsDown={moveRowsDown}\n row={row}\n rows={getRowModel().rows}\n />\n ),\n }),\n [moveRowsUp, moveRowsDown],\n );\n\n /**\n * columns defines the structure of the table.\n * It includes the action column and optionally a checkbox column.\n * The kebab menu position can be set to 'left' or 'right'.\n * If showCheckbox is true, a checkbox column is added.\n */\n const columns = useMemo<NonNullable<typeof columnsProp>>(\n () => [\n {\n id: 'numeral',\n cell: ({ row }) =>\n row.getIsPinned() ? (\n <Icon size='small'>\n <Pin />\n </Icon>\n ) : (\n <span data-testid='numeral'>{row.index + 1}</span>\n ),\n },\n ...(showCheckbox\n ? ([\n {\n id: 'selection',\n header: ({ table }) => (\n <Checkbox\n isSelected={table.getIsAllRowsSelected()}\n isIndeterminate={table.getIsSomeRowsSelected()}\n onChange={table.toggleAllRowsSelected}\n />\n ),\n cell: ({ row }) => (\n <Checkbox\n isSelected={row.getIsSelected()}\n isIndeterminate={row.getIsSomeSelected()}\n onChange={row.toggleSelected}\n />\n ),\n },\n ] satisfies NonNullable<typeof columnsProp>)\n : []),\n ...(kebabPosition === 'left' ? [actionColumn] : []),\n ...(columnsProp ?? []),\n ...(kebabPosition === 'right' ? [actionColumn] : []),\n ],\n [showCheckbox, columnsProp, kebabPosition, actionColumn],\n );\n\n const handleSortChange = (\n columnId: string,\n sortDirection: 'asc' | 'desc' | null,\n ) => {\n onSortChange?.(columnId, sortDirection);\n };\n\n const handleColumnReordering = (index: number) => {\n onColumnReorderChange?.(index);\n };\n\n const {\n getHeaderGroups,\n getTopRows,\n getCenterRows,\n getBottomRows,\n getRowModel,\n setColumnOrder,\n } = useReactTable<T>({\n data,\n columns,\n enableSorting,\n initialState: {\n columnOrder: columns.map(({ id }) => id ?? ''),\n },\n state: {\n rowSelection,\n rowPinning,\n },\n getRowId: (row, index) => {\n // Use the index as the row ID if no unique identifier is available\n return row.id ? row.id.toString() : index.toString();\n },\n enableRowSelection: true,\n enableRowPinning: true,\n manualSorting: manualSorting,\n onRowSelectionChange: setRowSelection,\n onRowPinningChange: setRowPinning,\n getCoreRowModel: getCoreRowModel<T>(),\n getSortedRowModel: getSortedRowModel<T>(),\n });\n\n const moveColumnLeft = useCallback(\n (oldIndex: number) => {\n setColumnOrder((order) => {\n const newColumnOrder = [...order];\n const newIndex = oldIndex - 1;\n\n if (newIndex < 0) {\n return order;\n }\n\n [newColumnOrder[oldIndex], newColumnOrder[newIndex]] = [\n newColumnOrder[newIndex] as string,\n newColumnOrder[oldIndex] as string,\n ];\n\n return newColumnOrder;\n });\n },\n [setColumnOrder],\n );\n\n const moveColumnRight = useCallback(\n (oldIndex: number) => {\n setColumnOrder((order) => {\n const newColumnOrder = [...order];\n const newIndex = oldIndex + 1;\n\n if (newIndex >= order.length) {\n return order;\n }\n\n [newColumnOrder[oldIndex], newColumnOrder[newIndex]] = [\n newColumnOrder[newIndex] as string,\n newColumnOrder[oldIndex] as string,\n ];\n\n return newColumnOrder;\n });\n },\n [setColumnOrder],\n );\n\n if (children) {\n return <table {...rest}>{children}</table>;\n }\n\n return (\n <TableContext.Provider\n value={{\n persistRowKebabMenu,\n persistHeaderKebabMenu,\n persistNumerals,\n enableSorting,\n enableColumnReordering,\n enableRowActions,\n columnSelection,\n setColumnSelection,\n moveColumnLeft,\n moveColumnRight,\n manualSorting,\n handleSortChange,\n handleColumnReordering,\n }}\n >\n <table {...rest}>\n <TableHeader\n headerGroups={getHeaderGroups()}\n columnSelection={columnSelection}\n />\n <TableBody\n rows={[...getTopRows(), ...getCenterRows(), ...getBottomRows()]}\n />\n </table>\n </TableContext.Provider>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/table/index.tsx"],"names":["useContext","isPinned","styles","we","G","MenuTrigger","jsx","Button","z","C","fe","o","Re","Kebab","jsxs","Menu","MenuItem","pe","MenuSeparator","moveRowsUp","row","rows","ge","M","moveRowsDown","Table","children","columnsProp","showCheckbox","kebabPosition","enableSorting","enableColumnReordering","enableRowActions","manualSorting","onRowSelectionChange","rest","useListData","dataProp","rowSelection","setRowSelection","rowSelectionProp","columnSelection","setColumnSelection","rowPinning","ce","useCallback","rowsToMove","id","b","w","firstRowToMove","prevRowId","moveBefore","lastRowToMove","nextRowId","moveAfter","RowActionsMenu","O","META_COLUMN_WIDTH","Icon","L","ae","Checkbox","H","actionColumn","handleSortChange","sortDirection","columnId","handleColumnReordering","index","onColumnReorderChange","handleRowSelectionChange","updaterOrValue","getHeaderGroups","getTopRows","getCenterRows","getBottomRows","getRowModel","setColumnOrder","columns","de","getCoreRowModel","me","newColumnOrder","newIndex","oldIndex","order","className","clsx","fullWidth","TableContext","persistHeaderKebabMenu","persistNumerals","Se"],"mappings":"ixBA4DA,MACE,CAAM,CAAE,EAAA,CAAA,SAAA,EAAA,CAAA,CAAA,yBAAsC,CAAIA,CAAAA,CAAAA,GAAuB,CACnEC,CAAAA,CAAW,IAAM,2BAKlB,CAAA,CAAA,CAAA,mBAAoCC,GAAO,CAAAC,UAAA,CAAAC,YAAA,CAAA,CAAA,CAAA,CAAS,CAAA,CACnD,CAAA,CAAA,WAACC,EACC,WAAAC,GAACC,CAAAA,KAAO,CAAA,CAAA,SAAQ,CAAAC,IAAO,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,mBAAuB,CAAQC,IAAC,CAAAC,WAAA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A,CAEApB,CAAAA,CAAC,UAAO,CAAA,CAAA,CAAG6B,CAAAA,CAAM,CAAA3B,IAAA,CAAA,CAAA,EAAA,oBAOnBF,CAACoF,CAAAA,CAAa,SAAb,CACC,CAAA,oCAEE,CAAA,CAAA,CAAA,QAAA,CAAA,CAAA,CAAA,CAAA,CAAA/E,GAAAgF,CAAAA,YACA,CAAA,QAAA,CAAA,CAAA,KAAAC,CAAAA,CACA,mBACA,CAAA,CAAA,CAAA,sBACA,CAAA,CAAA,CAAA,eACA,CAAA,CAAA,CAAA,aACA,yBACA,CAAA,CAAA,CAAA,gBACA,CAAA,CAAA,CAAA,eACA,CAAA,CAAA,CAAA,kBACA,CAAA,CAAA,CAAA,cACA,CAAA,EAAA,CAAA,eAGF,CAAA,EAAA,CAAA,aAAC,CAAA,CAAA,CAAO,gBAAoBL,CAC1B,CAAA,CAAA,sBACE,CAAA,CAAA,CAAA,CAAA,QACA,CAAA9E,IAAA,CAAA,OAAA,CAAA,CAAA,IACF,CAAA,SAEE,CAAA,CAAA,CAAM,QAAe,CAAG,CAAAE,GAAA,CAAGgE,WAAAA,CAAc,CAAA,YAC3C,CACF,EACF,EAEJ,CAAA,eAAA,CAAA,CAAA,CAAA,CAAA,CAAAhE,GAAA,CAAAkF,SAAA,CAAA,CAAA,IAAA,CAAA,CAAA,GAAA,EAAA,EAAA,CAAA,GAAA,EAAA,EAAA,CAAA,GAAA,EAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA","file":"index.js","sourcesContent":["/*\n * Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n'use client';\n\nimport { Kebab, Pin } from '@accelint/icons';\nimport { useListData } from '@react-stately/data';\nimport {\n getCoreRowModel,\n getSortedRowModel,\n type Row,\n type RowPinningState,\n type RowSelectionState,\n useReactTable,\n} from '@tanstack/react-table';\nimport type { Key } from '@react-types/shared';\nimport 'client-only';\nimport { clsx } from '@accelint/design-foundation/lib/utils';\nimport { useCallback, useContext, useMemo, useState } from 'react';\nimport { Button } from '../button';\nimport { Checkbox } from '../checkbox';\nimport { Icon } from '../icon';\nimport { Menu } from '../menu';\nimport { MenuItem } from '../menu/item';\nimport { MenuSeparator } from '../menu/separator';\nimport { MenuTrigger } from '../menu/trigger';\nimport { TableBody } from './body';\nimport { TableContext } from './context';\nimport { TableHeader } from './header';\nimport styles from './styles.module.css';\nimport type { TableProps } from './types';\n\n// This width is for columns in the table that provide features:\n// - Row count\n// - Row actions kebab\n// - Row selection (checkbox)\n// These columns should not need to grow with table width\nconst META_COLUMN_WIDTH = 32;\n\ntype RowActionsMenuProps<T> = {\n row: Row<T>;\n rows: Row<T>[];\n moveRowsDown: (row: Row<T>, rows: Row<T>[]) => void;\n moveRowsUp: (row: Row<T>, rows: Row<T>[]) => void;\n};\n\nfunction RowActionsMenu<T>({\n moveRowsDown,\n moveRowsUp,\n row,\n rows,\n}: RowActionsMenuProps<T>) {\n const { enableRowActions, persistRowKebabMenu } = useContext(TableContext);\n const isPinned = !!row.getIsPinned();\n const hideRowKebab = !persistRowKebabMenu;\n\n return (\n enableRowActions && (\n <div className={clsx(hideRowKebab && styles.hideInRow)}>\n <MenuTrigger>\n <Button variant='icon' aria-label={`row ${row.index + 1} actions`}>\n <Icon>\n <Kebab />\n </Icon>\n </Button>\n <Menu>\n <MenuItem onAction={() => row.pin(isPinned ? false : 'top')}>\n {isPinned ? 'Unpin' : 'Pin'}\n </MenuItem>\n <MenuSeparator />\n <MenuItem\n onAction={() => moveRowsUp(row, rows)}\n isDisabled={isPinned || row.index === 0}\n >\n Move Up\n </MenuItem>\n <MenuItem\n onAction={() => moveRowsDown(row, rows)}\n isDisabled={isPinned || row.index === rows.length - 1}\n >\n Move Down\n </MenuItem>\n </Menu>\n </MenuTrigger>\n </div>\n )\n );\n}\n\n/**\n * Table - Configurable data table with sorting and row actions\n *\n * Standardizes table behavior (sorting, selection, row actions) and can be\n * used with column definitions from TanStack React Table.\n *\n * @example\n * <Table columns={columns} data={data} />\n */\nexport function Table<T extends { id: Key }>({\n children,\n columns: columnsProp,\n data: dataProp,\n showCheckbox,\n rowSelection: rowSelectionProp,\n kebabPosition = 'right',\n persistRowKebabMenu = true,\n persistHeaderKebabMenu = true,\n persistNumerals = false,\n enableSorting = true,\n enableColumnReordering = true,\n enableRowActions = true,\n manualSorting = false,\n onSortChange,\n onColumnReorderChange,\n onRowSelectionChange,\n fullWidth = false,\n ...rest\n}: TableProps<T>) {\n const {\n items: data,\n moveAfter,\n moveBefore,\n } = useListData({\n initialItems: dataProp,\n });\n const [rowSelection, setRowSelection] = useState<RowSelectionState>(\n rowSelectionProp ?? {},\n );\n const [columnSelection, setColumnSelection] = useState<string | null>(null);\n const [rowPinning, setRowPinning] = useState<RowPinningState>({\n top: [],\n bottom: [],\n });\n\n /**\n * moveUpSelectedRows moves the selected rows up in the table.\n * It finds the first selected row, determines its index,\n * and moves it before the previous row if it exists.\n */\n const moveRowsUp = useCallback(\n (row: Row<T>, rows: Row<T>[]) => {\n const isSelected = rowSelection[row.id];\n const rowsToMove = isSelected\n ? rows.filter(({ id }) => rowSelection[id])\n : [row];\n const firstRowToMove = rowsToMove[0];\n\n if (!firstRowToMove || firstRowToMove.index === 0) {\n return;\n }\n\n const prevRowId = rows[firstRowToMove.index - 1]?.id;\n\n if (!prevRowId) {\n return;\n }\n\n moveBefore(\n prevRowId,\n rowsToMove.map(({ id }) => id),\n );\n },\n [rowSelection, moveBefore],\n );\n\n /**\n * moveDownRows moves the selected or active rows down in the table.\n * It finds the last selected row, determines its index,\n * and moves it after the next row if it exists.\n */\n const moveRowsDown = useCallback(\n (row: Row<T>, rows: Row<T>[]) => {\n const isSelected = rowSelection[row.id];\n const rowsToMove = isSelected\n ? rows.filter(({ id }) => rowSelection[id])\n : [row];\n const lastRowToMove = rowsToMove[rowsToMove.length - 1];\n\n if (!lastRowToMove || lastRowToMove.index === rows.length - 1) {\n return;\n }\n\n const nextRowId = rows[lastRowToMove.index + 1]?.id;\n\n if (!nextRowId) {\n return;\n }\n\n moveAfter(\n nextRowId,\n rowsToMove.map(({ id }) => id),\n );\n },\n [rowSelection, moveAfter],\n );\n\n /**\n * actionColumn defines the actions available in the kebab menu for each row.\n * It includes options to move the row up or down in the table.\n */\n // biome-ignore lint/correctness/useExhaustiveDependencies: can of worms to fix ticket added\n const actionColumn: NonNullable<typeof columnsProp>[number] = useMemo(\n () => ({\n id: 'kebab',\n cell: ({ row }) => (\n <RowActionsMenu\n moveRowsUp={moveRowsUp}\n moveRowsDown={moveRowsDown}\n row={row}\n rows={getRowModel().rows}\n />\n ),\n size: META_COLUMN_WIDTH,\n }),\n [moveRowsUp, moveRowsDown],\n );\n\n /**\n * columns defines the structure of the table.\n * It includes the action column and optionally a checkbox column.\n * The kebab menu position can be set to 'left' or 'right'.\n * If showCheckbox is true, a checkbox column is added.\n */\n const columns = useMemo<NonNullable<typeof columnsProp>>(\n () => [\n {\n id: 'numeral',\n cell: ({ row }) =>\n row.getIsPinned() ? (\n <Icon size='small'>\n <Pin />\n </Icon>\n ) : (\n <span data-testid='numeral'>{row.index + 1}</span>\n ),\n size: META_COLUMN_WIDTH,\n },\n ...(showCheckbox\n ? ([\n {\n id: 'selection',\n header: ({ table }) => (\n <Checkbox\n isSelected={table.getIsAllRowsSelected()}\n isIndeterminate={table.getIsSomeRowsSelected()}\n onChange={table.toggleAllRowsSelected}\n />\n ),\n cell: ({ row }) => (\n <Checkbox\n isSelected={row.getIsSelected()}\n isIndeterminate={row.getIsSomeSelected()}\n onChange={row.toggleSelected}\n />\n ),\n size: META_COLUMN_WIDTH,\n },\n ] satisfies NonNullable<typeof columnsProp>)\n : []),\n ...(kebabPosition === 'left' ? [actionColumn] : []),\n ...(columnsProp ?? []),\n ...(kebabPosition === 'right' ? [actionColumn] : []),\n ],\n [showCheckbox, columnsProp, kebabPosition, actionColumn],\n );\n\n const handleSortChange = (\n columnId: string,\n sortDirection: 'asc' | 'desc' | null,\n ) => {\n onSortChange?.(columnId, sortDirection);\n };\n\n const handleColumnReordering = (index: number) => {\n onColumnReorderChange?.(index);\n };\n\n const handleRowSelectionChange = useCallback(\n (\n updaterOrValue:\n | RowSelectionState\n | ((old: RowSelectionState) => RowSelectionState),\n ) => {\n setRowSelection(updaterOrValue);\n onRowSelectionChange?.(updaterOrValue);\n },\n [onRowSelectionChange],\n );\n\n const {\n getHeaderGroups,\n getTopRows,\n getCenterRows,\n getBottomRows,\n getRowModel,\n setColumnOrder,\n } = useReactTable<T>({\n data,\n columns,\n enableSorting,\n initialState: {\n columnOrder: columns.map(({ id }) => id ?? ''),\n rowSelection: rowSelectionProp ?? {},\n },\n state: {\n rowSelection,\n rowPinning,\n },\n getRowId: (row, index) => {\n // Use the index as the row ID if no unique identifier is available\n return row.id ? row.id.toString() : index.toString();\n },\n enableRowSelection: true,\n enableRowPinning: true,\n manualSorting: manualSorting,\n onRowSelectionChange: handleRowSelectionChange,\n onRowPinningChange: setRowPinning,\n getCoreRowModel: getCoreRowModel<T>(),\n getSortedRowModel: getSortedRowModel<T>(),\n });\n\n const moveColumnLeft = useCallback(\n (oldIndex: number) => {\n setColumnOrder((order) => {\n const newColumnOrder = [...order];\n const newIndex = oldIndex - 1;\n\n if (newIndex < 0) {\n return order;\n }\n\n [newColumnOrder[oldIndex], newColumnOrder[newIndex]] = [\n newColumnOrder[newIndex] as string,\n newColumnOrder[oldIndex] as string,\n ];\n\n return newColumnOrder;\n });\n },\n [setColumnOrder],\n );\n\n const moveColumnRight = useCallback(\n (oldIndex: number) => {\n setColumnOrder((order) => {\n const newColumnOrder = [...order];\n const newIndex = oldIndex + 1;\n\n if (newIndex >= order.length) {\n return order;\n }\n\n [newColumnOrder[oldIndex], newColumnOrder[newIndex]] = [\n newColumnOrder[newIndex] as string,\n newColumnOrder[oldIndex] as string,\n ];\n\n return newColumnOrder;\n });\n },\n [setColumnOrder],\n );\n\n const className = clsx(fullWidth && 'w-full table-fixed', rest.className);\n\n if (children) {\n return (\n <table {...rest} className={className}>\n {children}\n </table>\n );\n }\n\n return (\n <TableContext.Provider\n value={{\n persistRowKebabMenu,\n persistHeaderKebabMenu,\n persistNumerals,\n enableSorting,\n enableColumnReordering,\n enableRowActions,\n columnSelection,\n setColumnSelection,\n moveColumnLeft,\n moveColumnRight,\n manualSorting,\n handleSortChange,\n handleColumnReordering,\n }}\n >\n <table {...rest} className={className}>\n <TableHeader\n headerGroups={getHeaderGroups()}\n columnSelection={columnSelection}\n />\n <TableBody\n rows={[...getTopRows(), ...getCenterRows(), ...getBottomRows()]}\n />\n </table>\n </TableContext.Provider>\n );\n}\n"]}
|
|
@@ -78,10 +78,13 @@
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
.hideInRow {
|
|
81
|
-
|
|
81
|
+
/* making the `td` not visible was causing the bg color to not show for selected rows */
|
|
82
|
+
& > * {
|
|
83
|
+
@apply invisible;
|
|
82
84
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
+
@variant group-hover/row {
|
|
86
|
+
@apply visible;
|
|
87
|
+
}
|
|
85
88
|
}
|
|
86
89
|
}
|
|
87
90
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Key } from '@react-types/shared';
|
|
2
|
-
import { ColumnDef, Row, Cell, Header, HeaderGroup } from '@tanstack/react-table';
|
|
2
|
+
import { ColumnDef, RowSelectionState, Row, Cell, Header, HeaderGroup } from '@tanstack/react-table';
|
|
3
3
|
import { Dispatch, SetStateAction, ComponentPropsWithRef, PropsWithChildren } from 'react';
|
|
4
4
|
|
|
5
5
|
type BaseTableProps = Omit<ComponentPropsWithRef<'table'>, 'children'>;
|
|
@@ -21,6 +21,12 @@ type ExtendedTableProps<T extends {
|
|
|
21
21
|
* Whether to display a checkbox column.
|
|
22
22
|
*/
|
|
23
23
|
showCheckbox?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Initial row selection state.
|
|
26
|
+
* An object mapping row IDs to their selection state (true = selected).
|
|
27
|
+
* Example: { 'row-1': true, 'row-2': true }
|
|
28
|
+
*/
|
|
29
|
+
rowSelection?: RowSelectionState;
|
|
24
30
|
/**
|
|
25
31
|
* Position of the kebab menu, either 'left' or 'right'.
|
|
26
32
|
*/
|
|
@@ -81,6 +87,31 @@ type ExtendedTableProps<T extends {
|
|
|
81
87
|
* @param index - The new index position of the column after reordering.
|
|
82
88
|
*/
|
|
83
89
|
onColumnReorderChange?: (index: number) => void;
|
|
90
|
+
/**
|
|
91
|
+
* Callback function triggered when row selection changes.
|
|
92
|
+
* Receives an updater function or direct value following TanStack Table's API pattern.
|
|
93
|
+
*
|
|
94
|
+
* @param updaterOrValue - Either a function that receives the old state and returns new state,
|
|
95
|
+
* or a direct RowSelectionState object.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* // Using with state setter
|
|
99
|
+
* onRowSelectionChange={setSelectedRows}
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* // Using with custom handler
|
|
103
|
+
* onRowSelectionChange={(updater) => {
|
|
104
|
+
* const newState = typeof updater === 'function' ? updater(oldState) : updater;
|
|
105
|
+
* console.log('Selected rows:', newState);
|
|
106
|
+
* }}
|
|
107
|
+
*/
|
|
108
|
+
onRowSelectionChange?: (updaterOrValue: RowSelectionState | ((old: RowSelectionState) => RowSelectionState)) => void;
|
|
109
|
+
/**
|
|
110
|
+
* Whether the table should take full width and use fixed layout.
|
|
111
|
+
* When true, applies 'w-full table-fixed' classes.
|
|
112
|
+
* @default false
|
|
113
|
+
*/
|
|
114
|
+
fullWidth?: boolean;
|
|
84
115
|
};
|
|
85
116
|
/**
|
|
86
117
|
* Props for the Table component.
|
package/dist/index.d.ts
CHANGED
|
@@ -85,6 +85,8 @@ export { DrawerPanel } from './components/drawer/panel.js';
|
|
|
85
85
|
export { DrawerTrigger } from './components/drawer/trigger.js';
|
|
86
86
|
export { DrawerContextValue, DrawerEvent, DrawerLayoutProps, DrawerMenuItemProps, DrawerMenuProps, DrawerOpenEvent, DrawerProps, DrawerTitleProps, DrawerToggleEvent, DrawerTriggerProps } from './components/drawer/types.js';
|
|
87
87
|
export { DrawerView } from './components/drawer/view.js';
|
|
88
|
+
export { Flashcard, FlashcardAdditionalData, FlashcardContext, FlashcardDetailsLabel, FlashcardDetailsList, FlashcardDetailsValue, FlashcardHero } from './components/flashcard/index.js';
|
|
89
|
+
export { FlashcardComponentProps, FlashcardDetailsListProps, FlashcardProps } from './components/flashcard/types.js';
|
|
88
90
|
export { HeroContext } from './components/hero/context.js';
|
|
89
91
|
export { Hero } from './components/hero/index.js';
|
|
90
92
|
export { HeroSubtitle } from './components/hero/subtitle.js';
|