@astryxdesign/cli 0.7.18-canary.gfacee17 → 0.7.18
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/CHANGELOG.md +185 -19
- package/README.md +19 -19
- package/api/component/_adapter.d.mts +2 -1
- package/api/component/_adapter.mjs +2 -1
- package/api/docs/_adapter.d.mts +6 -5
- package/api/docs/_adapter.mjs +36 -5
- package/api/doctor/_adapter.d.mts +6 -3
- package/api/doctor/_adapter.mjs +13 -5
- package/api/doctor/doctor.mjs +5 -5
- package/api/doctor/font-packages.d.mts +36 -0
- package/api/doctor/font-packages.mjs +124 -0
- package/api/doctor/theme-checks.mjs +110 -49
- package/api/experimental.d.mts +0 -2
- package/api/experimental.mjs +0 -12
- package/api/icon/_adapter.d.mts +2 -2
- package/api/icon/_adapter.mjs +6 -2
- package/api/icon/_authoring.mjs +22 -13
- package/api/icon/_default-look.mjs +15 -15
- package/api/icon/add/add.mjs +14 -9
- package/api/icon/icon.doc.mjs +7 -7
- package/api/icon/icon.type.d.mts +33 -33
- package/api/icon/icon.type.mjs +45 -45
- package/api/icon/iconAdd.doc.mjs +9 -10
- package/api/icon/iconMap.doc.mjs +11 -12
- package/api/icon/iconNewDefinition.doc.mjs +8 -8
- package/api/icon/iconNewSet.doc.mjs +5 -5
- package/api/icon/map/map.mjs +7 -7
- package/api/icon/use/use.mjs +4 -4
- package/api/init/run/run.mjs +0 -1
- package/api/integration/add-helpers.mjs +1 -1
- package/api/integration/validate-integration.type.d.mts +6 -6
- package/api/integration/validate-integration.type.mjs +6 -6
- package/api/render/_adapter.d.mts +5 -3
- package/api/render/_adapter.mjs +64 -4
- package/api/render/render.doc.mjs +9 -2
- package/api/render/render.mjs +5 -2
- package/api/render/render.type.d.mts +17 -0
- package/api/render/render.type.mjs +10 -0
- package/api/search/ORDERING.md +1 -1
- package/api/search/_candidate-score.mjs +20 -0
- package/api/search/_words.d.mts +8 -0
- package/api/search/_words.mjs +15 -0
- package/api/template/template.type.d.mts +2 -2
- package/api/template/template.type.mjs +2 -2
- package/api/theme/_adapter.mjs +19 -11
- package/api/theme/build/build.d.mts +19 -51
- package/api/theme/build/build.mjs +195 -189
- package/api/theme/build/font-warning.d.mts +19 -2
- package/api/theme/build/font-warning.mjs +46 -5
- package/api/theme/generateTonalPalette.doc.mjs +1 -1
- package/api/theme/palette/generate/derive-look.mjs +108 -37
- package/api/theme/palette/generate/mapping.mjs +2 -0
- package/api/theme/template/template.d.mts +0 -17
- package/api/theme/template/template.mjs +1 -42
- package/api/theme/theme.type.d.mts +5 -4
- package/api/theme/theme.type.mjs +5 -4
- package/api/theme/themePaletteGenerate.doc.mjs +1 -1
- package/api/theme/themeRemove.doc.mjs +1 -1
- package/assets/codemods/transforms/v0.7.0/preserve-bottom-sheet-content-padding.mjs +3 -1
- package/assets/component-list.generated.json +1 -1
- package/assets/discover/official-packages.json +26 -2
- package/assets/docs/author-a-theme.doc.mjs +6 -5
- package/assets/docs/browser-support.doc.mjs +1 -0
- package/assets/docs/icons.doc.mjs +8 -7
- package/assets/docs/motion.doc.mjs +46 -0
- package/assets/docs/theme.doc.dense.mjs +6 -17
- package/assets/docs/theme.doc.mjs +6 -16
- package/assets/docs/theme.doc.zh.mjs +6 -16
- package/assets/docs/tree/ci-and-containers.doc.mjs +1 -1
- package/assets/docs/tree/data-colors-in-renderers.doc.mjs +400 -0
- package/assets/docs/tree/font-setup.doc.mjs +30 -0
- package/assets/docs/tree/icon-sets.doc.mjs +2 -2
- package/assets/docs/tree/share-a-page.doc.mjs +1 -1
- package/assets/docs/tree/template-icons.doc.mjs +3 -3
- package/assets/docs/tree/tokens-color.doc.mjs +5 -0
- package/assets/docs/tree/tokens.doc.mjs +4 -3
- package/assets/docs/tree/updates.doc.mjs +1 -1
- package/assets/docs/tree/visualization.doc.mjs +30 -0
- package/assets/docs-routes.generated.json +1 -1
- package/assets/docs.generated.json +2 -2
- package/assets/icons/definitions/drag.doc.mjs +1 -0
- package/assets/search-catalog.generated.json +2 -2
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/Card/SelectableCardElevated.doc.mjs +1 -1
- package/assets/templates/blocks/components/Card/SelectableCardElevated.tsx +20 -10
- package/assets/templates/blocks/components/Card/SelectableCardShowcase.doc.mjs +1 -1
- package/assets/templates/blocks/components/Card/SelectableCardShowcase.tsx +36 -16
- package/assets/templates/blocks/components/ChatComposerInput/ChatComposerInputMentionTrigger.tsx +6 -0
- package/assets/templates/blocks/components/ChatComposerInput/ChatComposerInputMultipleTriggers.tsx +6 -0
- package/assets/templates/blocks/components/Hooks/useIndicatorFocusRingHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Hooks/useIndicatorFocusRingHookUsage.tsx +63 -0
- package/assets/templates/blocks/components/Hooks/useLongPressHookUsage.doc.mjs +29 -0
- package/assets/templates/blocks/components/Hooks/useLongPressHookUsage.tsx +237 -0
- package/assets/templates/blocks/components/SideNav/SideNavShowcase.tsx +10 -72
- package/assets/templates/blocks/components/SideNav/SideNavWithHeaderMenu.doc.mjs +1 -1
- package/assets/templates/blocks/components/SideNav/SideNavWithHeaderMenu.tsx +7 -7
- package/assets/templates/blocks/components/Table/TableCustomRowTable.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/TableCustomRowTable.tsx +96 -0
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/ai-chat-landing/page.tsx +4 -0
- package/assets/templates/pages/dashboard-scorecard/page.tsx +26 -7
- package/assets/templates/pages/editor/page.tsx +13 -3
- package/assets/templates/themes/butter/butterPaletteRefs.generated.ts +2 -2
- package/assets/templates/themes/butter/butterTheme.ts +12 -10
- package/assets/templates/themes/butter/icons.tsx +2 -0
- package/assets/templates/themes/chocolate/chocolateTheme.ts +1 -0
- package/assets/templates/themes/chocolate/icons.tsx +2 -0
- package/assets/templates/themes/gothic/gothicPaletteRefs.generated.ts +1 -1
- package/assets/templates/themes/gothic/gothicTheme.ts +1 -0
- package/assets/templates/themes/gothic/icons.tsx +2 -0
- package/assets/templates/themes/matcha/icons.tsx +2 -0
- package/assets/templates/themes/matcha/matchaPaletteRefs.generated.ts +2 -2
- package/assets/templates/themes/matcha/matchaTheme.ts +1 -0
- package/assets/templates/themes/neutral/icons.tsx +2 -0
- package/assets/templates/themes/neutral/neutralPaletteRefs.generated.ts +2 -2
- package/assets/templates/themes/neutral/neutralTheme.ts +1 -0
- package/assets/templates/themes/stone/icons.tsx +2 -0
- package/assets/templates/themes/stone/stonePaletteRefs.generated.ts +1 -1
- package/assets/templates/themes/stone/stoneTheme.ts +1 -0
- package/assets/templates/themes/y2k/icons.tsx +2 -0
- package/assets/templates/themes/y2k/y2kTheme.ts +1 -0
- package/assets/theme.template.ts +9 -5
- package/authoring/config/parse.mjs +1 -1
- package/authoring/doctypes/base/type.ts +2 -3
- package/authoring/doctypes/component/component.doc.mjs +1 -1
- package/authoring/doctypes/icon-set/icon-names.mjs +1 -0
- package/authoring/integration/integration.doc.mjs +1 -1
- package/authoring/integration/type.ts +1 -1
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/doctor.mjs +2 -2
- package/clients/cli/commands/experimental/export.mjs +2 -1
- package/clients/cli/commands/experimental/icon.mjs +17 -17
- package/clients/cli/commands/experimental/index.mjs +0 -5
- package/clients/cli/commands/experimental/render-output.mjs +9 -0
- package/clients/cli/commands/experimental-export.doc.mjs +6 -0
- package/clients/cli/commands/experimental-icon-add.doc.mjs +8 -8
- package/clients/cli/commands/experimental-icon-map.doc.mjs +6 -6
- package/clients/cli/commands/experimental-icon-new-definition.doc.mjs +6 -6
- package/clients/cli/commands/experimental-icon-new-set.doc.mjs +3 -3
- package/clients/cli/commands/experimental-icon-use.doc.mjs +1 -1
- package/clients/cli/commands/experimental-icon.doc.mjs +6 -6
- package/clients/cli/commands/experimental.doc.mjs +2 -6
- package/clients/cli/commands/template.mjs +1 -1
- package/clients/cli/commands/theme-build.doc.mjs +8 -1
- package/clients/cli/commands/theme-palette-generate.doc.mjs +1 -1
- package/clients/cli/commands/theme-remove.doc.mjs +1 -1
- package/clients/cli/commands/theme.doc.mjs +1 -11
- package/clients/cli/commands/theme.mjs +110 -475
- package/clients/cli/commands.generated.json +1 -1
- package/clients/cli/index.mjs +4 -34
- package/clients/cli/lib/base-gate.mjs +2 -3
- package/clients/cli/lib/cli-error.mjs +8 -72
- package/clients/cli/lib/define-command.mjs +0 -19
- package/clients/cli/lib/json-shim.mjs +11 -633
- package/clients/cli/lib/manifest.mjs +0 -4
- package/clients/cli/lib/stray-option.mjs +1 -2
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/agent-docs/agent-docs.mjs +1 -1
- package/foundation/color/css-color.mjs +2 -3
- package/foundation/discovery/app-layout.d.mts +13 -0
- package/foundation/discovery/app-layout.mjs +35 -0
- package/foundation/discovery/cli-self-docs.mjs +4 -4
- package/foundation/discovery/fixture-refs.d.mts +51 -0
- package/foundation/discovery/fixture-refs.mjs +351 -0
- package/foundation/discovery/icon-definition-discovery.mjs +7 -7
- package/foundation/discovery/icon-ranking.mjs +2 -2
- package/foundation/discovery/icon-set-checks.mjs +6 -6
- package/foundation/discovery/icon-set-discovery.mjs +2 -2
- package/foundation/discovery/icon-set-writer.d.mts +24 -7
- package/foundation/discovery/icon-set-writer.mjs +75 -31
- package/foundation/discovery/static-descriptor.d.mts +49 -0
- package/foundation/discovery/static-descriptor.mjs +548 -0
- package/foundation/discovery/template-adapter.d.mts +0 -47
- package/foundation/discovery/template-adapter.mjs +1 -333
- package/foundation/discovery/theme-discovery.d.mts +6 -47
- package/foundation/discovery/theme-discovery.mjs +15 -537
- package/foundation/doc-compiler/bundle.mjs +2 -2
- package/foundation/doc-compiler/import.mjs +1 -1
- package/foundation/env/user-dirs.d.mts +5 -2
- package/foundation/env/user-dirs.mjs +12 -5
- package/foundation/fonts/next-font.d.mts +26 -0
- package/foundation/fonts/next-font.mjs +149 -0
- package/foundation/fs/empty-folder.mjs +2 -2
- package/foundation/fs/read-record.mjs +11 -4
- package/foundation/pictures/pictures.d.mts +152 -0
- package/foundation/pictures/pictures.mjs +565 -0
- package/foundation/release/folder-lock.mjs +3 -2
- package/foundation/render/cut-short.d.mts +2 -2
- package/foundation/render/cut-short.mjs +2 -2
- package/foundation/render/drawn-contrast.d.mts +2 -2
- package/foundation/render/drawn-contrast.mjs +2 -2
- package/foundation/render/font-probe.d.mts +2 -2
- package/foundation/render/font-probe.mjs +2 -2
- package/foundation/render/layers.mjs +1 -2
- package/foundation/render/package-resolve-hooks.d.mts +25 -5
- package/foundation/render/package-resolve-hooks.mjs +77 -14
- package/foundation/render/page-worker.mjs +24 -12
- package/foundation/render/part-boxes.d.mts +2 -3
- package/foundation/render/part-boxes.mjs +2 -3
- package/foundation/render/picture-chrome.mjs +18 -15
- package/foundation/render/picture-playwright.mjs +10 -7
- package/foundation/render/picture-window.d.mts +13 -0
- package/foundation/render/picture-window.mjs +31 -0
- package/foundation/render/render-page.d.mts +1 -1
- package/foundation/render/render-page.mjs +4 -5
- package/foundation/render/single-copy-hooks.d.mts +2 -0
- package/foundation/render/single-copy-hooks.mjs +2 -0
- package/foundation/response/error-codes.doc.mjs +14 -14
- package/foundation/response/error-codes.mjs +13 -13
- package/foundation/response/response-types.doc.mjs +8 -69
- package/foundation/runtime/css-tree.mjs +2 -2
- package/foundation/runtime/word-table.d.mts +1 -1
- package/foundation/runtime/word-table.mjs +1 -1
- package/foundation/suggest/other-command.d.mts +52 -15
- package/foundation/suggest/other-command.mjs +168 -45
- package/foundation/text/suggest-order.d.mts +7 -0
- package/foundation/text/suggest-order.mjs +1 -1
- package/package.json +7 -8
- package/api/theme-edit/_adapter.d.mts +0 -228
- package/api/theme-edit/_adapter.mjs +0 -2025
- package/api/theme-edit/_catalog.d.mts +0 -172
- package/api/theme-edit/_catalog.mjs +0 -806
- package/api/theme-edit/_check.d.mts +0 -391
- package/api/theme-edit/_check.mjs +0 -9370
- package/api/theme-edit/_color.d.mts +0 -135
- package/api/theme-edit/_color.mjs +0 -480
- package/api/theme-edit/_compiler.d.mts +0 -77
- package/api/theme-edit/_compiler.mjs +0 -1053
- package/api/theme-edit/_context.d.mts +0 -399
- package/api/theme-edit/_context.mjs +0 -1778
- package/api/theme-edit/_css.d.mts +0 -169
- package/api/theme-edit/_css.mjs +0 -1167
- package/api/theme-edit/_edit.d.mts +0 -167
- package/api/theme-edit/_edit.mjs +0 -11220
- package/api/theme-edit/_how-commands.d.mts +0 -315
- package/api/theme-edit/_how-commands.mjs +0 -1664
- package/api/theme-edit/_how-question.d.mts +0 -341
- package/api/theme-edit/_how-question.mjs +0 -33291
- package/api/theme-edit/_how-sides.d.mts +0 -22
- package/api/theme-edit/_how-sides.mjs +0 -173
- package/api/theme-edit/_how-steps.d.mts +0 -42
- package/api/theme-edit/_how-steps.mjs +0 -208
- package/api/theme-edit/_how-values.d.mts +0 -29
- package/api/theme-edit/_how-values.mjs +0 -111
- package/api/theme-edit/_how-words.d.mts +0 -15
- package/api/theme-edit/_how-words.mjs +0 -239
- package/api/theme-edit/_how.d.mts +0 -55
- package/api/theme-edit/_how.mjs +0 -2388
- package/api/theme-edit/_importers.d.mts +0 -38
- package/api/theme-edit/_importers.mjs +0 -188
- package/api/theme-edit/_marks.d.mts +0 -39
- package/api/theme-edit/_marks.mjs +0 -67
- package/api/theme-edit/_missed.d.mts +0 -56
- package/api/theme-edit/_missed.mjs +0 -1128
- package/api/theme-edit/_name-rule.d.mts +0 -11
- package/api/theme-edit/_name-rule.mjs +0 -12
- package/api/theme-edit/_normal.d.mts +0 -365
- package/api/theme-edit/_normal.mjs +0 -1978
- package/api/theme-edit/_overview.d.mts +0 -9
- package/api/theme-edit/_overview.mjs +0 -293
- package/api/theme-edit/_palette.d.mts +0 -616
- package/api/theme-edit/_palette.mjs +0 -2776
- package/api/theme-edit/_part-pieces.d.mts +0 -54
- package/api/theme-edit/_part-pieces.mjs +0 -179
- package/api/theme-edit/_part-words.d.mts +0 -39
- package/api/theme-edit/_part-words.mjs +0 -242
- package/api/theme-edit/_parts.d.mts +0 -402
- package/api/theme-edit/_parts.mjs +0 -2294
- package/api/theme-edit/_picture-traits.d.mts +0 -259
- package/api/theme-edit/_picture-traits.mjs +0 -1030
- package/api/theme-edit/_png.d.mts +0 -94
- package/api/theme-edit/_png.mjs +0 -479
- package/api/theme-edit/_preview-app.d.mts +0 -172
- package/api/theme-edit/_preview-app.mjs +0 -6430
- package/api/theme-edit/_preview.d.mts +0 -549
- package/api/theme-edit/_preview.mjs +0 -3264
- package/api/theme-edit/_project.d.mts +0 -207
- package/api/theme-edit/_project.mjs +0 -643
- package/api/theme-edit/_resolved.d.mts +0 -46
- package/api/theme-edit/_resolved.mjs +0 -800
- package/api/theme-edit/_set-line.d.mts +0 -29
- package/api/theme-edit/_set-line.mjs +0 -100
- package/api/theme-edit/_settings.d.mts +0 -2426
- package/api/theme-edit/_settings.mjs +0 -18435
- package/api/theme-edit/_tables.d.mts +0 -227
- package/api/theme-edit/_tables.mjs +0 -1128
- package/api/theme-edit/_text-looks.d.mts +0 -78
- package/api/theme-edit/_text-looks.mjs +0 -376
- package/api/theme-edit/_vet.d.mts +0 -50
- package/api/theme-edit/_vet.mjs +0 -166
- package/api/theme-edit/how/how.d.mts +0 -17
- package/api/theme-edit/how/how.mjs +0 -28
- package/api/theme-edit/new/new.d.mts +0 -11
- package/api/theme-edit/new/new.mjs +0 -22
- package/api/theme-edit/preview-add/preview-add.d.mts +0 -14
- package/api/theme-edit/preview-add/preview-add.mjs +0 -25
- package/api/theme-edit/preview-app/preview-app.d.mts +0 -13
- package/api/theme-edit/preview-app/preview-app.mjs +0 -24
- package/api/theme-edit/preview-list/preview-list.d.mts +0 -10
- package/api/theme-edit/preview-list/preview-list.mjs +0 -21
- package/api/theme-edit/preview-remove/preview-remove.d.mts +0 -12
- package/api/theme-edit/preview-remove/preview-remove.mjs +0 -23
- package/api/theme-edit/set/set.d.mts +0 -13
- package/api/theme-edit/set/set.mjs +0 -24
- package/api/theme-edit/show/show.d.mts +0 -13
- package/api/theme-edit/show/show.mjs +0 -24
- package/api/theme-edit/theme-edit.d.mts +0 -12
- package/api/theme-edit/theme-edit.mjs +0 -36
- package/api/theme-edit/theme-edit.type.d.mts +0 -730
- package/api/theme-edit/theme-edit.type.mjs +0 -342
- package/api/theme-edit/themeEditHow.doc.d.mts +0 -6
- package/api/theme-edit/themeEditHow.doc.mjs +0 -105
- package/api/theme-edit/themeEditNew.doc.d.mts +0 -5
- package/api/theme-edit/themeEditNew.doc.mjs +0 -112
- package/api/theme-edit/themeEditPreviewAdd.doc.d.mts +0 -6
- package/api/theme-edit/themeEditPreviewAdd.doc.mjs +0 -121
- package/api/theme-edit/themeEditPreviewApp.doc.d.mts +0 -6
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +0 -87
- package/api/theme-edit/themeEditPreviewList.doc.d.mts +0 -6
- package/api/theme-edit/themeEditPreviewList.doc.mjs +0 -62
- package/api/theme-edit/themeEditPreviewRemove.doc.d.mts +0 -6
- package/api/theme-edit/themeEditPreviewRemove.doc.mjs +0 -96
- package/api/theme-edit/themeEditSet.doc.d.mts +0 -6
- package/api/theme-edit/themeEditSet.doc.mjs +0 -175
- package/api/theme-edit/themeEditShow.doc.d.mts +0 -6
- package/api/theme-edit/themeEditShow.doc.mjs +0 -118
- package/api/theme-edit/themeEditUndo.doc.d.mts +0 -6
- package/api/theme-edit/themeEditUndo.doc.mjs +0 -133
- package/api/theme-edit/undo/undo.d.mts +0 -13
- package/api/theme-edit/undo/undo.mjs +0 -24
- package/assets/preview-app/README.md +0 -6
- package/assets/preview-app/css.d.ts +0 -5
- package/assets/preview-app/gitignore +0 -4
- package/assets/preview-app/next.config.mjs +0 -12
- package/assets/preview-app/package.json +0 -24
- package/assets/preview-app/src/app/globals.css +0 -6
- package/assets/preview-app/src/app/layout.tsx +0 -21
- package/assets/preview-app/src/app/page.tsx +0 -94
- package/assets/preview-app/src/app/providers.tsx +0 -16
- package/assets/preview-app/tsconfig.json +0 -27
- package/clients/cli/commands/experimental/theme.mjs +0 -2990
- package/clients/cli/commands/experimental-theme-add.doc.mjs +0 -80
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +0 -98
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +0 -196
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +0 -174
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +0 -139
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +0 -77
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +0 -105
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +0 -49
- package/clients/cli/commands/experimental-theme-eject.doc.mjs +0 -72
- package/clients/cli/commands/experimental-theme-list.doc.mjs +0 -49
- package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +0 -88
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +0 -61
- package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +0 -48
- package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +0 -59
- package/clients/cli/commands/experimental-theme-preview.doc.mjs +0 -41
- package/clients/cli/commands/experimental-theme-remove.doc.mjs +0 -57
- package/clients/cli/commands/experimental-theme-targets.doc.mjs +0 -62
- package/clients/cli/commands/experimental-theme-template.doc.mjs +0 -63
- package/clients/cli/commands/experimental-theme-use.doc.mjs +0 -57
- package/clients/cli/commands/experimental-theme.doc.mjs +0 -60
- package/foundation/fonts/fontsource-families.generated.d.mts +0 -5
- package/foundation/fonts/fontsource-families.generated.mjs +0 -2110
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
useRef,
|
|
7
|
+
useState,
|
|
8
|
+
type KeyboardEvent,
|
|
9
|
+
type MouseEvent,
|
|
10
|
+
type TouchEvent,
|
|
11
|
+
} from 'react';
|
|
12
|
+
import * as stylex from '@stylexjs/stylex';
|
|
13
|
+
import {Badge} from '@astryxdesign/core/Badge';
|
|
14
|
+
import {Button} from '@astryxdesign/core/Button';
|
|
15
|
+
import {Card} from '@astryxdesign/core/Card';
|
|
16
|
+
import {DropdownMenu} from '@astryxdesign/core/DropdownMenu';
|
|
17
|
+
import {useLongPress} from '@astryxdesign/core/hooks';
|
|
18
|
+
import {HStack, VStack} from '@astryxdesign/core/Layout';
|
|
19
|
+
import {Heading, Text} from '@astryxdesign/core/Text';
|
|
20
|
+
|
|
21
|
+
type TriggerSource = 'long press' | 'right-click';
|
|
22
|
+
|
|
23
|
+
interface MenuPosition {
|
|
24
|
+
x: number;
|
|
25
|
+
y: number;
|
|
26
|
+
// The surface's height when the panel opened, so CSS can keep the panel in it.
|
|
27
|
+
surfaceHeight: number;
|
|
28
|
+
source: TriggerSource;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const MENU_WIDTH = 180;
|
|
32
|
+
// Room for the panel's note and its three actions in every theme (the tallest
|
|
33
|
+
// theme's panel is about 202px), so the panel stays inside the surface.
|
|
34
|
+
const SURFACE_MIN_HEIGHT = 216;
|
|
35
|
+
|
|
36
|
+
const styles = stylex.create({
|
|
37
|
+
surface: {
|
|
38
|
+
position: 'relative',
|
|
39
|
+
width: '100%',
|
|
40
|
+
maxWidth: 360,
|
|
41
|
+
minHeight: SURFACE_MIN_HEIGHT,
|
|
42
|
+
// Safari, the browser that starts a text selection on a long press, reads
|
|
43
|
+
// only the prefixed property; Chrome and Firefox read it too.
|
|
44
|
+
WebkitUserSelect: 'none',
|
|
45
|
+
},
|
|
46
|
+
// The card fills the surface, so the area that listens for the press is
|
|
47
|
+
// the area a person sees.
|
|
48
|
+
card: {flexGrow: 1},
|
|
49
|
+
panel: (x: number, y: number, surfaceHeight: number) => ({
|
|
50
|
+
position: 'absolute',
|
|
51
|
+
// The point sets the panel's top-left corner. The clamp keeps the panel's
|
|
52
|
+
// width inside the surface. A translate percentage is of the panel's own
|
|
53
|
+
// height, so near the bottom the panel moves up just enough to fit, and
|
|
54
|
+
// never above the surface's top.
|
|
55
|
+
left: `clamp(0px, ${x}px, calc(100% - ${MENU_WIDTH}px))`,
|
|
56
|
+
top: `${y}px`,
|
|
57
|
+
transform: `translateY(min(0px, max(-${y}px, calc(${surfaceHeight - y}px - 100%))))`,
|
|
58
|
+
zIndex: 1,
|
|
59
|
+
}),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
export default function UseLongPressHookUsage() {
|
|
63
|
+
const surfaceRef = useRef<HTMLElement>(null);
|
|
64
|
+
const actionsButtonRef = useRef<HTMLButtonElement>(null);
|
|
65
|
+
const hasLongPressFiredRef = useRef(false);
|
|
66
|
+
const [menu, setMenu] = useState<MenuPosition | null>(null);
|
|
67
|
+
const [isActionsOpen, setIsActionsOpen] = useState(false);
|
|
68
|
+
const [isPinned, setIsPinned] = useState(false);
|
|
69
|
+
const [lastAction, setLastAction] = useState(
|
|
70
|
+
'Hold on touch, right-click, or use Actions.',
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const openMenuAt = (point: {x: number; y: number}, source: TriggerSource) => {
|
|
74
|
+
const surface = surfaceRef.current;
|
|
75
|
+
if (!surface) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
// One action list at a time: the panel replaces an open Actions menu.
|
|
79
|
+
setIsActionsOpen(false);
|
|
80
|
+
const rect = surface.getBoundingClientRect();
|
|
81
|
+
const x = Math.max(0, Math.round(point.x - rect.left));
|
|
82
|
+
const y = Math.max(0, Math.round(point.y - rect.top));
|
|
83
|
+
setMenu({
|
|
84
|
+
x,
|
|
85
|
+
y,
|
|
86
|
+
surfaceHeight: Math.round(rect.height),
|
|
87
|
+
source,
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// Only the four touch handlers belong on the DOM element; start, moveTo, and
|
|
92
|
+
// cancel are the imperative API for custom pointer state machines.
|
|
93
|
+
const {onTouchStart, onTouchMove, onTouchEnd, onTouchCancel} = useLongPress({
|
|
94
|
+
onLongPress: point => {
|
|
95
|
+
hasLongPressFiredRef.current = true;
|
|
96
|
+
openMenuAt(point, 'long press');
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const handleTouchStart = (e: TouchEvent<HTMLElement>) => {
|
|
101
|
+
hasLongPressFiredRef.current = false;
|
|
102
|
+
onTouchStart(e);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// The finger that opened the panel lifts over it. Canceling that lift stops
|
|
106
|
+
// the browser's click, so the release does not run the action under it. The
|
|
107
|
+
// hook runs first: on a busy page it can report the long press in this lift.
|
|
108
|
+
const handleTouchEnd = (e: TouchEvent<HTMLElement>) => {
|
|
109
|
+
onTouchEnd(e);
|
|
110
|
+
if (hasLongPressFiredRef.current) {
|
|
111
|
+
e.preventDefault();
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const closeMenu = () => {
|
|
116
|
+
setMenu(null);
|
|
117
|
+
actionsButtonRef.current?.focus();
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const handleContextMenu = (e: MouseEvent<HTMLElement>) => {
|
|
121
|
+
e.preventDefault();
|
|
122
|
+
// Chromium emits a synthetic contextmenu event with pointerType 'touch'
|
|
123
|
+
// after a long press; keep the original 'long press' trigger source.
|
|
124
|
+
if ((e.nativeEvent as PointerEvent).pointerType === 'touch') {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
openMenuAt({x: e.clientX, y: e.clientY}, 'right-click');
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const handleKeyDown = (e: KeyboardEvent<HTMLElement>) => {
|
|
131
|
+
if (e.key === 'Escape' && menu) {
|
|
132
|
+
closeMenu();
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const runAction = (action: 'copy' | 'pin', via: string) => {
|
|
137
|
+
if (action === 'pin') {
|
|
138
|
+
const nextPinned = !isPinned;
|
|
139
|
+
setIsPinned(nextPinned);
|
|
140
|
+
setLastAction(`${nextPinned ? 'Pinned' : 'Unpinned'} via ${via}.`);
|
|
141
|
+
} else {
|
|
142
|
+
setLastAction(`Copied link via ${via}.`);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const runPanelAction = (action: 'copy' | 'pin') => {
|
|
147
|
+
if (menu) {
|
|
148
|
+
runAction(action, `${menu.source} (${menu.x}, ${menu.y})`);
|
|
149
|
+
closeMenu();
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
return (
|
|
154
|
+
<VStack gap={3}>
|
|
155
|
+
<VStack
|
|
156
|
+
ref={surfaceRef}
|
|
157
|
+
data-testid="long-press-surface"
|
|
158
|
+
xstyle={styles.surface}
|
|
159
|
+
onTouchStart={handleTouchStart}
|
|
160
|
+
onTouchMove={onTouchMove}
|
|
161
|
+
onTouchEnd={handleTouchEnd}
|
|
162
|
+
onTouchCancel={onTouchCancel}
|
|
163
|
+
onContextMenu={handleContextMenu}
|
|
164
|
+
onKeyDown={handleKeyDown}>
|
|
165
|
+
<Card padding={4} xstyle={styles.card}>
|
|
166
|
+
<VStack gap={2}>
|
|
167
|
+
<HStack gap={2} justify="between" vAlign="center" wrap="wrap">
|
|
168
|
+
<HStack gap={2} vAlign="center" wrap="wrap">
|
|
169
|
+
<Heading level={3}>Q3 launch brief.pdf</Heading>
|
|
170
|
+
{isPinned && <Badge variant="success" label="Pinned" />}
|
|
171
|
+
</HStack>
|
|
172
|
+
{/* Every action without a hold. Core places the menu below the
|
|
173
|
+
button when there is room, above it when only that fits. */}
|
|
174
|
+
<DropdownMenu
|
|
175
|
+
isMenuOpen={isActionsOpen}
|
|
176
|
+
onOpenChange={isOpen => {
|
|
177
|
+
setIsActionsOpen(isOpen);
|
|
178
|
+
if (isOpen) {
|
|
179
|
+
setMenu(null);
|
|
180
|
+
}
|
|
181
|
+
}}
|
|
182
|
+
button={{
|
|
183
|
+
ref: actionsButtonRef,
|
|
184
|
+
label: 'Actions',
|
|
185
|
+
variant: 'secondary',
|
|
186
|
+
}}
|
|
187
|
+
items={[
|
|
188
|
+
{
|
|
189
|
+
label: 'Copy link',
|
|
190
|
+
onClick: () => runAction('copy', 'the Actions menu'),
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
label: isPinned ? 'Unpin' : 'Pin draft',
|
|
194
|
+
onClick: () => runAction('pin', 'the Actions menu'),
|
|
195
|
+
},
|
|
196
|
+
]}
|
|
197
|
+
/>
|
|
198
|
+
</HStack>
|
|
199
|
+
<Text type="body" color="secondary">
|
|
200
|
+
Touch press-and-hold or right-click anywhere else on this card to
|
|
201
|
+
open actions under your finger or cursor.
|
|
202
|
+
</Text>
|
|
203
|
+
</VStack>
|
|
204
|
+
</Card>
|
|
205
|
+
|
|
206
|
+
{menu && (
|
|
207
|
+
<Card
|
|
208
|
+
role="group"
|
|
209
|
+
aria-label="Document actions"
|
|
210
|
+
padding={2}
|
|
211
|
+
width={MENU_WIDTH}
|
|
212
|
+
xstyle={styles.panel(menu.x, menu.y, menu.surfaceHeight)}>
|
|
213
|
+
<VStack gap={1}>
|
|
214
|
+
<Text type="supporting" color="secondary">
|
|
215
|
+
Opened by {menu.source} at ({menu.x}, {menu.y})
|
|
216
|
+
</Text>
|
|
217
|
+
<Button
|
|
218
|
+
label="Copy link"
|
|
219
|
+
variant="ghost"
|
|
220
|
+
onClick={() => runPanelAction('copy')}
|
|
221
|
+
/>
|
|
222
|
+
<Button
|
|
223
|
+
label={isPinned ? 'Unpin' : 'Pin draft'}
|
|
224
|
+
variant="ghost"
|
|
225
|
+
onClick={() => runPanelAction('pin')}
|
|
226
|
+
/>
|
|
227
|
+
<Button label="Dismiss" variant="ghost" onClick={closeMenu} />
|
|
228
|
+
</VStack>
|
|
229
|
+
</Card>
|
|
230
|
+
)}
|
|
231
|
+
</VStack>
|
|
232
|
+
<Text type="supporting" color="secondary">
|
|
233
|
+
{lastAction}
|
|
234
|
+
</Text>
|
|
235
|
+
</VStack>
|
|
236
|
+
);
|
|
237
|
+
}
|
|
@@ -2,8 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
'use client';
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
|
|
5
|
+
import {
|
|
6
|
+
ChartIcon,
|
|
7
|
+
DocumentIcon,
|
|
8
|
+
FolderIcon,
|
|
9
|
+
HelpIcon,
|
|
10
|
+
HomeIcon,
|
|
11
|
+
SettingsIcon,
|
|
12
|
+
} from '@astryxdesign/template-icons';
|
|
7
13
|
import {
|
|
8
14
|
SideNav,
|
|
9
15
|
SideNavHeading,
|
|
@@ -11,74 +17,6 @@ import {
|
|
|
11
17
|
SideNavSection,
|
|
12
18
|
} from '@astryxdesign/core/SideNav';
|
|
13
19
|
|
|
14
|
-
function HomeIcon(props: ComponentProps<'svg'>) {
|
|
15
|
-
return (
|
|
16
|
-
<svg
|
|
17
|
-
fill="none"
|
|
18
|
-
viewBox="0 0 24 24"
|
|
19
|
-
strokeWidth={1.5}
|
|
20
|
-
stroke="currentColor"
|
|
21
|
-
{...props}>
|
|
22
|
-
<path
|
|
23
|
-
strokeLinecap="round"
|
|
24
|
-
strokeLinejoin="round"
|
|
25
|
-
d="m2.25 12 8.954-8.955c.44-.439 1.152-.439 1.591 0L21.75 12M4.5 9.75v10.125c0 .621.504 1.125 1.125 1.125H9.75v-4.875c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125V21h4.125c.621 0 1.125-.504 1.125-1.125V9.75M8.25 21h8.25"
|
|
26
|
-
/>
|
|
27
|
-
</svg>
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function FolderIcon(props: ComponentProps<'svg'>) {
|
|
32
|
-
return (
|
|
33
|
-
<svg
|
|
34
|
-
fill="none"
|
|
35
|
-
viewBox="0 0 24 24"
|
|
36
|
-
strokeWidth={1.5}
|
|
37
|
-
stroke="currentColor"
|
|
38
|
-
{...props}>
|
|
39
|
-
<path
|
|
40
|
-
strokeLinecap="round"
|
|
41
|
-
strokeLinejoin="round"
|
|
42
|
-
d="M2.25 12.75V12A2.25 2.25 0 0 1 4.5 9.75h15A2.25 2.25 0 0 1 21.75 12v.75m-8.69-6.44-2.12-2.12a1.5 1.5 0 0 0-1.061-.44H4.5A2.25 2.25 0 0 0 2.25 6v12a2.25 2.25 0 0 0 2.25 2.25h15A2.25 2.25 0 0 0 21.75 18V9a2.25 2.25 0 0 0-2.25-2.25h-5.379a1.5 1.5 0 0 1-1.06-.44Z"
|
|
43
|
-
/>
|
|
44
|
-
</svg>
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function ChartBarIcon(props: ComponentProps<'svg'>) {
|
|
49
|
-
return (
|
|
50
|
-
<svg
|
|
51
|
-
fill="none"
|
|
52
|
-
viewBox="0 0 24 24"
|
|
53
|
-
strokeWidth={1.5}
|
|
54
|
-
stroke="currentColor"
|
|
55
|
-
{...props}>
|
|
56
|
-
<path
|
|
57
|
-
strokeLinecap="round"
|
|
58
|
-
strokeLinejoin="round"
|
|
59
|
-
d="M3 13.125C3 12.504 3.504 12 4.125 12h2.25c.621 0 1.125.504 1.125 1.125v6.75C7.5 20.496 6.996 21 6.375 21h-2.25A1.125 1.125 0 0 1 3 19.875v-6.75ZM9.75 8.625c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125v11.25c0 .621-.504 1.125-1.125 1.125h-2.25a1.125 1.125 0 0 1-1.125-1.125V8.625ZM16.5 4.125c0-.621.504-1.125 1.125-1.125h2.25C20.496 3 21 3.504 21 4.125v15.75c0 .621-.504 1.125-1.125 1.125h-2.25a1.125 1.125 0 0 1-1.125-1.125V4.125Z"
|
|
60
|
-
/>
|
|
61
|
-
</svg>
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function DocumentTextIcon(props: ComponentProps<'svg'>) {
|
|
66
|
-
return (
|
|
67
|
-
<svg
|
|
68
|
-
fill="none"
|
|
69
|
-
viewBox="0 0 24 24"
|
|
70
|
-
strokeWidth={1.5}
|
|
71
|
-
stroke="currentColor"
|
|
72
|
-
{...props}>
|
|
73
|
-
<path
|
|
74
|
-
strokeLinecap="round"
|
|
75
|
-
strokeLinejoin="round"
|
|
76
|
-
d="M19.5 14.25v-2.625a3.375 3.375 0 0 0-3.375-3.375h-1.5A1.125 1.125 0 0 1 13.5 7.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 0 0-9-9Z"
|
|
77
|
-
/>
|
|
78
|
-
</svg>
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
20
|
export default function SideNavShowcase() {
|
|
83
21
|
return (
|
|
84
22
|
<SideNav
|
|
@@ -97,12 +35,12 @@ export default function SideNavShowcase() {
|
|
|
97
35
|
href="/dashboard"
|
|
98
36
|
/>
|
|
99
37
|
<SideNavItem label="Projects" icon={FolderIcon} href="/projects" />
|
|
100
|
-
<SideNavItem label="Analytics" icon={
|
|
38
|
+
<SideNavItem label="Analytics" icon={ChartIcon} href="/analytics" />
|
|
101
39
|
</SideNavSection>
|
|
102
40
|
<SideNavSection title="Documents">
|
|
103
41
|
<SideNavItem
|
|
104
42
|
label="All Documents"
|
|
105
|
-
icon={
|
|
43
|
+
icon={DocumentIcon}
|
|
106
44
|
href="/documents"
|
|
107
45
|
/>
|
|
108
46
|
</SideNavSection>
|
|
@@ -10,5 +10,5 @@ export const doc = {
|
|
|
10
10
|
'Side navigation with an account switcher dropdown in the header for multi-account apps.',
|
|
11
11
|
isReady: true,
|
|
12
12
|
aspectRatio: 4 / 3,
|
|
13
|
-
componentsUsed: ['SideNav', '
|
|
13
|
+
componentsUsed: ['SideNav', 'NavHeadingMenu', 'NavHeadingMenuItem', 'NavIcon'],
|
|
14
14
|
};
|
|
@@ -9,8 +9,8 @@ import {
|
|
|
9
9
|
SideNavItem,
|
|
10
10
|
SideNavSection,
|
|
11
11
|
} from '@astryxdesign/core/SideNav';
|
|
12
|
-
import {ListItem} from '@astryxdesign/core/List';
|
|
13
12
|
import {NavIcon} from '@astryxdesign/core/NavIcon';
|
|
13
|
+
import {NavHeadingMenu, NavHeadingMenuItem} from '@astryxdesign/core/NavMenu';
|
|
14
14
|
|
|
15
15
|
function HomeIcon(props: ComponentProps<'svg'>) {
|
|
16
16
|
return (
|
|
@@ -77,12 +77,12 @@ export default function SideNavWithHeaderMenu() {
|
|
|
77
77
|
heading="Product Name"
|
|
78
78
|
subheading="Business Account"
|
|
79
79
|
menu={
|
|
80
|
-
|
|
81
|
-
<
|
|
82
|
-
<
|
|
83
|
-
<
|
|
84
|
-
<
|
|
85
|
-
|
|
80
|
+
<NavHeadingMenu>
|
|
81
|
+
<NavHeadingMenuItem label="Personal Account" href="#" />
|
|
82
|
+
<NavHeadingMenuItem label="Acme Corp" href="#" />
|
|
83
|
+
<NavHeadingMenuItem label="Add account" href="#" />
|
|
84
|
+
<NavHeadingMenuItem label="Sign out" href="#" />
|
|
85
|
+
</NavHeadingMenu>
|
|
86
86
|
}
|
|
87
87
|
/>
|
|
88
88
|
}>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
|
|
4
|
+
export const doc = {
|
|
5
|
+
type: 'block',
|
|
6
|
+
exampleFor: 'Table',
|
|
7
|
+
name: 'Table — Custom Row',
|
|
8
|
+
displayName: 'Table — Custom Row',
|
|
9
|
+
description:
|
|
10
|
+
"An orders table where a small plugin renders each cancelled order as one full-width row with a message. transformBodyRow replaces the row's cells with one TableCell that spans every column, before the cells mount, so the column renderers do not run for that row.",
|
|
11
|
+
isReady: true,
|
|
12
|
+
aspectRatio: 16 / 9,
|
|
13
|
+
componentsUsed: ['Table', 'TableCell', 'Text'],
|
|
14
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
import {useMemo} from 'react';
|
|
6
|
+
import {
|
|
7
|
+
Table,
|
|
8
|
+
TableCell,
|
|
9
|
+
type TableColumn,
|
|
10
|
+
type TablePlugin,
|
|
11
|
+
} from '@astryxdesign/core/Table';
|
|
12
|
+
import {Text} from '@astryxdesign/core/Text';
|
|
13
|
+
|
|
14
|
+
interface Order extends Record<string, unknown> {
|
|
15
|
+
id: string;
|
|
16
|
+
customer: string;
|
|
17
|
+
status: 'Processing' | 'Shipped' | 'Delivered' | 'Cancelled';
|
|
18
|
+
total: number;
|
|
19
|
+
cancelledOn?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const orders: Order[] = [
|
|
23
|
+
{id: '1042', customer: 'Ana Costa', status: 'Shipped', total: 120},
|
|
24
|
+
{
|
|
25
|
+
id: '1043',
|
|
26
|
+
customer: 'Bruno Silva',
|
|
27
|
+
status: 'Cancelled',
|
|
28
|
+
total: 64.5,
|
|
29
|
+
cancelledOn: '12 March',
|
|
30
|
+
},
|
|
31
|
+
{id: '1044', customer: 'Chen Wei', status: 'Processing', total: 310.25},
|
|
32
|
+
{id: '1045', customer: 'Dana Levi', status: 'Delivered', total: 42},
|
|
33
|
+
{id: '1046', customer: 'Emeka Obi', status: 'Shipped', total: 89.99},
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
const price = new Intl.NumberFormat('en-GB', {
|
|
37
|
+
style: 'currency',
|
|
38
|
+
currency: 'GBP',
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const columns: TableColumn<Order>[] = [
|
|
42
|
+
{key: 'id', header: 'Order', renderCell: order => `#${order.id}`},
|
|
43
|
+
{key: 'customer', header: 'Customer'},
|
|
44
|
+
{key: 'status', header: 'Status'},
|
|
45
|
+
{
|
|
46
|
+
key: 'total',
|
|
47
|
+
header: 'Total',
|
|
48
|
+
align: 'end',
|
|
49
|
+
renderCell: order => price.format(order.total),
|
|
50
|
+
},
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Renders a cancelled order as one full-width row. The row transform replaces
|
|
55
|
+
* the row's cells before they mount, so the column renderers do not run for
|
|
56
|
+
* that row. Every other row passes through unchanged. `columnCount` is the
|
|
57
|
+
* number of columns the table renders: count the columns other plugins add,
|
|
58
|
+
* such as a selection or row index column.
|
|
59
|
+
*/
|
|
60
|
+
function useCancelledOrderRows(columnCount: number): TablePlugin<Order> {
|
|
61
|
+
return useMemo(
|
|
62
|
+
(): TablePlugin<Order> => ({
|
|
63
|
+
rowModel: 'flat',
|
|
64
|
+
transformBodyRow: (props, order) => {
|
|
65
|
+
if (order.status !== 'Cancelled') {
|
|
66
|
+
return props;
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
...props,
|
|
70
|
+
children: (
|
|
71
|
+
<TableCell colSpan={columnCount}>
|
|
72
|
+
<Text type="supporting" color="secondary">
|
|
73
|
+
Order #{order.id} was cancelled on {order.cancelledOn}. Refund
|
|
74
|
+
sent to {order.customer}.
|
|
75
|
+
</Text>
|
|
76
|
+
</TableCell>
|
|
77
|
+
),
|
|
78
|
+
};
|
|
79
|
+
},
|
|
80
|
+
}),
|
|
81
|
+
[columnCount],
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export default function TableCustomRowTable() {
|
|
86
|
+
const cancelledOrderRows = useCancelledOrderRows(columns.length);
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<Table
|
|
90
|
+
data={orders}
|
|
91
|
+
columns={columns}
|
|
92
|
+
idKey="id"
|
|
93
|
+
plugins={{cancelledOrderRows}}
|
|
94
|
+
/>
|
|
95
|
+
);
|
|
96
|
+
}
|