@trellixio/roaster-react 2.0.0 → 2.1.1
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/cjs/components/ActionList/components/ActionListDropdown.js +11 -4
- package/cjs/components/ActionList/components/ActionListDropdown.js.map +1 -1
- package/cjs/components/DropdownCard/components/DropdownCardDropdown.js +8 -5
- package/cjs/components/DropdownCard/components/DropdownCardDropdown.js.map +1 -1
- package/cjs/components/Modal/Modal.js +7 -1
- package/cjs/components/Modal/Modal.js.map +1 -1
- package/cjs/components/Sidebar/Sidebar.js +35 -22
- package/cjs/components/Sidebar/Sidebar.js.map +1 -1
- package/cjs/components/Table/Table.js +4 -1
- package/cjs/components/Table/Table.js.map +1 -1
- package/cjs/components/Table/components/TableCell.js +3 -1
- package/cjs/components/Table/components/TableCell.js.map +1 -1
- package/cjs/components/Table/components/TableHeadCell.js +2 -2
- package/cjs/components/Table/components/TableHeadCell.js.map +1 -1
- package/cjs/tokens/tokens.js +3 -0
- package/cjs/tokens/tokens.js.map +1 -1
- package/cjs/utils/useMediaQuery/index.js +41 -0
- package/cjs/utils/useMediaQuery/index.js.map +1 -0
- package/esm/components/ActionList/components/ActionListDropdown.js +10 -3
- package/esm/components/ActionList/components/ActionListDropdown.js.map +1 -1
- package/esm/components/DropdownCard/components/DropdownCardDropdown.js +6 -3
- package/esm/components/DropdownCard/components/DropdownCardDropdown.js.map +1 -1
- package/esm/components/Modal/Modal.js +7 -1
- package/esm/components/Modal/Modal.js.map +1 -1
- package/esm/components/Sidebar/Sidebar.js +35 -22
- package/esm/components/Sidebar/Sidebar.js.map +1 -1
- package/esm/components/Table/Table.js +4 -1
- package/esm/components/Table/Table.js.map +1 -1
- package/esm/components/Table/components/TableCell.js +3 -1
- package/esm/components/Table/components/TableCell.js.map +1 -1
- package/esm/components/Table/components/TableHeadCell.js +2 -2
- package/esm/components/Table/components/TableHeadCell.js.map +1 -1
- package/esm/tokens/tokens.js +3 -0
- package/esm/tokens/tokens.js.map +1 -1
- package/esm/utils/useMediaQuery/index.js +25 -0
- package/esm/utils/useMediaQuery/index.js.map +1 -0
- package/fonts/jetbrains-mono/LICENSE +93 -0
- package/fonts/jetbrains-mono/jetbrains-mono-latin-wght-normal.woff2 +0 -0
- package/lib/components/ActionList/ActionList.d.ts +1 -1
- package/lib/components/ActionList/components/ActionListDropdown.d.ts +10 -2
- package/lib/components/ActionList/components/ActionListDropdown.d.ts.map +1 -1
- package/lib/components/DropdownCard/components/DropdownCardDropdown.d.ts +7 -0
- package/lib/components/DropdownCard/components/DropdownCardDropdown.d.ts.map +1 -1
- package/lib/components/Modal/Modal.d.ts.map +1 -1
- package/lib/components/Modal/types/index.d.ts +6 -0
- package/lib/components/Modal/types/index.d.ts.map +1 -1
- package/lib/components/Modal/utils/reducer.d.ts +1 -0
- package/lib/components/Modal/utils/reducer.d.ts.map +1 -1
- package/lib/components/Sidebar/Sidebar.d.ts +6 -3
- package/lib/components/Sidebar/Sidebar.d.ts.map +1 -1
- package/lib/components/Table/Table.d.ts +4 -2
- package/lib/components/Table/Table.d.ts.map +1 -1
- package/lib/components/Table/Table.types.d.ts +9 -0
- package/lib/components/Table/Table.types.d.ts.map +1 -1
- package/lib/components/Table/components/TableCell.d.ts +3 -1
- package/lib/components/Table/components/TableCell.d.ts.map +1 -1
- package/lib/components/Table/components/TableHeadCell.d.ts +3 -1
- package/lib/components/Table/components/TableHeadCell.d.ts.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/tokens/tokens.d.ts +3 -0
- package/lib/tokens/tokens.d.ts.map +1 -1
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.d.ts.map +1 -1
- package/lib/utils/useMediaQuery/index.d.ts +8 -0
- package/lib/utils/useMediaQuery/index.d.ts.map +1 -0
- package/package.json +8 -4
- package/roaster.css +1 -0
- package/themes/azoth.css +1 -0
- package/themes/azoth.css.d.ts +2 -0
- package/themes/coffee.css +1 -0
- package/themes/coffee.css.d.ts +2 -0
- package/themes/scalar.css +1 -0
- package/themes/scalar.css.d.ts +2 -0
- package/theme.css +0 -1
- /package/{theme.css.d.ts → roaster.css.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -18,11 +18,13 @@ touching a component.
|
|
|
18
18
|
npm install @trellixio/roaster-react
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
**2. Load the theme.** Import
|
|
22
|
-
the components. With the Next.js pages
|
|
21
|
+
**2. Load the CSS and a theme.** Import Roaster's CSS, then one theme (`coffee`, `azoth` or `scalar`), once, in your
|
|
22
|
+
app's entry file. These copies ship inside the package, so they always match the components. With the Next.js pages
|
|
23
|
+
router, import them in `_app.tsx`.
|
|
23
24
|
|
|
24
25
|
```tsx
|
|
25
|
-
import '@trellixio/roaster-react/
|
|
26
|
+
import '@trellixio/roaster-react/roaster.css';
|
|
27
|
+
import '@trellixio/roaster-react/themes/coffee.css';
|
|
26
28
|
```
|
|
27
29
|
|
|
28
30
|
**3. Load the icons.** Font Awesome is not inside the package. Add it to your HTML `<head>`:
|
|
@@ -34,8 +36,8 @@ import '@trellixio/roaster-react/theme.css';
|
|
|
34
36
|
You do not need `theme.js` from the CDN: the components handle their own behavior.
|
|
35
37
|
|
|
36
38
|
**4. Add the root and theme classes to `<html>`.** The base styles (page font, form controls) only apply inside
|
|
37
|
-
`roaster`, and
|
|
38
|
-
`roaster-theme-azoth` or `roaster-theme-scalar
|
|
39
|
+
`roaster`, and the theme's tokens only apply with its class, `roaster-theme-coffee`: there is no default theme.
|
|
40
|
+
`roaster-theme-azoth` or `roaster-theme-scalar`, with its file imported, picks the Azoth or the Scalar theme instead, with `roaster-dark` for
|
|
39
41
|
its dark look or `roaster-auto` for light or dark from the system setting, and Scalar takes `roaster-purple` for its
|
|
40
42
|
purple dark variant: see the Themes page of the docs. The components do not add them for you:
|
|
41
43
|
|
|
@@ -79,9 +81,9 @@ This package replaces `@trellixio/roaster-coffee`, which stays at 0.3.1 and gets
|
|
|
79
81
|
|
|
80
82
|
1. `npm uninstall @trellixio/roaster-coffee && npm install @trellixio/roaster-react`
|
|
81
83
|
2. Replace `@trellixio/roaster-coffee` with `@trellixio/roaster-react` in your imports.
|
|
82
|
-
3. Change `@trellixio/roaster-coffee/theme-coffee.css` to `@trellixio/roaster-react/
|
|
83
|
-
|
|
84
|
-
|
|
84
|
+
3. Change `@trellixio/roaster-coffee/theme-coffee.css` to `@trellixio/roaster-react/roaster.css` and
|
|
85
|
+
`@trellixio/roaster-react/themes/coffee.css`, and add `roaster-theme-coffee` next to `roaster` on `<html>`.
|
|
86
|
+
4. Import only from `@trellixio/roaster-react` and its stylesheets: deep imports no longer resolve.
|
|
85
87
|
5. Check the behavior changes in `Alert`, `RangeField`, `Switch`, `Radio`, `TextField`, `Tooltip`, `DatePicker`,
|
|
86
88
|
`Tag`, `BlockCard` and `CodeBlock`, listed in the
|
|
87
89
|
[changelog](https://github.com/trellixio/roaster/blob/main/packages/roaster-react/CHANGELOG.md).
|
|
@@ -6,7 +6,8 @@ var react = require('@floating-ui/react');
|
|
|
6
6
|
var React = require('react');
|
|
7
7
|
var reactDom = require('react-dom');
|
|
8
8
|
var ActionList_context = require('../ActionList.context.js');
|
|
9
|
-
var index = require('../../../utils/
|
|
9
|
+
var index = require('../../../utils/useMediaQuery/index.js');
|
|
10
|
+
var index$1 = require('../../../utils/classNames/index.js');
|
|
10
11
|
|
|
11
12
|
function _interopNamespaceDefault(e) {
|
|
12
13
|
var n = Object.create(null);
|
|
@@ -22,9 +23,10 @@ function _interopNamespaceDefault(e) {
|
|
|
22
23
|
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
23
24
|
|
|
24
25
|
const ActionListDropdown = React__namespace.forwardRef(
|
|
25
|
-
({ className, style, children, ...props }, propRef) => {
|
|
26
|
+
({ className, style, children, sheet = false, ...props }, propRef) => {
|
|
26
27
|
const { context: floatingContext, ...context } = ActionList_context.useActionListContext();
|
|
27
28
|
const ref = react.useMergeRefs([context.refs.setFloating, propRef]);
|
|
29
|
+
const asSheet = index.useMediaQuery(index.PHONE_QUERY) && sheet;
|
|
28
30
|
const [returnFocus, setReturnFocus] = React__namespace.useState(true);
|
|
29
31
|
React__namespace.useEffect(() => {
|
|
30
32
|
if (context.open) setReturnFocus(true);
|
|
@@ -47,8 +49,13 @@ const ActionListDropdown = React__namespace.forwardRef(
|
|
|
47
49
|
}
|
|
48
50
|
}
|
|
49
51
|
}),
|
|
50
|
-
className: index.classNames(
|
|
51
|
-
|
|
52
|
+
className: index$1.classNames(
|
|
53
|
+
"roaster-action-list",
|
|
54
|
+
"roaster-action-list--floating",
|
|
55
|
+
sheet && "roaster-action-list--sheet",
|
|
56
|
+
className
|
|
57
|
+
),
|
|
58
|
+
style: asSheet ? style : { ...context.floatingStyles, ...style },
|
|
52
59
|
children: /* @__PURE__ */ jsxRuntime.jsx(react.FloatingList, { elementsRef: context.elementsRef, labelsRef: context.labelsRef, children })
|
|
53
60
|
}
|
|
54
61
|
) })
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActionListDropdown.js","sources":["../../../../../src/components/ActionList/components/ActionListDropdown.tsx"],"sourcesContent":["import { FloatingFocusManager, FloatingList, useMergeRefs } from '@floating-ui/react';\nimport * as React from 'react';\nimport { flushSync } from 'react-dom';\nimport { classNames } from '@/utils';\nimport { useActionListContext } from '../ActionList.context';\n\n/** Every native `<div>` prop (`aria-label`, `className`, `style`...) is accepted and forwarded to the menu. */\nexport
|
|
1
|
+
{"version":3,"file":"ActionListDropdown.js","sources":["../../../../../src/components/ActionList/components/ActionListDropdown.tsx"],"sourcesContent":["import { FloatingFocusManager, FloatingList, useMergeRefs } from '@floating-ui/react';\nimport * as React from 'react';\nimport { flushSync } from 'react-dom';\nimport { PHONE_QUERY, classNames, useMediaQuery } from '@/utils';\nimport { useActionListContext } from '../ActionList.context';\n\n/** Every native `<div>` prop (`aria-label`, `className`, `style`...) is accepted and forwarded to the menu. */\nexport interface ActionListDropdownProps extends React.ComponentPropsWithoutRef<'div'> {\n /**\n * On a phone (480px wide at most), the menu rises from the window's bottom as a sheet, its full width, over the\n * dimmed page; on a wider screen it opens under its trigger as usual. Guidance: keep a menu beside its trigger; a\n * sheet suits a long one, such as a list of filters with a search.\n * @defaultValue false\n */\n sheet?: boolean;\n}\n\n/** The menu: its groups, dividers and items. Rendered while the action list is open. */\nexport const ActionListDropdown = React.forwardRef<HTMLDivElement, ActionListDropdownProps>(\n ({ className, style, children, sheet = false, ...props }, propRef) => {\n const { context: floatingContext, ...context } = useActionListContext();\n const ref = useMergeRefs([context.refs.setFloating, propRef]);\n // A sheet on a phone is placed by the CSS, at the window's bottom, not beside its trigger.\n const asSheet = useMediaQuery(PHONE_QUERY) && sheet;\n // Closing gives the focus back to the trigger, except when tabbing away: then it moves on from the trigger.\n const [returnFocus, setReturnFocus] = React.useState(true);\n React.useEffect(() => {\n if (context.open) setReturnFocus(true);\n }, [context.open]);\n if (!context.open) return null;\n\n return (\n // The list navigation moves the focus to the first item.\n <FloatingFocusManager context={floatingContext} modal={false} initialFocus={-1} returnFocus={returnFocus}>\n <div\n ref={ref}\n {...context.getFloatingProps({\n ...props,\n onKeyDown(event: React.KeyboardEvent<HTMLDivElement>) {\n props.onKeyDown?.(event);\n // Tabbing away closes the menu, and Tab moves on from the trigger, as if the menu weren't there.\n if (event.key === 'Tab') {\n flushSync(() => setReturnFocus(false));\n (context.refs.domReference.current as HTMLElement | null)?.focus();\n context.setOpen(false);\n }\n },\n })}\n // After the spread, so a caller's className and style add to these instead of replacing them.\n className={classNames(\n 'roaster-action-list',\n 'roaster-action-list--floating',\n sheet && 'roaster-action-list--sheet',\n className\n )}\n style={asSheet ? style : { ...context.floatingStyles, ...style }}\n >\n <FloatingList elementsRef={context.elementsRef} labelsRef={context.labelsRef}>\n {children}\n </FloatingList>\n </div>\n </FloatingFocusManager>\n );\n }\n);\n\nActionListDropdown.displayName = 'ActionListDropdown';\n"],"names":["React","useAct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KAAK,CAAC;AACtC,cAAc,IAAI,KAAK,CAAC,GAAG,KAAK,KAAK,EAAE;AACvC,gBAAgBE,kBAAS,CAAC,MAAM,cAAc,CAAC,KAAK,CAAC,CAAC;AACtD,gBAAgB,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,KAAK,EAAE;AAC1D,gBAAgB,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;AACtC,cAAc;AACd,YAAY;AACZ,WAAW,CAAC;AACZ,UAAU,SAAS,EAAEC,kBAAU;AAC/B,YAAY,qBAAqB;AACjC,YAAY,+BAA+B;AAC3C,YAAY,KAAK,IAAI,4BAA4B;AACjD,YAAY;AACZ,WAAW;AACX,UAAU,KAAK,EAAE,OAAO,GAAG,KAAK,GAAG,EAAE,GAAG,OAAO,CAAC,cAAc,EAAE,GAAG,KAAK,EAAE;AAC1E,UAAU,QAAQ,kBAAkBH,cAAG,CAACI,kBAAY,EAAE,EAAE,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,QAAQ,EAAE;AAClI;AACA,OAAO,EAAE;AACT;AACA,EAAE;AACF;AACA,kBAAkB,CAAC,WAAW,GAAG,oBAAoB;;"}
|
|
@@ -5,7 +5,8 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var react = require('@floating-ui/react');
|
|
7
7
|
var DropdownCard_context = require('../DropdownCard.context.js');
|
|
8
|
-
var index = require('../../../utils/
|
|
8
|
+
var index = require('../../../utils/useMediaQuery/index.js');
|
|
9
|
+
var index$1 = require('../../../utils/classNames/index.js');
|
|
9
10
|
|
|
10
11
|
function _interopNamespaceDefault(e) {
|
|
11
12
|
var n = Object.create(null);
|
|
@@ -21,25 +22,27 @@ function _interopNamespaceDefault(e) {
|
|
|
21
22
|
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
22
23
|
|
|
23
24
|
const DropdownCardDropdown = React__namespace.forwardRef(
|
|
24
|
-
({ className, style, children, variant = "default", ...props }, propRef) => {
|
|
25
|
+
({ className, style, children, variant = "default", sheet = false, ...props }, propRef) => {
|
|
25
26
|
const { context: floatingContext, ...context } = DropdownCard_context.useDropdownCardContext();
|
|
26
27
|
const ref = react.useMergeRefs([context.refs.setFloating, propRef]);
|
|
28
|
+
const asSheet = index.useMediaQuery(index.PHONE_QUERY) && sheet;
|
|
27
29
|
if (!context.open) return null;
|
|
28
30
|
return /* @__PURE__ */ jsxRuntime.jsx(react.FloatingFocusManager, { context: floatingContext, modal: false, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
29
31
|
"div",
|
|
30
32
|
{
|
|
31
33
|
ref,
|
|
32
34
|
...context.getFloatingProps(props),
|
|
33
|
-
className: index.classNames(
|
|
35
|
+
className: index$1.classNames(
|
|
34
36
|
"roaster-dropdown-card",
|
|
35
37
|
"roaster-dropdown-card--floating",
|
|
36
38
|
{
|
|
37
39
|
"roaster-dropdown-card--compact": variant === "compact",
|
|
38
|
-
"roaster-dropdown-card--tabs": variant === "tabs"
|
|
40
|
+
"roaster-dropdown-card--tabs": variant === "tabs",
|
|
41
|
+
"roaster-dropdown-card--sheet": sheet
|
|
39
42
|
},
|
|
40
43
|
className
|
|
41
44
|
),
|
|
42
|
-
style: { ...context.floatingStyles, ...style },
|
|
45
|
+
style: asSheet ? style : { ...context.floatingStyles, ...style },
|
|
43
46
|
children
|
|
44
47
|
}
|
|
45
48
|
) });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DropdownCardDropdown.js","sources":["../../../../../src/components/DropdownCard/components/DropdownCardDropdown.tsx"],"sourcesContent":["import * as React from 'react';\nimport { FloatingFocusManager, useMergeRefs } from '@floating-ui/react';\nimport { useDropdownCardContext } from '../DropdownCard.context';\nimport { classNames } from '@/utils';\n\n/** Every native `<div>` prop (`aria-label`, `className`, `style`...) is accepted and forwarded to the card. */\nexport interface DropdownCardDropdownProps extends React.ComponentPropsWithoutRef<'div'> {\n /**\n * `compact`: a row or two of fields in a menu's frame, such as a sort order. `tabs`: a list of tabs beside the\n * content, with DropdownCard.Tabs.\n */\n variant?: 'default' | 'compact' | 'tabs';\n}\n\n/**\n * The card: its content and actions. Rendered while the dropdown card is open, after its trigger, so Tab goes from one\n * to the other; fixed, so a parent's overflow doesn't cut it.\n */\nexport const DropdownCardDropdown = React.forwardRef<HTMLDivElement, DropdownCardDropdownProps>(\n ({ className, style, children, variant = 'default', ...props }, propRef) => {\n const { context: floatingContext, ...context } = useDropdownCardContext();\n const ref = useMergeRefs([context.refs.setFloating, propRef]);\n if (!context.open) return null;\n\n return (\n <FloatingFocusManager context={floatingContext} modal={false}>\n <div\n ref={ref}\n {...context.getFloatingProps(props)}\n // After the spread, so a caller's className and style add to these instead of replacing them.\n className={classNames(\n 'roaster-dropdown-card',\n 'roaster-dropdown-card--floating',\n {\n 'roaster-dropdown-card--compact': variant === 'compact',\n 'roaster-dropdown-card--tabs': variant === 'tabs',\n },\n className\n )}\n style={{ ...context.floatingStyles, ...style }}\n >\n {children}\n </div>\n </FloatingFocusManager>\n );\n }\n);\n\nDropdownCardDropdown.displayName = 'DropdownCardDropdown';\n"],"names":["React","useDropdownCardContext","useMergeRefs","jsx","FloatingFocusManager","classNames"],"mappings":"
|
|
1
|
+
{"version":3,"file":"DropdownCardDropdown.js","sources":["../../../../../src/components/DropdownCard/components/DropdownCardDropdown.tsx"],"sourcesContent":["import * as React from 'react';\nimport { FloatingFocusManager, useMergeRefs } from '@floating-ui/react';\nimport { useDropdownCardContext } from '../DropdownCard.context';\nimport { PHONE_QUERY, classNames, useMediaQuery } from '@/utils';\n\n/** Every native `<div>` prop (`aria-label`, `className`, `style`...) is accepted and forwarded to the card. */\nexport interface DropdownCardDropdownProps extends React.ComponentPropsWithoutRef<'div'> {\n /**\n * `compact`: a row or two of fields in a menu's frame, such as a sort order. `tabs`: a list of tabs beside the\n * content, with DropdownCard.Tabs.\n */\n variant?: 'default' | 'compact' | 'tabs';\n /**\n * On a phone (480px wide at most), the card rises from the window's bottom as a sheet, its full width, over the\n * dimmed page; on a wider screen it opens under its trigger as usual. Guidance: a sheet suits a large card, such as\n * filters or a date; a small one (`compact`) stays beside its trigger.\n * @defaultValue false\n */\n sheet?: boolean;\n}\n\n/**\n * The card: its content and actions. Rendered while the dropdown card is open, after its trigger, so Tab goes from one\n * to the other; fixed, so a parent's overflow doesn't cut it.\n */\nexport const DropdownCardDropdown = React.forwardRef<HTMLDivElement, DropdownCardDropdownProps>(\n ({ className, style, children, variant = 'default', sheet = false, ...props }, propRef) => {\n const { context: floatingContext, ...context } = useDropdownCardContext();\n const ref = useMergeRefs([context.refs.setFloating, propRef]);\n // A sheet on a phone is placed by the CSS, at the window's bottom, not beside its trigger.\n const asSheet = useMediaQuery(PHONE_QUERY) && sheet;\n if (!context.open) return null;\n\n return (\n <FloatingFocusManager context={floatingContext} modal={false}>\n <div\n ref={ref}\n {...context.getFloatingProps(props)}\n // After the spread, so a caller's className and style add to these instead of replacing them.\n className={classNames(\n 'roaster-dropdown-card',\n 'roaster-dropdown-card--floating',\n {\n 'roaster-dropdown-card--compact': variant === 'compact',\n 'roaster-dropdown-card--tabs': variant === 'tabs',\n 'roaster-dropdown-card--sheet': sheet,\n },\n className\n )}\n style={asSheet ? style : { ...context.floatingStyles, ...style }}\n >\n {children}\n </div>\n </FloatingFocusManager>\n );\n }\n);\n\nDropdownCardDropdown.displayName = 'DropdownCardDropdown';\n"],"names":["React","useDropdownCardContext","useMergeRefs","useMediaQuery","PHONE_QUERY","jsx","FloatingFocusManager","classNames"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAMY,MAAC,oBAAoB,GAAGA,gBAAK,CAAC,UAAU;AACpD,EAAE,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,GAAG,SAAS,EAAE,KAAK,GAAG,KAAK,EAAE,GAAG,KAAK,EAAE,EAAE,OAAO,KAAK;AAC7F,IAAI,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,GAAG,OAAO,EAAE,GAAGC,2CAAsB,EAAE;AAC7E,IAAI,MAAM,GAAG,GAAGC,kBAAY,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AACjE,IAAI,MAAM,OAAO,GAAGC,mBAAa,CAACC,iBAAW,CAAC,IAAI,KAAK;AACvD,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,IAAI;AAClC,IAAI,uBAAuBC,cAAG,CAACC,0BAAoB,EAAE,EAAE,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,kBAAkBD,cAAG;AAC5H,MAAM,KAAK;AACX,MAAM;AACN,QAAQ,GAAG;AACX,QAAQ,GAAG,OAAO,CAAC,gBAAgB,CAAC,KAAK,CAAC;AAC1C,QAAQ,SAAS,EAAEE,kBAAU;AAC7B,UAAU,uBAAuB;AACjC,UAAU,iCAAiC;AAC3C,UAAU;AACV,YAAY,gCAAgC,EAAE,OAAO,KAAK,SAAS;AACnE,YAAY,6BAA6B,EAAE,OAAO,KAAK,MAAM;AAC7D,YAAY,8BAA8B,EAAE;AAC5C,WAAW;AACX,UAAU;AACV,SAAS;AACT,QAAQ,KAAK,EAAE,OAAO,GAAG,KAAK,GAAG,EAAE,GAAG,OAAO,CAAC,cAAc,EAAE,GAAG,KAAK,EAAE;AACxE,QAAQ;AACR;AACA,KAAK,EAAE,CAAC;AACR,EAAE;AACF;AACA,oBAAoB,CAAC,WAAW,GAAG,sBAAsB;;"}
|
|
@@ -36,6 +36,7 @@ const Modal = React__namespace.forwardRef((props, ref) => {
|
|
|
36
36
|
title,
|
|
37
37
|
description,
|
|
38
38
|
size = "small",
|
|
39
|
+
sheet = false,
|
|
39
40
|
footer,
|
|
40
41
|
labels,
|
|
41
42
|
children,
|
|
@@ -80,7 +81,12 @@ const Modal = React__namespace.forwardRef((props, ref) => {
|
|
|
80
81
|
"aria-describedby": description ? descriptionId : void 0,
|
|
81
82
|
...others,
|
|
82
83
|
ref: setRefs,
|
|
83
|
-
className: index$2.classNames(
|
|
84
|
+
className: index$2.classNames(
|
|
85
|
+
"roaster-modal",
|
|
86
|
+
size !== "small" && `roaster-modal--${size}`,
|
|
87
|
+
sheet && "roaster-modal--sheet",
|
|
88
|
+
className
|
|
89
|
+
),
|
|
84
90
|
onCancel: (event) => {
|
|
85
91
|
onCancel?.(event);
|
|
86
92
|
event.preventDefault();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Modal.js","sources":["../../../../src/components/Modal/Modal.tsx"],"sourcesContent":["import * as React from 'react';\nimport { classNames, useControllableState, useUid } from '@/utils';\nimport { ModalLabels, ModalProps } from './types';\nimport { ButtonIcon } from '../ButtonIcon';\nimport { Icon } from '@/components/Icon';\n\nconst defaultModalLabels: ModalLabels = { close: 'Close' };\n\n// A layout effect in the browser (the modal opens before it paints), and nothing on the server, which warns about one.\nconst useClientLayoutEffect = typeof window === 'undefined' ? React.useEffect : React.useLayoutEffect;\n\n/** Whether the pointer event happened outside the dialog's box, on its backdrop. */\nfunction onBackdrop(dialog: HTMLDialogElement, event: React.MouseEvent) {\n const box = dialog.getBoundingClientRect();\n return event.clientX < box.left || event.clientX > box.right || event.clientY < box.top || event.clientY > box.bottom;\n}\n\n/**\n * A dialog over the page (`<dialog>` opened with `showModal()`), with a title, content and an optional footer. The page\n * behind is inert and doesn't scroll; the close button, Escape and a click outside ask to close it; the focus goes\n * back where it was. Open it with `open`, or with `useModal().openModal()` inside a ModalProvider.\n */\nexport const Modal = React.forwardRef<HTMLDialogElement, ModalProps>((props, ref) => {\n const {\n open: openProp,\n defaultOpen = false,\n onOpenChange,\n title,\n description,\n size = 'small',\n footer,\n labels,\n children,\n className,\n onCancel,\n onMouseDown,\n onClick,\n ...others\n } = props;\n const [open, setOpen] = useControllableState({ value: openProp, defaultValue: defaultOpen, onChange: onOpenChange });\n const text = { ...defaultModalLabels, ...labels };\n const titleId = useUid();\n const descriptionId = useUid();\n const dialogRef = React.useRef<HTMLDialogElement | null>(null);\n const setRefs = React.useCallback(\n (dialog: HTMLDialogElement | null) => {\n dialogRef.current = dialog;\n if (typeof ref === 'function') ref(dialog);\n else if (ref) ref.current = dialog;\n },\n [ref]\n );\n // Set on mousedown, so that a selection dragged from inside the dialog to outside doesn't close it.\n const pressedOutside = React.useRef(false);\n\n // Shown as a modal once mounted. Unmounting removes it without close(), so the focus goes back by hand.\n useClientLayoutEffect(() => {\n if (!open) return undefined;\n const dialog = dialogRef.current;\n const previous = document.activeElement;\n if (dialog && !dialog.open) dialog.showModal();\n return () => {\n if (dialog?.open) dialog.close();\n if (previous instanceof HTMLElement && previous.isConnected) previous.focus({ preventScroll: true });\n };\n }, [open]);\n\n if (!open) return null;\n\n return (\n // The mouse handlers only add a click outside to close it; the keyboard has Escape, through the cancel event.\n // eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions\n <dialog\n aria-labelledby={title ? titleId : undefined}\n aria-describedby={description ? descriptionId : undefined}\n {...others}\n ref={setRefs}\n className={classNames('roaster-modal'
|
|
1
|
+
{"version":3,"file":"Modal.js","sources":["../../../../src/components/Modal/Modal.tsx"],"sourcesContent":["import * as React from 'react';\nimport { classNames, useControllableState, useUid } from '@/utils';\nimport { ModalLabels, ModalProps } from './types';\nimport { ButtonIcon } from '../ButtonIcon';\nimport { Icon } from '@/components/Icon';\n\nconst defaultModalLabels: ModalLabels = { close: 'Close' };\n\n// A layout effect in the browser (the modal opens before it paints), and nothing on the server, which warns about one.\nconst useClientLayoutEffect = typeof window === 'undefined' ? React.useEffect : React.useLayoutEffect;\n\n/** Whether the pointer event happened outside the dialog's box, on its backdrop. */\nfunction onBackdrop(dialog: HTMLDialogElement, event: React.MouseEvent) {\n const box = dialog.getBoundingClientRect();\n return event.clientX < box.left || event.clientX > box.right || event.clientY < box.top || event.clientY > box.bottom;\n}\n\n/**\n * A dialog over the page (`<dialog>` opened with `showModal()`), with a title, content and an optional footer. The page\n * behind is inert and doesn't scroll; the close button, Escape and a click outside ask to close it; the focus goes\n * back where it was. Open it with `open`, or with `useModal().openModal()` inside a ModalProvider.\n */\nexport const Modal = React.forwardRef<HTMLDialogElement, ModalProps>((props, ref) => {\n const {\n open: openProp,\n defaultOpen = false,\n onOpenChange,\n title,\n description,\n size = 'small',\n sheet = false,\n footer,\n labels,\n children,\n className,\n onCancel,\n onMouseDown,\n onClick,\n ...others\n } = props;\n const [open, setOpen] = useControllableState({ value: openProp, defaultValue: defaultOpen, onChange: onOpenChange });\n const text = { ...defaultModalLabels, ...labels };\n const titleId = useUid();\n const descriptionId = useUid();\n const dialogRef = React.useRef<HTMLDialogElement | null>(null);\n const setRefs = React.useCallback(\n (dialog: HTMLDialogElement | null) => {\n dialogRef.current = dialog;\n if (typeof ref === 'function') ref(dialog);\n else if (ref) ref.current = dialog;\n },\n [ref]\n );\n // Set on mousedown, so that a selection dragged from inside the dialog to outside doesn't close it.\n const pressedOutside = React.useRef(false);\n\n // Shown as a modal once mounted. Unmounting removes it without close(), so the focus goes back by hand.\n useClientLayoutEffect(() => {\n if (!open) return undefined;\n const dialog = dialogRef.current;\n const previous = document.activeElement;\n if (dialog && !dialog.open) dialog.showModal();\n return () => {\n if (dialog?.open) dialog.close();\n if (previous instanceof HTMLElement && previous.isConnected) previous.focus({ preventScroll: true });\n };\n }, [open]);\n\n if (!open) return null;\n\n return (\n // The mouse handlers only add a click outside to close it; the keyboard has Escape, through the cancel event.\n // eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions\n <dialog\n aria-labelledby={title ? titleId : undefined}\n aria-describedby={description ? descriptionId : undefined}\n {...others}\n ref={setRefs}\n className={classNames(\n 'roaster-modal',\n size !== 'small' && `roaster-modal--${size}`,\n sheet && 'roaster-modal--sheet',\n className\n )}\n onCancel={(event) => {\n onCancel?.(event);\n // Escape: the state closes the dialog, so a parent that keeps it open is obeyed.\n event.preventDefault();\n setOpen(false);\n }}\n onMouseDown={(event) => {\n onMouseDown?.(event);\n pressedOutside.current = event.target === event.currentTarget && onBackdrop(event.currentTarget, event);\n }}\n onClick={(event) => {\n onClick?.(event);\n const outside = event.target === event.currentTarget && onBackdrop(event.currentTarget, event);\n if (pressedOutside.current && outside) setOpen(false);\n pressedOutside.current = false;\n }}\n >\n <div className=\"roaster-modal__header\">\n {title && (\n <h2 className=\"roaster-modal__title\" id={titleId}>\n {title}\n </h2>\n )}\n <ButtonIcon size=\"medium\" aria-label={text.close} onClick={() => setOpen(false)}>\n <Icon name=\"xmark\" />\n </ButtonIcon>\n {description && (\n <p className=\"roaster-modal__description\" id={descriptionId}>\n {description}\n </p>\n )}\n </div>\n <div className=\"roaster-modal__body\">{children}</div>\n {footer && <div className=\"roaster-modal__footer\">{footer}</div>}\n </dialog>\n );\n});\n\nModal.displayName = 'Modal';\n"],"names":["React","useControllableState","useUid","jsxs","classNames","jsx","ButtonIcon","Icon"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAM,kBAAkB,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE;AAC7C,MAAM,qBAAqB,GAAG,OAAO,MAAM,KAAK,WAAW,GAAGA,gBAAK,CAAC,SAAS,GAAGA,gBAAK,CAAC,eAAe;AACrG,SAAS,UAAU,CAAC,MAAM,EAAE,KAAK,EAAE;AACnC,EAAE,MAAM,GAAG,GAAG,MAAM,CAAC,qBAAqB,EAAE;AAC5C,EAAE,OAAO,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC,IAAI,IAAI,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC,KAAK,IAAI,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC,GAAG,IAAI,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC,MAAM;AACvH;AACY,MAAC,KAAK,GAAGA,gBAAK,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK;AACtD,EAAE,MAAM;AACR,IAAI,IA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,EAAE,MAAM,EAAE;AACvG;AACA;AACA;AACA;AACA,CAAC;AACD,KAAK,CAAC,WAAW,GAAG,OAAO;;"}
|
|
@@ -25,7 +25,7 @@ function _interopNamespaceDefault(e) {
|
|
|
25
25
|
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
26
26
|
|
|
27
27
|
const isSection = (entry) => !Array.isArray(entry) && "items" in entry && "title" in entry;
|
|
28
|
-
const defaultSidebarLabels = { navigation: "Main", open: "Open the menu" };
|
|
28
|
+
const defaultSidebarLabels = { navigation: "Main", open: "Open the menu", close: "Close the menu" };
|
|
29
29
|
const keyOf = (item, index) => item.pathname ?? `item-${index}`;
|
|
30
30
|
const SidebarBase = React__namespace.forwardRef((props, ref) => {
|
|
31
31
|
const { mobileHeader, header, footer, activePath, onMenuItemClick, items, labels, className, id, ...others } = props;
|
|
@@ -126,27 +126,40 @@ const SidebarBase = React__namespace.forwardRef((props, ref) => {
|
|
|
126
126
|
),
|
|
127
127
|
mobileHeader
|
|
128
128
|
] }),
|
|
129
|
-
/* @__PURE__ */ jsxRuntime.
|
|
130
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
"
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
129
|
+
/* @__PURE__ */ jsxRuntime.jsxs("aside", { ...others, ...popover, id: sidebarId, ref: setRefs, className: index$1.classNames("roaster-sidebar", className), children: [
|
|
130
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
131
|
+
Button.Button,
|
|
132
|
+
{
|
|
133
|
+
variant: "secondary",
|
|
134
|
+
iconOnly: true,
|
|
135
|
+
className: "roaster-sidebar__close",
|
|
136
|
+
"aria-label": text.close,
|
|
137
|
+
onClick: () => panelRef.current?.hidePopover?.(),
|
|
138
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(Icon.Icon, { name: "xmark" })
|
|
139
|
+
}
|
|
140
|
+
),
|
|
141
|
+
/* @__PURE__ */ jsxRuntime.jsxs("nav", { className: "roaster-sidebar__nav", "aria-label": text.navigation, children: [
|
|
142
|
+
/* @__PURE__ */ jsxRuntime.jsx(Section.Section, { className: "roaster-sidebar__header", children: header }),
|
|
143
|
+
/* @__PURE__ */ jsxRuntime.jsx(Section.Section, { className: "roaster-sidebar__body", children: items.map(
|
|
144
|
+
(item, index) => isSection(item) ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
145
|
+
"section",
|
|
146
|
+
{
|
|
147
|
+
className: "roaster-sidebar__section",
|
|
148
|
+
"aria-labelledby": `${sidebarId}-section-${index}`,
|
|
149
|
+
children: [
|
|
150
|
+
/* @__PURE__ */ jsxRuntime.jsxs("h2", { className: "roaster-sidebar__label", id: `${sidebarId}-section-${index}`, children: [
|
|
151
|
+
item.title,
|
|
152
|
+
item.action
|
|
153
|
+
] }),
|
|
154
|
+
/* @__PURE__ */ jsxRuntime.jsx(Menu.Menu, { children: item.items.map(renderItem) })
|
|
155
|
+
]
|
|
156
|
+
},
|
|
157
|
+
`section-${index}`
|
|
158
|
+
) : Array.isArray(item) ? /* @__PURE__ */ jsxRuntime.jsx(Menu.Menu, { children: item.map(renderItem) }, `group-${keyOf(item[0] ?? { }, index)}`) : /* @__PURE__ */ jsxRuntime.jsx(Menu.Menu, { children: renderItem(item, index) }, `group-${keyOf(item, index)}`)
|
|
159
|
+
) }),
|
|
160
|
+
/* @__PURE__ */ jsxRuntime.jsx(Section.Section, { className: "roaster-sidebar__footer", children: footer })
|
|
161
|
+
] })
|
|
162
|
+
] })
|
|
150
163
|
] });
|
|
151
164
|
});
|
|
152
165
|
SidebarBase.displayName = "Sidebar";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Sidebar.js","sources":["../../../../src/components/Sidebar/Sidebar.tsx"],"sourcesContent":["import * as React from 'react';\nimport { classNames, useUid } from '@/utils';\nimport { Button } from '../Button';\nimport { Icon } from '@/components/Icon';\nimport { Section } from './components/Section';\nimport { Menu } from './components/Menu';\nimport type { MenuItemProps } from './components/MenuItem';\nimport { Back } from './components/Back';\n\n/** An item of the sidebar. Its other props (`href`, `onClick`...) go to its link. */\nexport interface SidebarItemProps extends Omit<MenuItemProps, 'children' | 'current'> {\n /** The text of the item. */\n label: React.ReactNode;\n /** The item's path: it is the current page when it matches `activePath`, and is passed to `onMenuItemClick`. */\n pathname?: string;\n /** The items under it, in a sub-menu that opens and closes. */\n subMenu?: SidebarItemProps[];\n}\n\n/** A labeled section of the sidebar, such as \"Company\" or \"Team\": a label over its items. */\nexport interface SidebarSection {\n /** The label, over the items. */\n title: React.ReactNode;\n /** A small button at the label's end, such as one that adds an item. */\n action?: React.ReactNode;\n /** The items of the section. */\n items: SidebarItemProps[];\n}\n\nconst isSection = (entry: SidebarItemProps | SidebarItemProps[] | SidebarSection): entry is SidebarSection =>\n !Array.isArray(entry) && 'items' in entry && 'title' in entry;\n\n/** The text of the sidebar, for other languages. */\nexport interface SidebarLabels {\n /** The name of the navigation, read by screen readers. */\n navigation: string;\n /** The name of the button that opens the sidebar on phones. */\n open: string;\n}\n\nconst defaultSidebarLabels: SidebarLabels = { navigation: 'Main', open: 'Open the menu' };\n\n/** Every native `<aside>` prop (`id`, `aria-*`, `data-*`, ...) is accepted and forwarded to it. */\nexport interface SidebarProps extends React.ComponentPropsWithoutRef<'aside'> {\n /** The top of the sidebar: the logo, buttons. */\n header?: React.ReactNode;\n /** The bottom of the sidebar: settings, the account. */\n footer?: React.ReactNode;\n /** The path of the current page: its item gets `aria-current=\"page\"`, and its sub-menu starts open. */\n activePath?: string;\n /** Next to the button that opens the sidebar on phones, such as the logo. */\n mobileHeader?: React.ReactNode;\n /**\n * The items. An array of items is a group, set apart from the next by a line or room; a section (`{ title, items }`)\n * is a group with a label over it.\n */\n items: (SidebarItemProps | SidebarItemProps[] | SidebarSection)[];\n /** Called when an item is clicked, with its pathname. */\n onMenuItemClick?: ({ itemId }: { itemId: string }) => void;\n /** The text of the sidebar, in English by default. */\n labels?: Partial<SidebarLabels>;\n}\n\nconst keyOf = (item: SidebarItemProps, index: number) => item.pathname ?? `item-${index}`;\n\nconst SidebarBase = React.forwardRef<HTMLElement, SidebarProps>((props, ref) => {\n const { mobileHeader, header, footer, activePath, onMenuItemClick, items, labels, className, id, ...others } = props;\n const text = { ...defaultSidebarLabels, ...labels };\n const sidebarId = useUid(id);\n const panelRef = React.useRef<HTMLElement | null>(null);\n const setRefs = React.useCallback(\n (panel: HTMLElement | null) => {\n panelRef.current = panel;\n if (typeof ref === 'function') ref(panel);\n else if (ref) ref.current = panel;\n },\n [ref]\n );\n\n // Whether the drawer is open on phones, for the opener's aria-expanded. The browser opens and closes it (popover).\n const [drawerOpen, setDrawerOpen] = React.useState(false);\n React.useEffect(() => {\n const panel = panelRef.current;\n const onToggle = (event: Event) => setDrawerOpen((event as ToggleEvent).newState === 'open');\n panel?.addEventListener('toggle', onToggle);\n return () => panel?.removeEventListener('toggle', onToggle);\n }, []);\n\n // The open sub-menus, by pathname: the current page's opens with it.\n const groupOf = React.useCallback(\n (path: string | undefined) =>\n items\n .flatMap((entry) => (isSection(entry) ? entry.items : entry))\n .find((item) => item.subMenu?.some((sub) => sub.pathname === path) || (item.subMenu && item.pathname === path))\n ?.pathname,\n [items]\n );\n const [openGroups, setOpenGroups] = React.useState(() => new Set([groupOf(activePath)].filter(Boolean)));\n React.useEffect(() => {\n const group = groupOf(activePath);\n if (group) setOpenGroups((open) => (open.has(group) ? open : new Set([...open, group])));\n }, [activePath, groupOf]);\n\n function onItemClick(item: SidebarItemProps) {\n if (item.pathname !== undefined) onMenuItemClick?.({ itemId: item.pathname });\n // On phones, choosing a page closes the drawer.\n if (!item.subMenu?.length && drawerOpen) panelRef.current?.hidePopover?.();\n }\n\n function renderItem(item: SidebarItemProps, index: number) {\n const { pathname, subMenu, icon, label, onClick, action, suffix, detail, ...linkProps } = item;\n if (subMenu && subMenu.length > 0) {\n const groupKey = keyOf(item, index);\n return (\n <li key={groupKey}>\n <details\n className=\"roaster-sidebar__group\"\n open={openGroups.has(groupKey)}\n onToggle={(event) => {\n const isOpen = event.currentTarget.open;\n setOpenGroups((open) => {\n if (open.has(groupKey) === isOpen) return open;\n const next = new Set(open);\n if (isOpen) next.add(groupKey);\n else next.delete(groupKey);\n return next;\n });\n }}\n >\n <summary className=\"roaster-sidebar__item\" onClick={() => onItemClick(item)}>\n {icon && <span className=\"roaster-sidebar__icon\">{icon}</span>}\n {label}\n {suffix != null && <span className=\"roaster-sidebar__end\">{suffix}</span>}\n {action && <span className=\"roaster-sidebar__end\">{action}</span>}\n </summary>\n <Menu.SubMenu>{subMenu.map((sub, subIndex) => renderItem(sub, subIndex))}</Menu.SubMenu>\n </details>\n </li>\n );\n }\n return (\n <Menu.Item\n key={keyOf(item, index)}\n {...linkProps}\n icon={icon}\n action={action}\n suffix={suffix}\n detail={detail}\n current={pathname !== undefined && pathname === activePath}\n onClick={(event) => {\n onClick?.(event);\n onItemClick(item);\n }}\n >\n {label}\n </Menu.Item>\n );\n }\n\n // `popover` isn't in React 18's types.\n const popover = { popover: 'auto' } as React.HTMLAttributes<HTMLElement>;\n\n return (\n <>\n <div className=\"roaster-sidebar-opener\">\n <Button\n variant=\"ghost\"\n iconOnly\n aria-label={text.open}\n aria-controls={sidebarId}\n aria-expanded={drawerOpen}\n onClick={() => panelRef.current?.showPopover?.()}\n >\n <Icon name=\"bars\" />\n </Button>\n {mobileHeader}\n </div>\n\n <aside {...others} {...popover} id={sidebarId} ref={setRefs} className={classNames('roaster-sidebar', className)}>\n <nav className=\"roaster-sidebar__nav\" aria-label={text.navigation}>\n <Section className=\"roaster-sidebar__header\">{header}</Section>\n <Section className=\"roaster-sidebar__body\">\n {items.map((item, index) =>\n isSection(item) ? (\n <section\n key={`section-${index}`}\n className=\"roaster-sidebar__section\"\n aria-labelledby={`${sidebarId}-section-${index}`}\n >\n <h2 className=\"roaster-sidebar__label\" id={`${sidebarId}-section-${index}`}>\n {item.title}\n {item.action}\n </h2>\n <Menu>{item.items.map(renderItem)}</Menu>\n </section>\n ) : Array.isArray(item) ? (\n <Menu key={`group-${keyOf(item[0] ?? { label: '' }, index)}`}>{item.map(renderItem)}</Menu>\n ) : (\n <Menu key={`group-${keyOf(item, index)}`}>{renderItem(item, index)}</Menu>\n )\n )}\n </Section>\n <Section className=\"roaster-sidebar__footer\">{footer}</Section>\n </nav>\n </aside>\n </>\n );\n});\n\nSidebarBase.displayName = 'Sidebar';\n\n/**\n * The navigation of an application: a header (the logo, or the account button with a Sidebar.Back under it), groups\n * of items with sub-menus (`<details>`), labeled sections, and a footer. The current\n * page's item has `aria-current=\"page\"`. On phones, it is a drawer (a popover) that a bar at the top opens.\n */\nexport const Sidebar = Object.assign(SidebarBase, { Section: Section, Menu: Menu, Back: Back });\n"],"names":["React","useUid","jsx","jsxs","Menu","Fragment","Button","Icon","classNames","Section","Back"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AASA,MAAM,SAAS,GAAG,CAAC,KAAK,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,OAAO,IAAI,KAAK,IAAI,OAAO,IAAI,KAAK;AAC1F,MAAM,oBAAoB,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE;AAC1E,MAAM,KAAK,GAAG,CAAC,IAAI,EAAE,KAAK,KAAK,IAAI,CAAC,QAAQ,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAC/D,MAAM,WAAW,GAAGA,gBAAK,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK;AACrD,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,EAA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AC1B,gBAAgB,IAAI,CAAC;AACrB,eAAe,EAAE,CAAC;AAClB,8BAA8BD,cAAG,CAACE,SAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE;AAChF;AACA,WAAW;AACX,UAAU,CAAC,QAAQ,EAAE,KAAK,CAAC;AAC3B,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,mBAAmBF,cAAG,CAACE,SAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAY,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,mBAAmBF,cAAG,CAACE,SAAI,EAAE,EAAE,QAAQ,EAAE,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;AACnP,OAAO,EAAE,CAAC;AACV,sBAAsBF,cAAG,CAACO,eAAO,EAAE,EAAE,SAAS,EAAE,yBAAyB,EAAE,QAAQ,EAAE,MAAM,EAAE;AAC7F,KAAK,EAAE,CAAC,EAAE;AACV,GAAG,EAAE,CAAC;AACN,CAAC,CAAC;AACF,WAAW,CAAC,WAAW,GAAG,SAAS;AACvB,MAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,WAAEA,eAAO,QAAEL,SAAI,QAAEM,SAAI,EAAE;;"}
|
|
1
|
+
{"version":3,"file":"Sidebar.js","sources":["../../../../src/components/Sidebar/Sidebar.tsx"],"sourcesContent":["import * as React from 'react';\nimport { classNames, useUid } from '@/utils';\nimport { Button } from '../Button';\nimport { Icon } from '@/components/Icon';\nimport { Section } from './components/Section';\nimport { Menu } from './components/Menu';\nimport type { MenuItemProps } from './components/MenuItem';\nimport { Back } from './components/Back';\n\n/** An item of the sidebar. Its other props (`href`, `onClick`...) go to its link. */\nexport interface SidebarItemProps extends Omit<MenuItemProps, 'children' | 'current'> {\n /** The text of the item. */\n label: React.ReactNode;\n /** The item's path: it is the current page when it matches `activePath`, and is passed to `onMenuItemClick`. */\n pathname?: string;\n /** The items under it, in a sub-menu that opens and closes. */\n subMenu?: SidebarItemProps[];\n}\n\n/** A labeled section of the sidebar, such as \"Company\" or \"Team\": a label over its items. */\nexport interface SidebarSection {\n /** The label, over the items. */\n title: React.ReactNode;\n /** A small button at the label's end, such as one that adds an item. */\n action?: React.ReactNode;\n /** The items of the section. */\n items: SidebarItemProps[];\n}\n\nconst isSection = (entry: SidebarItemProps | SidebarItemProps[] | SidebarSection): entry is SidebarSection =>\n !Array.isArray(entry) && 'items' in entry && 'title' in entry;\n\n/** The text of the sidebar, for other languages. */\nexport interface SidebarLabels {\n /** The name of the navigation, read by screen readers. */\n navigation: string;\n /** The name of the button that opens the sidebar where it is a drawer (up to 1024px). */\n open: string;\n /** The name of the button that closes it there. */\n close: string;\n}\n\nconst defaultSidebarLabels: SidebarLabels = { navigation: 'Main', open: 'Open the menu', close: 'Close the menu' };\n\n/** Every native `<aside>` prop (`id`, `aria-*`, `data-*`, ...) is accepted and forwarded to it. */\nexport interface SidebarProps extends React.ComponentPropsWithoutRef<'aside'> {\n /** The top of the sidebar: the logo, buttons. */\n header?: React.ReactNode;\n /** The bottom of the sidebar: settings, the account. */\n footer?: React.ReactNode;\n /** The path of the current page: its item gets `aria-current=\"page\"`, and its sub-menu starts open. */\n activePath?: string;\n /** Next to the button that opens the sidebar where it is a drawer, such as the logo. */\n mobileHeader?: React.ReactNode;\n /**\n * The items. An array of items is a group, set apart from the next by a line or room; a section (`{ title, items }`)\n * is a group with a label over it.\n */\n items: (SidebarItemProps | SidebarItemProps[] | SidebarSection)[];\n /** Called when an item is clicked, with its pathname. */\n onMenuItemClick?: ({ itemId }: { itemId: string }) => void;\n /** The text of the sidebar, in English by default. */\n labels?: Partial<SidebarLabels>;\n}\n\nconst keyOf = (item: SidebarItemProps, index: number) => item.pathname ?? `item-${index}`;\n\nconst SidebarBase = React.forwardRef<HTMLElement, SidebarProps>((props, ref) => {\n const { mobileHeader, header, footer, activePath, onMenuItemClick, items, labels, className, id, ...others } = props;\n const text = { ...defaultSidebarLabels, ...labels };\n const sidebarId = useUid(id);\n const panelRef = React.useRef<HTMLElement | null>(null);\n const setRefs = React.useCallback(\n (panel: HTMLElement | null) => {\n panelRef.current = panel;\n if (typeof ref === 'function') ref(panel);\n else if (ref) ref.current = panel;\n },\n [ref]\n );\n\n // Whether the drawer is open, for the opener's aria-expanded. The browser opens and closes it (popover).\n const [drawerOpen, setDrawerOpen] = React.useState(false);\n React.useEffect(() => {\n const panel = panelRef.current;\n const onToggle = (event: Event) => setDrawerOpen((event as ToggleEvent).newState === 'open');\n panel?.addEventListener('toggle', onToggle);\n return () => panel?.removeEventListener('toggle', onToggle);\n }, []);\n\n // The open sub-menus, by pathname: the current page's opens with it.\n const groupOf = React.useCallback(\n (path: string | undefined) =>\n items\n .flatMap((entry) => (isSection(entry) ? entry.items : entry))\n .find((item) => item.subMenu?.some((sub) => sub.pathname === path) || (item.subMenu && item.pathname === path))\n ?.pathname,\n [items]\n );\n const [openGroups, setOpenGroups] = React.useState(() => new Set([groupOf(activePath)].filter(Boolean)));\n React.useEffect(() => {\n const group = groupOf(activePath);\n if (group) setOpenGroups((open) => (open.has(group) ? open : new Set([...open, group])));\n }, [activePath, groupOf]);\n\n function onItemClick(item: SidebarItemProps) {\n if (item.pathname !== undefined) onMenuItemClick?.({ itemId: item.pathname });\n // Where the sidebar is a drawer, choosing a page closes it.\n if (!item.subMenu?.length && drawerOpen) panelRef.current?.hidePopover?.();\n }\n\n function renderItem(item: SidebarItemProps, index: number) {\n const { pathname, subMenu, icon, label, onClick, action, suffix, detail, ...linkProps } = item;\n if (subMenu && subMenu.length > 0) {\n const groupKey = keyOf(item, index);\n return (\n <li key={groupKey}>\n <details\n className=\"roaster-sidebar__group\"\n open={openGroups.has(groupKey)}\n onToggle={(event) => {\n const isOpen = event.currentTarget.open;\n setOpenGroups((open) => {\n if (open.has(groupKey) === isOpen) return open;\n const next = new Set(open);\n if (isOpen) next.add(groupKey);\n else next.delete(groupKey);\n return next;\n });\n }}\n >\n <summary className=\"roaster-sidebar__item\" onClick={() => onItemClick(item)}>\n {icon && <span className=\"roaster-sidebar__icon\">{icon}</span>}\n {label}\n {suffix != null && <span className=\"roaster-sidebar__end\">{suffix}</span>}\n {action && <span className=\"roaster-sidebar__end\">{action}</span>}\n </summary>\n <Menu.SubMenu>{subMenu.map((sub, subIndex) => renderItem(sub, subIndex))}</Menu.SubMenu>\n </details>\n </li>\n );\n }\n return (\n <Menu.Item\n key={keyOf(item, index)}\n {...linkProps}\n icon={icon}\n action={action}\n suffix={suffix}\n detail={detail}\n current={pathname !== undefined && pathname === activePath}\n onClick={(event) => {\n onClick?.(event);\n onItemClick(item);\n }}\n >\n {label}\n </Menu.Item>\n );\n }\n\n // `popover` isn't in React 18's types.\n const popover = { popover: 'auto' } as React.HTMLAttributes<HTMLElement>;\n\n return (\n <>\n <div className=\"roaster-sidebar-opener\">\n <Button\n variant=\"ghost\"\n iconOnly\n aria-label={text.open}\n aria-controls={sidebarId}\n aria-expanded={drawerOpen}\n onClick={() => panelRef.current?.showPopover?.()}\n >\n <Icon name=\"bars\" />\n </Button>\n {mobileHeader}\n </div>\n\n <aside {...others} {...popover} id={sidebarId} ref={setRefs} className={classNames('roaster-sidebar', className)}>\n <Button\n variant=\"secondary\"\n iconOnly\n className=\"roaster-sidebar__close\"\n aria-label={text.close}\n onClick={() => panelRef.current?.hidePopover?.()}\n >\n <Icon name=\"xmark\" />\n </Button>\n <nav className=\"roaster-sidebar__nav\" aria-label={text.navigation}>\n <Section className=\"roaster-sidebar__header\">{header}</Section>\n <Section className=\"roaster-sidebar__body\">\n {items.map((item, index) =>\n isSection(item) ? (\n <section\n key={`section-${index}`}\n className=\"roaster-sidebar__section\"\n aria-labelledby={`${sidebarId}-section-${index}`}\n >\n <h2 className=\"roaster-sidebar__label\" id={`${sidebarId}-section-${index}`}>\n {item.title}\n {item.action}\n </h2>\n <Menu>{item.items.map(renderItem)}</Menu>\n </section>\n ) : Array.isArray(item) ? (\n <Menu key={`group-${keyOf(item[0] ?? { label: '' }, index)}`}>{item.map(renderItem)}</Menu>\n ) : (\n <Menu key={`group-${keyOf(item, index)}`}>{renderItem(item, index)}</Menu>\n )\n )}\n </Section>\n <Section className=\"roaster-sidebar__footer\">{footer}</Section>\n </nav>\n </aside>\n </>\n );\n});\n\nSidebarBase.displayName = 'Sidebar';\n\n/**\n * The navigation of an application: a header (the logo, or the account button with a Sidebar.Back under it), groups\n * of items with sub-menus (`<details>`), labeled sections, and a footer. The current\n * page's item has `aria-current=\"page\"`. Up to a tablet's width (1024px), it is a drawer (a popover) that a bar at the\n * top opens, with a close button beside it.\n */\nexport const Sidebar = Object.assign(SidebarBase, { Section: Section, Menu: Menu, Back: Back });\n"],"names":["React","useUid","jsx","jsxs","Menu","Fragment","Button","Icon","classNames","Section","Back"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AASA,MAAM,SAAS,GAAG,CAAC,KAAK,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,OAAO,IAAI,KAAK,IAAI,OAAO,IAAI,KAAK;AAC1F,MAAM,oBAAoB,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,gBAAgB,EAAE;AACnG,MAAM,KAAK,GAAG,CAAC,IAAI,EAAE,KAAK,KAAK,IAAI,CAAC,QAAQ,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAC/D,MAAM,WAAW,GAAGA,gBAAK,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK;AACrD,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,e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,CAAC;AACN,CAAC,CAAC;AACF,WAAW,CAAC,WAAW,GAAG,SAAS;AACvB,MAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,WAAEA,eAAO,QAAEL,SAAI,QAAEM,SAAI,EAAE;;"}
|
|
@@ -103,7 +103,10 @@ const TableBase = React__namespace.forwardRef((props, ref) => {
|
|
|
103
103
|
ref,
|
|
104
104
|
className: index$1.classNames("roaster-table__table", { "roaster-table__table--browsable": browsable }, className),
|
|
105
105
|
children: [
|
|
106
|
-
columns && /* @__PURE__ */ jsxRuntime.jsx("colgroup", { children: columns.map((
|
|
106
|
+
columns && /* @__PURE__ */ jsxRuntime.jsx("colgroup", { children: columns.map((column, index) => {
|
|
107
|
+
const { width, priority } = typeof column === "object" ? column : { width: column, priority: void 0 };
|
|
108
|
+
return /* @__PURE__ */ jsxRuntime.jsx("col", { style: width === void 0 ? void 0 : { width }, "data-priority": priority }, index);
|
|
109
|
+
}) }),
|
|
107
110
|
children
|
|
108
111
|
]
|
|
109
112
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Table.js","sources":["../../../../src/components/Table/Table.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { Button } from '@/components/Button';\nimport { PaginationProps } from '@/components/Pagination';\n\nimport { Checkbox } from './components/Checkbox';\nimport { TableBody } from './components/TableBody';\nimport { TableGroup } from './components/TableGroup';\nimport { TableCell } from './components/TableCell';\nimport { TableHead } from './components/TableHead';\nimport { TableHeadCell, TableSortButton } from './components/TableHeadCell';\nimport { TablePagination, TablePaginationProps } from './components/TablePagination';\nimport { TableProvider } from './components/TableProvider';\nimport { TableRow } from './components/TableRow';\nimport { TableProviderProps, SELECT_ALL_ITEMS, useTableSelectionChange, useTableValue } from './utils/table';\nimport { defaultTableLabels, TableLabels, TableLabelsContext } from './labels';\n\nexport type { TableLabels } from './labels';\nimport { classNames } from '@/utils';\n\n/**\n * Every native `<table>` prop (`id`, `aria-*`, `className`...) is accepted and forwarded to the `<table>`, but the\n * obsolete `summary`.\n */\nexport interface NativeTableProps extends Omit<React.ComponentPropsWithoutRef<'table'>, 'summary'> {\n /** The table content: Table.Head and Table.Body. */\n children?: React.ReactNode;\n /**\n * Whether rows can be selected, with a checkbox column and a bulk-action bar.\n * @defaultValue false\n */\n selectable?: boolean;\n /**\n * Whether rows lead somewhere: they react to the pointer.\n * @defaultValue false\n */\n browsable?: boolean;\n /** The actions to be displayed when a row in the table is selected (optional). */\n selectActions?: React.ReactNode;\n /** The text of the table, in English by default. */\n labels?: Partial<TableLabels>;\n /**\n * The columns' widths, in order, in pixels or any CSS length: kept exactly, the table scrolling sideways when they\n * add up to more than its width.\n */\n columns?: (number | string)[];\n /** Reaches the edges of a full-width page, its rows from edge to edge. */\n bleed?: boolean;\n /** Shorter rows, such as a short list in a card. */\n compact?: boolean;\n /** Keeps the column titles in view: the rows scroll under them, in a box no taller than the window. */\n sticky?: boolean;\n /** Floats the bulk-action bar low in the window, in the middle of the content; the column titles stay. */\n floatingActions?: boolean;\n /** Draws a row's fill (hovered, pressed, open or checked) inset from the table's sides, with rounded ends. */\n insetRows?: boolean;\n /** More room above and below each row's cells, such as rows of two lines (a name and its description). */\n roomy?: boolean;\n /** Over the table: its filters, sorting and actions. */\n toolbar?: React.ReactNode;\n /** A band over the rows, such as totals (`StatCard.Group variant=\"compact\"`), with an action at its end. */\n summary?: React.ReactNode;\n}\n\n/**\n * This interface defines the props that can be passed to a table component that includes pagination.\n * It extends the `NativeTableProps` interface, and includes additional props related to pagination.\n */\ninterface TableBaseWithPagination extends NativeTableProps, Omit<TablePaginationProps, keyof PaginationProps> {\n /** A boolean indicating whether pagination should be displayed (required). */\n showPagination: true;\n /** A function that is called when the \"Next\" button is clicked (required). */\n onNextPage: () => void;\n /** A function that is called when the \"Previous\" button is clicked (required). */\n onPreviousPage: () => void;\n /** A boolean indicating whether there is a next page (required). */\n hasNextPage: boolean;\n /** A boolean indicating whether there is a previous page (required). */\n hasPreviousPage: boolean;\n /** CSS class names to be applied to the pagination element (optional). */\n paginationClassName?: string;\n /** Before the pagination's buttons, such as the number of rows (\"312 transactions\"). */\n count?: React.ReactNode;\n}\n\n/**\n * This interface defines the props that can be passed to a table component that does not include pagination.\n * It extends the `NativeTableProps` interface, and does not include any additional props.\n */\ninterface TableBaseWithoutPagination extends NativeTableProps {\n /** A boolean indicating whether pagination should be displayed (optional). */\n showPagination?: never;\n /** A function that is called when the \"Next\" button is clicked (optional). */\n onNextPage?: never;\n /** A function that is called when the \"Previous\" button is clicked (optional). */\n onPreviousPage?: never;\n /** A boolean indicating whether there is a next page (optional). */\n hasNextPage?: never;\n /** A boolean indicating whether there is a previous page (optional). */\n hasPreviousPage?: never;\n /** CSS class names to be applied to the pagination element (optional). */\n paginationClassName?: never;\n count?: never;\n}\n\n/**\n * This type defines the props that can be passed to a table component.\n * It includes the `TableBaseWithPagination` and `TableBaseWithoutPagination` interfaces,\n * and ensures that only one set of props is used at a time.\n */\nexport type TableBaseProps = TableBaseWithPagination | TableBaseWithoutPagination;\n\nconst TableBase = React.forwardRef<HTMLTableElement, TableBaseProps>((props, ref) => {\n const {\n children,\n showPagination,\n selectActions,\n browsable = false,\n labels,\n className,\n onNextPage,\n onPreviousPage,\n hasNextPage,\n hasPreviousPage,\n paginationClassName,\n count,\n columns,\n bleed = false,\n compact = false,\n sticky = false,\n floatingActions = false,\n insetRows = false,\n roomy = false,\n toolbar,\n summary,\n ...others\n } = props;\n const text = { ...defaultTableLabels, ...labels };\n const { bulkSelectState, itemCount, selectedItemsCount } = useTableValue();\n const handleSelectionChange = useTableSelectionChange();\n\n const handleSelectAllItems = React.useCallback(() => {\n handleSelectionChange(selectedItemsCount === SELECT_ALL_ITEMS ? 'page' : 'all');\n }, [handleSelectionChange, selectedItemsCount]);\n\n const handleTogglePage = React.useCallback(() => {\n handleSelectionChange('page');\n }, [handleSelectionChange]);\n\n return (\n <TableLabelsContext.Provider value={text}>\n <section\n className={classNames('roaster-table', {\n 'roaster-table--bleed': bleed,\n 'roaster-table--compact': compact,\n 'roaster-table--sticky': sticky,\n 'roaster-table--floating-actions': floatingActions,\n 'roaster-table--inset-rows': insetRows,\n 'roaster-table--roomy': roomy,\n })}\n >\n {toolbar != null && <section className=\"roaster-table-toolbar\">{toolbar}</section>}\n {summary != null && <div className=\"roaster-table__summary\">{summary}</div>}\n {bulkSelectState && (\n // data-state: shown even before the rows' checkboxes are (the CSS shows the bar from them too).\n <div className=\"roaster-table__bulk-actions\" data-state=\"open\">\n <div className=\"roaster-stack roaster-stack--spread\" style={{ alignItems: 'center' }}>\n <div className=\"roaster-stack\">\n <Checkbox\n onChange={() => handleTogglePage()}\n indeterminate={selectedItemsCount !== SELECT_ALL_ITEMS && selectedItemsCount < itemCount}\n checked\n label={\n <span className=\"roaster-table__selected-count\">{text.selectedCount(selectedItemsCount)}</span>\n }\n />\n {selectActions}\n </div>\n\n <div className=\"action\">\n <Button variant=\"plain\" onClick={() => handleSelectAllItems()}>\n {text.selectAll}\n </Button>\n </div>\n </div>\n </div>\n )}\n <div className=\"roaster-table__scroll\">\n <table\n {...others}\n ref={ref}\n className={classNames('roaster-table__table', { 'roaster-table__table--browsable': browsable }, className)}\n >\n {columns && (\n <colgroup>\n {columns.map((width, index) => (\n <col key={index} style={{ width }} />\n ))}\n </colgroup>\n )}\n {children}\n </table>\n </div>\n {showPagination && (\n <TablePagination\n hasNextPage={hasNextPage}\n hasPreviousPage={hasPreviousPage}\n onNextPage={onNextPage}\n onPreviousPage={onPreviousPage}\n className={paginationClassName}\n count={count}\n labels={{ previousPage: text.previousPage, nextPage: text.nextPage }}\n />\n )}\n </section>\n </TableLabelsContext.Provider>\n );\n});\n\nTableBase.displayName = 'TableBase';\n\nexport type TableProps = TableBaseProps & TableProviderProps;\n\n/**\n * A data table with typed columns, optional row selection (a checkbox column, and a bulk-action bar in place of the\n * column titles while rows are selected), and pagination. Compose it with Table.Head, HeadCell, Body, Row and Cell\n * (Table.Group in place of Body for rows in groups, each under a title row); a\n * sortable column's title is a Table.SortButton, such as the trigger of a menu of sort orders. In a currency cell, the\n * cents can go in a `<sup>`; an enum cell can start with an `Icon`.\n */\nexport function Table({\n children,\n selectable = false,\n itemCount,\n selectedItemsCount = 0,\n onSelectionChange,\n ...tableBaseProps\n}: TableProps) {\n return (\n <TableProvider\n selectable={selectable}\n itemCount={itemCount}\n selectedItemsCount={selectedItemsCount}\n onSelectionChange={onSelectionChange}\n >\n <TableBase {...tableBaseProps}>{children}</TableBase>\n </TableProvider>\n );\n}\n\nTable.displayName = 'Table';\n\nTable.Head = TableHead;\nTable.Body = TableBody;\nTable.Group = TableGroup;\nTable.Row = TableRow;\nTable.HeadCell = TableHeadCell;\nTable.Cell = TableCell;\nTable.SortButton = TableSortButton;\n"],"names":["React","labels","defaultTableLabels","useTableValue","useTableSelectionChange","SELECT_ALL_ITEMS","jsx","TableLabelsContext","jsxs","classNames","Checkbox","Button","TablePagination","TableProvider","TableHead","TableBody","TableGroup","TableRow","TableHeadCell","TableCell","TableSortButton"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,MAAM,SAAS,GAAGA,gBAAK,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK;AACnD,EAAE,MAAM;AACR,IAAI,QAAQ;AACZ,IAAI,cAAc;AAClB,IAAI,aAAa;AACjB,IAAI,SAAS,GAAG,KAAK;AACrB,YAAIC,QAAM;AACV,IAAI,SAAS;AACb,IAAI,UAAU;AACd,IAAI,cAAc;AAClB,IAAI,WAAW;AACf,IAAI,eAAe;AACnB,IAAI,mBAAmB;AACvB,IAAI,KAAK;AACT,IAAI,OAAO;AACX,IAAI,KAAK,GAAG,KAAK;AACjB,IAAI,OAAO,GAAG,KAAK;AACnB,IAAI,MAAM,GAAG,KAAK;AAClB,IAAI,eAAe,GAAG,KAAK;AAC3B,IAAI,SAAS,GAAG,KAAK;AACrB,IAAI,KAAK,GAAG,KAAK;AACjB,IAAI,OAAO;AACX,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AC9E;AACA,GAAG;AACH;AACA,KAAK,CAAC,WAAW,GAAG,OAAO;AAC3B,KAAK,CAAC,IAAI,GAAGQ,mBAAS;AACtB,KAAK,CAAC,IAAI,GAAGC,mBAAS;AACtB,KAAK,CAAC,KAAK,GAAGC,qBAAU;AACxB,KAAK,CAAC,GAAG,GAAGC,iBAAQ;AACpB,KAAK,CAAC,QAAQ,GAAGC,2BAAa;AAC9B,KAAK,CAAC,IAAI,GAAGC,mBAAS;AACtB,KAAK,CAAC,UAAU,GAAGC,6BAAe;;"}
|
|
1
|
+
{"version":3,"file":"Table.js","sources":["../../../../src/components/Table/Table.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { Button } from '@/components/Button';\nimport { PaginationProps } from '@/components/Pagination';\n\nimport { Checkbox } from './components/Checkbox';\nimport { TableBody } from './components/TableBody';\nimport { TableGroup } from './components/TableGroup';\nimport { TableCell } from './components/TableCell';\nimport { TableHead } from './components/TableHead';\nimport { TableHeadCell, TableSortButton } from './components/TableHeadCell';\nimport { TablePagination, TablePaginationProps } from './components/TablePagination';\nimport { TableProvider } from './components/TableProvider';\nimport { TableRow } from './components/TableRow';\nimport type { TableColumn } from './Table.types';\nimport { TableProviderProps, SELECT_ALL_ITEMS, useTableSelectionChange, useTableValue } from './utils/table';\nimport { defaultTableLabels, TableLabels, TableLabelsContext } from './labels';\n\nexport type { TableLabels } from './labels';\nimport { classNames } from '@/utils';\n\n/**\n * Every native `<table>` prop (`id`, `aria-*`, `className`...) is accepted and forwarded to the `<table>`, but the\n * obsolete `summary`.\n */\nexport interface NativeTableProps extends Omit<React.ComponentPropsWithoutRef<'table'>, 'summary'> {\n /** The table content: Table.Head and Table.Body. */\n children?: React.ReactNode;\n /**\n * Whether rows can be selected, with a checkbox column and a bulk-action bar.\n * @defaultValue false\n */\n selectable?: boolean;\n /**\n * Whether rows lead somewhere: they react to the pointer.\n * @defaultValue false\n */\n browsable?: boolean;\n /** The actions to be displayed when a row in the table is selected (optional). */\n selectActions?: React.ReactNode;\n /** The text of the table, in English by default. */\n labels?: Partial<TableLabels>;\n /**\n * The columns' widths, in order, in pixels or any CSS length: kept exactly, the table scrolling sideways when they\n * add up to more than its width. With a selection column, the first is its own. A column can be `{ width, priority }`:\n * `priority: 'secondary'` hides it on a phone (its cells take the same `priority`).\n */\n columns?: (number | string | TableColumn)[];\n /** Reaches the edges of a full-width page, its rows from edge to edge. */\n bleed?: boolean;\n /** Shorter rows, such as a short list in a card. */\n compact?: boolean;\n /** Keeps the column titles in view: the rows scroll under them, in a box no taller than the window. */\n sticky?: boolean;\n /** Floats the bulk-action bar low in the window, in the middle of the content; the column titles stay. */\n floatingActions?: boolean;\n /** Draws a row's fill (hovered, pressed, open or checked) inset from the table's sides, with rounded ends. */\n insetRows?: boolean;\n /** More room above and below each row's cells, such as rows of two lines (a name and its description). */\n roomy?: boolean;\n /** Over the table: its filters, sorting and actions. */\n toolbar?: React.ReactNode;\n /** A band over the rows, such as totals (`StatCard.Group variant=\"compact\"`), with an action at its end. */\n summary?: React.ReactNode;\n}\n\n/**\n * This interface defines the props that can be passed to a table component that includes pagination.\n * It extends the `NativeTableProps` interface, and includes additional props related to pagination.\n */\ninterface TableBaseWithPagination extends NativeTableProps, Omit<TablePaginationProps, keyof PaginationProps> {\n /** A boolean indicating whether pagination should be displayed (required). */\n showPagination: true;\n /** A function that is called when the \"Next\" button is clicked (required). */\n onNextPage: () => void;\n /** A function that is called when the \"Previous\" button is clicked (required). */\n onPreviousPage: () => void;\n /** A boolean indicating whether there is a next page (required). */\n hasNextPage: boolean;\n /** A boolean indicating whether there is a previous page (required). */\n hasPreviousPage: boolean;\n /** CSS class names to be applied to the pagination element (optional). */\n paginationClassName?: string;\n /** Before the pagination's buttons, such as the number of rows (\"312 transactions\"). */\n count?: React.ReactNode;\n}\n\n/**\n * This interface defines the props that can be passed to a table component that does not include pagination.\n * It extends the `NativeTableProps` interface, and does not include any additional props.\n */\ninterface TableBaseWithoutPagination extends NativeTableProps {\n /** A boolean indicating whether pagination should be displayed (optional). */\n showPagination?: never;\n /** A function that is called when the \"Next\" button is clicked (optional). */\n onNextPage?: never;\n /** A function that is called when the \"Previous\" button is clicked (optional). */\n onPreviousPage?: never;\n /** A boolean indicating whether there is a next page (optional). */\n hasNextPage?: never;\n /** A boolean indicating whether there is a previous page (optional). */\n hasPreviousPage?: never;\n /** CSS class names to be applied to the pagination element (optional). */\n paginationClassName?: never;\n count?: never;\n}\n\n/**\n * This type defines the props that can be passed to a table component.\n * It includes the `TableBaseWithPagination` and `TableBaseWithoutPagination` interfaces,\n * and ensures that only one set of props is used at a time.\n */\nexport type TableBaseProps = TableBaseWithPagination | TableBaseWithoutPagination;\n\nconst TableBase = React.forwardRef<HTMLTableElement, TableBaseProps>((props, ref) => {\n const {\n children,\n showPagination,\n selectActions,\n browsable = false,\n labels,\n className,\n onNextPage,\n onPreviousPage,\n hasNextPage,\n hasPreviousPage,\n paginationClassName,\n count,\n columns,\n bleed = false,\n compact = false,\n sticky = false,\n floatingActions = false,\n insetRows = false,\n roomy = false,\n toolbar,\n summary,\n ...others\n } = props;\n const text = { ...defaultTableLabels, ...labels };\n const { bulkSelectState, itemCount, selectedItemsCount } = useTableValue();\n const handleSelectionChange = useTableSelectionChange();\n\n const handleSelectAllItems = React.useCallback(() => {\n handleSelectionChange(selectedItemsCount === SELECT_ALL_ITEMS ? 'page' : 'all');\n }, [handleSelectionChange, selectedItemsCount]);\n\n const handleTogglePage = React.useCallback(() => {\n handleSelectionChange('page');\n }, [handleSelectionChange]);\n\n return (\n <TableLabelsContext.Provider value={text}>\n <section\n className={classNames('roaster-table', {\n 'roaster-table--bleed': bleed,\n 'roaster-table--compact': compact,\n 'roaster-table--sticky': sticky,\n 'roaster-table--floating-actions': floatingActions,\n 'roaster-table--inset-rows': insetRows,\n 'roaster-table--roomy': roomy,\n })}\n >\n {toolbar != null && <section className=\"roaster-table-toolbar\">{toolbar}</section>}\n {summary != null && <div className=\"roaster-table__summary\">{summary}</div>}\n {bulkSelectState && (\n // data-state: shown even before the rows' checkboxes are (the CSS shows the bar from them too).\n <div className=\"roaster-table__bulk-actions\" data-state=\"open\">\n <div className=\"roaster-stack roaster-stack--spread\" style={{ alignItems: 'center' }}>\n <div className=\"roaster-stack\">\n <Checkbox\n onChange={() => handleTogglePage()}\n indeterminate={selectedItemsCount !== SELECT_ALL_ITEMS && selectedItemsCount < itemCount}\n checked\n label={\n <span className=\"roaster-table__selected-count\">{text.selectedCount(selectedItemsCount)}</span>\n }\n />\n {selectActions}\n </div>\n\n <div className=\"action\">\n <Button variant=\"plain\" onClick={() => handleSelectAllItems()}>\n {text.selectAll}\n </Button>\n </div>\n </div>\n </div>\n )}\n <div className=\"roaster-table__scroll\">\n <table\n {...others}\n ref={ref}\n className={classNames('roaster-table__table', { 'roaster-table__table--browsable': browsable }, className)}\n >\n {columns && (\n <colgroup>\n {columns.map((column, index) => {\n const { width, priority } =\n typeof column === 'object' ? column : { width: column, priority: undefined };\n return (\n <col key={index} style={width === undefined ? undefined : { width }} data-priority={priority} />\n );\n })}\n </colgroup>\n )}\n {children}\n </table>\n </div>\n {showPagination && (\n <TablePagination\n hasNextPage={hasNextPage}\n hasPreviousPage={hasPreviousPage}\n onNextPage={onNextPage}\n onPreviousPage={onPreviousPage}\n className={paginationClassName}\n count={count}\n labels={{ previousPage: text.previousPage, nextPage: text.nextPage }}\n />\n )}\n </section>\n </TableLabelsContext.Provider>\n );\n});\n\nTableBase.displayName = 'TableBase';\n\nexport type TableProps = TableBaseProps & TableProviderProps;\n\n/**\n * A data table with typed columns, optional row selection (a checkbox column, and a bulk-action bar in place of the\n * column titles while rows are selected), and pagination. Compose it with Table.Head, HeadCell, Body, Row and Cell\n * (Table.Group in place of Body for rows in groups, each under a title row); a\n * sortable column's title is a Table.SortButton, such as the trigger of a menu of sort orders. In a currency cell, the\n * cents can go in a `<sup>`; an enum cell can start with an `Icon`.\n */\nexport function Table({\n children,\n selectable = false,\n itemCount,\n selectedItemsCount = 0,\n onSelectionChange,\n ...tableBaseProps\n}: TableProps) {\n return (\n <TableProvider\n selectable={selectable}\n itemCount={itemCount}\n selectedItemsCount={selectedItemsCount}\n onSelectionChange={onSelectionChange}\n >\n <TableBase {...tableBaseProps}>{children}</TableBase>\n </TableProvider>\n );\n}\n\nTable.displayName = 'Table';\n\nTable.Head = TableHead;\nTable.Body = TableBody;\nTable.Group = TableGroup;\nTable.Row = TableRow;\nTable.HeadCell = TableHeadCell;\nTable.Cell = TableCell;\nTable.SortButton = TableSortButton;\n"],"names":["React","labels","defaultTableLabels","useTableValue","useTableSelectionChange","SELECT_ALL_ITEMS","jsx","TableLabelsContext","jsxs","classNames","Checkbox","Button","TablePagination","TableProvider","TableHead","TableBody","TableGroup","TableRow","TableHeadCell","TableCell","TableSortButton"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,MAAM,SAAS,GAAGA,gBAAK,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK;AACnD,EAAE,MAAM;AACR,IAAI,QAAQ;AACZ,IAAI,cAAc;AAClB,IAAI,aAAa;AACjB,IAAI,SAAS,GAAG,KAAK;AACrB,YAAIC,QAAM;AACV,IAAI,SAAS;AACb,IAAI,UAAU;AACd,IAAI,cAAc;AAClB,IAAI,WAAW;AACf,IAAI,eAAe;AACnB,IAAI,mBAAmB;AACvB,IAAI,KAAK;AACT,IAAI,OAAO;AACX,IAAI,KAAK,GAAG,KAAK;AACjB,IAAI,OAAO,GAAG,KAAK;AACnB,IAAI,MAAM,GAAG,KAAK;AAClB,IAAI,eAAe,GAAG,KAAK;AAC3B,IAAI,SAAS,GAAG,KAAK;AACrB,IAAI,KAAK,GAAG,KAAK;AACjB,IAAI,OAAO;AACX,IAAI,OAAO;AACX,IAAI,GAAG;AACP,GAAG,GAAG,KAAK;AACX,EAAE,MAAM,IAAI,GAAG,EAAE,GAAGC,yBAAkB,EAAE,GAAGD,QAAM,EAAE;AACnD,EAAE,MAAM,EAAE,eAAe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BAAiB;AACvB,MAAM,QAAQ,kBAAkBP,cAAG,CAAC,SAAS,EAAE,EAAE,GAAG,cAAc,EAAE,QAAQ,EAAE;AAC9E;AACA,GAAG;AACH;AACA,KAAK,CAAC,WAAW,GAAG,OAAO;AAC3B,KAAK,CAAC,IAAI,GAAGQ,mBAAS;AACtB,KAAK,CAAC,IAAI,GAAGC,mBAAS;AACtB,KAAK,CAAC,KAAK,GAAGC,qBAAU;AACxB,KAAK,CAAC,GAAG,GAAGC,iBAAQ;AACpB,KAAK,CAAC,QAAQ,GAAGC,2BAAa;AAC9B,KAAK,CAAC,IAAI,GAAGC,mBAAS;AACtB,KAAK,CAAC,UAAU,GAAGC,6BAAe;;"}
|
|
@@ -17,7 +17,9 @@ function _interopNamespaceDefault(e) {
|
|
|
17
17
|
|
|
18
18
|
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
19
19
|
|
|
20
|
-
const TableCell = React__namespace.forwardRef(
|
|
20
|
+
const TableCell = React__namespace.forwardRef(
|
|
21
|
+
({ children, type, priority, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx("td", { ...props, ref, "data-type": type, "data-priority": priority, children: type === "paragraph" ? /* @__PURE__ */ jsxRuntime.jsx("p", { children }) : children })
|
|
22
|
+
);
|
|
21
23
|
TableCell.displayName = "TableCell";
|
|
22
24
|
|
|
23
25
|
exports.TableCell = TableCell;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableCell.js","sources":["../../../../../src/components/Table/components/TableCell.tsx"],"sourcesContent":["import * as React from 'react';\nimport type { TableDataType } from '../Table.types';\n\n/** Every native `<td>` prop is accepted and forwarded to it. */\nexport interface TableCellProps extends React.ComponentPropsWithoutRef<'td'> {\n /** The column's kind of data, which aligns and wraps the cell (`data-type`). */\n type: TableDataType;\n /** The value. A `paragraph` is clamped to four lines. */\n children?: React.ReactNode;\n}\n\n/** A cell, typed by its column's kind of data. */\nexport const TableCell = React.forwardRef<HTMLTableCellElement, TableCellProps>(({ children, type, ...props }, ref) => (\n
|
|
1
|
+
{"version":3,"file":"TableCell.js","sources":["../../../../../src/components/Table/components/TableCell.tsx"],"sourcesContent":["import * as React from 'react';\nimport type { TableColumnPriority, TableDataType } from '../Table.types';\n\n/** Every native `<td>` prop is accepted and forwarded to it. */\nexport interface TableCellProps extends React.ComponentPropsWithoutRef<'td'> {\n /** The column's kind of data, which aligns and wraps the cell (`data-type`). */\n type: TableDataType;\n /** The value. A `paragraph` is clamped to four lines. */\n children?: React.ReactNode;\n /** `secondary`: hidden on a phone, with its column (give the column the same priority in `Table`'s `columns`). */\n priority?: TableColumnPriority;\n}\n\n/** A cell, typed by its column's kind of data. */\nexport const TableCell = React.forwardRef<HTMLTableCellElement, TableCellProps>(\n ({ children, type, priority, ...props }, ref) => (\n <td {...props} ref={ref} data-type={type} data-priority={priority}>\n {type === 'paragraph' ? <p>{children}</p> : children}\n </td>\n )\n);\nTableCell.displayName = 'TableCell';\n"],"names":["React","jsx"],"mappings":";;;;;;;;;;;;;;;;;;;AAGY,MAAC,SAAS,GAAGA,gBAAK,CAAC,UAAU;AACzC,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,GAAG,qBAAqBC,cAAG,CAAC,IAAI,EAAE,EAAE,GAAG,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,eAAe,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,KAAK,WAAW,mBAAmBA,cAAG,CAAC,GAAG,EAAE,EAAE,QAAQ,EAAE,CAAC,GAAG,QAAQ,EAAE;AAChO;AACA,SAAS,CAAC,WAAW,GAAG,WAAW;;"}
|
|
@@ -22,9 +22,9 @@ function _interopNamespaceDefault(e) {
|
|
|
22
22
|
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
23
23
|
|
|
24
24
|
const TableHeadCell = React__namespace.forwardRef(
|
|
25
|
-
({ title, type, description, tooltipProps, sort, children, ...props }, ref) => {
|
|
25
|
+
({ title, type, description, tooltipProps, sort, priority, children, ...props }, ref) => {
|
|
26
26
|
const text = React__namespace.useContext(labels.TableLabelsContext);
|
|
27
|
-
return /* @__PURE__ */ jsxRuntime.jsx("th", { ...props, ref, "data-type": type, "aria-sort": sort, children: /* @__PURE__ */ jsxRuntime.jsxs(SortContext.Provider, { value: sort, children: [
|
|
27
|
+
return /* @__PURE__ */ jsxRuntime.jsx("th", { ...props, ref, "data-type": type, "data-priority": priority, "aria-sort": sort, children: /* @__PURE__ */ jsxRuntime.jsxs(SortContext.Provider, { value: sort, children: [
|
|
28
28
|
title,
|
|
29
29
|
children,
|
|
30
30
|
description && " ",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableHeadCell.js","sources":["../../../../../src/components/Table/components/TableHeadCell.tsx"],"sourcesContent":["import * as React from 'react';\nimport { Tooltip, TooltipProps } from '@/components/Tooltip';\nimport { Icon } from '@/components/Icon';\nimport type { TableDataType } from '../Table.types';\nimport { TableLabelsContext } from '../labels';\nimport { classNames } from '@/utils';\n\n/** Every native `<th>` prop is accepted and forwarded to it. */\nexport interface TableHeadCellBaseProps extends Omit<React.ComponentPropsWithoutRef<'th'>, 'title'> {\n /** The column's kind of data, which aligns its cells (`data-type`). */\n type: TableDataType;\n /** What the column means, in a tooltip on an info button after the title. */\n description?: React.ReactNode;\n /** The tooltip's other props, such as `placement`. */\n tooltipProps?: Omit<TooltipProps, 'children' | 'label'>;\n /** How the column sorts the rows (`aria-sort`), with an arrow after its Table.SortButton's title. */\n sort?: 'ascending' | 'descending';\n}\n\nexport interface TableHeadCellPropsWithChildren extends TableHeadCellBaseProps {\n /** The title of the column. */\n children?: React.ReactNode;\n title?: never;\n}\n\nexport interface TableHeadCellPropsWithTitle extends TableHeadCellBaseProps {\n children?: never;\n /** The title of the column. */\n title?: React.ReactNode;\n}\n\nexport type TableHeadCellProps = TableHeadCellPropsWithChildren | TableHeadCellPropsWithTitle;\n\n/** A column title, with an optional info button that shows the column's description. */\nexport const TableHeadCell = React.forwardRef<HTMLTableCellElement, TableHeadCellProps>(\n ({ title, type, description, tooltipProps, sort, children, ...props }, ref) => {\n const text = React.useContext(TableLabelsContext);\n return (\n <th {...props} ref={ref} data-type={type} aria-sort={sort}>\n <SortContext.Provider value={sort}>\n {title}\n {children}\n {description && ' '}\n {description && (\n <Tooltip placement=\"bottom\" {...tooltipProps} label={description}>\n <button className=\"roaster-table__info\" type=\"button\" aria-label={text.columnInfo}>\n <Icon name=\"circle-info\" />\n </button>\n </Tooltip>\n )}\n </SortContext.Provider>\n </th>\n );\n }\n);\n\nTableHeadCell.displayName = 'TableHeadCell';\n\nconst SortContext = React.createContext<TableHeadCellBaseProps['sort']>(undefined);\n\n/** Every native `<button>` prop is accepted and forwarded to it. */\nexport interface TableSortButtonProps extends React.ComponentPropsWithoutRef<'button'> {\n /** The column's title. */\n children: React.ReactNode;\n}\n\n/**\n * A sortable column's title, as a button: it sorts the rows, or opens a menu of sort orders (in ActionList.Trigger).\n * The column's `sort` adds its arrow.\n */\nexport const TableSortButton = React.forwardRef<HTMLButtonElement, TableSortButtonProps>(\n ({ children, className, type = 'button', ...props }, ref) => {\n const sort = React.useContext(SortContext);\n return (\n <button {...props} ref={ref} type={type} className={classNames('roaster-table__sort', className)}>\n {children}\n {sort && <Icon name={sort === 'ascending' ? 'arrow-up' : 'arrow-down'} />}\n </button>\n );\n }\n);\nTableSortButton.displayName = 'TableSortButton';\n"],"names":["React","TableLabelsContext","jsx","jsxs","Tooltip","Icon","classNames"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAOY,MAAC,aAAa,GAAGA,gBAAK,CAAC,UAAU;AAC7C,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,GAAG,KAAK;
|
|
1
|
+
{"version":3,"file":"TableHeadCell.js","sources":["../../../../../src/components/Table/components/TableHeadCell.tsx"],"sourcesContent":["import * as React from 'react';\nimport { Tooltip, TooltipProps } from '@/components/Tooltip';\nimport { Icon } from '@/components/Icon';\nimport type { TableColumnPriority, TableDataType } from '../Table.types';\nimport { TableLabelsContext } from '../labels';\nimport { classNames } from '@/utils';\n\n/** Every native `<th>` prop is accepted and forwarded to it. */\nexport interface TableHeadCellBaseProps extends Omit<React.ComponentPropsWithoutRef<'th'>, 'title'> {\n /** The column's kind of data, which aligns its cells (`data-type`). */\n type: TableDataType;\n /** What the column means, in a tooltip on an info button after the title. */\n description?: React.ReactNode;\n /** The tooltip's other props, such as `placement`. */\n tooltipProps?: Omit<TooltipProps, 'children' | 'label'>;\n /** How the column sorts the rows (`aria-sort`), with an arrow after its Table.SortButton's title. */\n sort?: 'ascending' | 'descending';\n /** `secondary`: hidden on a phone, with its column (give the column the same priority in `Table`'s `columns`). */\n priority?: TableColumnPriority;\n}\n\nexport interface TableHeadCellPropsWithChildren extends TableHeadCellBaseProps {\n /** The title of the column. */\n children?: React.ReactNode;\n title?: never;\n}\n\nexport interface TableHeadCellPropsWithTitle extends TableHeadCellBaseProps {\n children?: never;\n /** The title of the column. */\n title?: React.ReactNode;\n}\n\nexport type TableHeadCellProps = TableHeadCellPropsWithChildren | TableHeadCellPropsWithTitle;\n\n/** A column title, with an optional info button that shows the column's description. */\nexport const TableHeadCell = React.forwardRef<HTMLTableCellElement, TableHeadCellProps>(\n ({ title, type, description, tooltipProps, sort, priority, children, ...props }, ref) => {\n const text = React.useContext(TableLabelsContext);\n return (\n <th {...props} ref={ref} data-type={type} data-priority={priority} aria-sort={sort}>\n <SortContext.Provider value={sort}>\n {title}\n {children}\n {description && ' '}\n {description && (\n <Tooltip placement=\"bottom\" {...tooltipProps} label={description}>\n <button className=\"roaster-table__info\" type=\"button\" aria-label={text.columnInfo}>\n <Icon name=\"circle-info\" />\n </button>\n </Tooltip>\n )}\n </SortContext.Provider>\n </th>\n );\n }\n);\n\nTableHeadCell.displayName = 'TableHeadCell';\n\nconst SortContext = React.createContext<TableHeadCellBaseProps['sort']>(undefined);\n\n/** Every native `<button>` prop is accepted and forwarded to it. */\nexport interface TableSortButtonProps extends React.ComponentPropsWithoutRef<'button'> {\n /** The column's title. */\n children: React.ReactNode;\n}\n\n/**\n * A sortable column's title, as a button: it sorts the rows, or opens a menu of sort orders (in ActionList.Trigger).\n * The column's `sort` adds its arrow.\n */\nexport const TableSortButton = React.forwardRef<HTMLButtonElement, TableSortButtonProps>(\n ({ children, className, type = 'button', ...props }, ref) => {\n const sort = React.useContext(SortContext);\n return (\n <button {...props} ref={ref} type={type} className={classNames('roaster-table__sort', className)}>\n {children}\n {sort && <Icon name={sort === 'ascending' ? 'arrow-up' : 'arrow-down'} />}\n </button>\n );\n }\n);\nTableSortButton.displayName = 'TableSortButton';\n"],"names":["React","TableLabelsContext","jsx","jsxs","Tooltip","Icon","classNames"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAOY,MAAC,aAAa,GAAGA,gBAAK,CAAC,UAAU;AAC7C,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,GAAG,KAAK;AAC3F,IAAI,MAAM,IAAI,GAAGA,gBAAK,CAAC,UAAU,CAACC,yBAAkB,CAAC;AACrD,IAAI,uBAAuBC,cAAG,CAAC,IAAI,EAAE,EAAE,GAAG,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,eAAe,EAAE,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ,kBAAkBC,eAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE;AACrM,MAAM,KAAK;AACX,MAAM,QAAQ;AACd,MAAM,WAAW,IAAI,GAAG;AACxB,MAAM,WAAW,oBAAoBD,cAAG,CAACE,eAAO,EAAE,EAAE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