mirror of
https://github.com/navikt/aksel.git
synced 2026-11-25 06:04:05 +00:00
Compare commits
45
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
010a2028f8 | ||
|
|
4700da665c | ||
|
|
0de6bc83bc | ||
|
|
8c73a23939 | ||
|
|
6d608cda93 | ||
|
|
a37da7bd3e | ||
|
|
342fea97e2 | ||
|
|
0f06198db9 | ||
|
|
87736bdd28 | ||
|
|
6ebcf8b0f2 | ||
|
|
c5de39d98a | ||
|
|
b7711b59f9 | ||
|
|
e45962b013 | ||
|
|
23bc2d9b01 | ||
|
|
03e93cace9 | ||
|
|
6fa7df05c7 | ||
|
|
6ed064ab1a | ||
|
|
5a5a015a10 | ||
|
|
b9b6d3f45b | ||
|
|
f2e86b1c27 | ||
|
|
01f7475dfe | ||
|
|
ed68f0d4cc | ||
|
|
7350014c84 | ||
|
|
e18c7b2808 | ||
|
|
733eda03b7 | ||
|
|
9b2ccba85e | ||
|
|
ac023b4aa9 | ||
|
|
48b1289866 | ||
|
|
88dc6c7d09 | ||
|
|
e90410673b | ||
|
|
ceba3aa4de | ||
|
|
45519d52fc | ||
|
|
05a6734eaa | ||
|
|
2edeaf4446 | ||
|
|
820af7c17c | ||
|
|
137d3c2d51 | ||
|
|
b4f4bb5c11 | ||
|
|
a1317dc3df | ||
|
|
5e90726eb7 | ||
|
|
9bef84205e | ||
|
|
7a49867e77 | ||
|
|
0ee13d82d7 | ||
|
|
18a1eda79c | ||
|
|
12ff585b3e | ||
|
|
3390f0f230 |
No files matched your search
@@ -1,5 +0,0 @@
|
||||
---
|
||||
"@navikt/aksel-icons": minor
|
||||
---
|
||||
|
||||
Icons: All icons are now available as CSS custom properties. Import `@navikt/aksel-icons/css/<IconName>.css` for a single icon (e.g. `--aksel-icon-magnifying-glass`), or `@navikt/aksel-icons/css/index.css` for every icon.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@navikt/ds-react": patch
|
||||
---
|
||||
|
||||
Button: Preserve keyboard modifiers during native Space activation.
|
||||
@@ -1,5 +0,0 @@
|
||||
---
|
||||
"@navikt/ds-react": patch
|
||||
---
|
||||
|
||||
Accordion, Dropdown, ExpansionCard, Fieldset, CheckboxGroup, RadioGroup, List, Search, Table, Timeline: Memoize internal context values to avoid unnecessary re-renders of child components.
|
||||
@@ -68,7 +68,7 @@ jobs:
|
||||
with:
|
||||
issue-number: ${{ github.event.pull_request.number }}
|
||||
comment-author: "github-actions[bot]"
|
||||
body-includes: Storybook demo
|
||||
body-includes: Chromatic
|
||||
|
||||
- name: Create or update comment
|
||||
if: github.event_name != 'push' && !contains(github.event.head_commit.message, '[ci skip]') && github.actor != 'dependabot[bot]'
|
||||
@@ -77,11 +77,11 @@ jobs:
|
||||
comment-id: ${{ steps.fc.outputs.comment-id }}
|
||||
issue-number: ${{ github.event.pull_request.number }}
|
||||
body: |
|
||||
## [Storybook demo](${{steps.chromatic_tests.outputs.storybookUrl}}) / [Chromatic](${{steps.chromatic_tests.outputs.url}})
|
||||
|
||||
${{ steps.chromatic_tests.outputs.url != 'undefined' && format('## [Storybook demo]({0}) / [Chromatic]({1})', steps.chromatic_tests.outputs.storybookUrl, steps.chromatic_tests.outputs.url) || '## Chromatic skipped' }}
|
||||
|
||||
${{ steps.chromatic_tests.outputs.changeCount > 0 && format('### 📝 Changes to review: {0}', steps.chromatic_tests.outputs.changeCount) || '' }}
|
||||
${{ steps.chromatic_tests.outputs.errorCount > 0 && format('### ❌ Stories with errors: {0}', steps.chromatic_tests.outputs.errorCount) || '' }}
|
||||
${{ steps.chromatic_tests.outputs.interactionTestFailuresCount > 0 && format('### ❌ Failed interaction tests: {0}', steps.chromatic_tests.outputs.interactionTestFailuresCount) || '' }}
|
||||
|
||||
[${{ steps.vars.outputs.sha_short }}](https://github.com/navikt/aksel/commit/${{ steps.vars.outputs.sha_short }}) | ${{steps.chromatic_tests.outputs.componentCount}} components | ${{steps.chromatic_tests.outputs.specCount}} stories
|
||||
[${{steps.vars.outputs.sha_short}}](https://github.com/navikt/aksel/commit/${{steps.vars.outputs.sha_short}}) | ${{steps.chromatic_tests.outputs.componentCount}} components | ${{steps.chromatic_tests.outputs.specCount}} stories | ${{steps.chromatic_tests.outputs.actualCaptureCount}} captured snapshots | ${{steps.chromatic_tests.outputs.inheritedCaptureCount}} inherited snapshots
|
||||
edit-mode: replace
|
||||
@@ -10,8 +10,8 @@ import "../@navikt/core/css/src/data-token-filter.css";
|
||||
import dataTokenFilterStyles from "../@navikt/core/css/src/data-token-filter.css?inline";
|
||||
import "../@navikt/core/css/src/data-toolbar.css";
|
||||
import dataToolbarStyles from "../@navikt/core/css/src/data-toolbar.css?inline";
|
||||
import "../@navikt/core/css/src/form/combobox2.css";
|
||||
import combobox2Styles from "../@navikt/core/css/src/form/combobox2.css?inline";
|
||||
import "../@navikt/core/css/src/form/combo-box.css";
|
||||
import combobox2Styles from "../@navikt/core/css/src/form/combo-box.css?inline";
|
||||
import "../@navikt/core/css/src/index.css";
|
||||
import dsStyles from "../@navikt/core/css/src/index.css?inline";
|
||||
import "../@navikt/core/css/src/listbox.css";
|
||||
|
||||
Vendored
-1
@@ -8,7 +8,6 @@
|
||||
"**/cjs": true
|
||||
},
|
||||
"playwright.reuseBrowser": true,
|
||||
"oxc.fixKind": "all",
|
||||
"js/ts.tsdk.path": "node_modules/typescript/lib",
|
||||
"deno.enablePaths": ["./scripts/deno"]
|
||||
}
|
||||
@@ -1,5 +1,11 @@
|
||||
# @navikt/aksel-icons
|
||||
|
||||
## 8.23.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- Icons: All icons are now available as CSS custom properties. Import `@navikt/aksel-icons/css/<IconName>.css` for a single icon (e.g. `--aksel-icon-magnifying-glass`), or `@navikt/aksel-icons/css/index.css` for every icon. ([#5489](https://github.com/navikt/aksel/pull/5489))
|
||||
|
||||
## 8.22.1
|
||||
|
||||
## 8.22.0
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// oxlint-disable typescript/no-require-imports
|
||||
const fastglob = require("fast-glob");
|
||||
const kebabCase = require("lodash/kebabCase");
|
||||
const path = require("node:path");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@navikt/aksel-icons",
|
||||
"version": "8.22.1",
|
||||
"version": "8.23.0",
|
||||
"author": "Aksel | Nav",
|
||||
"homepage": "https://aksel.nav.no/ikoner",
|
||||
"repository": {
|
||||
@@ -88,14 +88,14 @@
|
||||
"hast-util-select": "6.0.4",
|
||||
"js-yaml": "^5.5.0",
|
||||
"lodash": "4.18.1",
|
||||
"prettier": "3.9.6",
|
||||
"prettier": "3.9.10",
|
||||
"react": "19.3.1",
|
||||
"rehype-parse": "9.0.1",
|
||||
"svgo": "3.3.5",
|
||||
"tsc-alias": "1.9.7",
|
||||
"tsc-alias": "1.9.10",
|
||||
"tsx": "^4.23.15",
|
||||
"typescript": "6.0.3",
|
||||
"unified": "11.0.5",
|
||||
"vitest": "5.0.5"
|
||||
"vitest": "5.1.0"
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,11 @@
|
||||
# @navikt/aksel-stylelint
|
||||
|
||||
## 8.23.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Stylelint: `@navikt/aksel-stylelint/recommended` now references its plugin by explicit file path, fixing `Could not find "."` errors with Stylelint 18. ([#5527](https://github.com/navikt/aksel/pull/5527))
|
||||
|
||||
## 8.22.1
|
||||
|
||||
## 8.22.0
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@navikt/aksel-stylelint",
|
||||
"version": "8.22.1",
|
||||
"version": "8.23.0",
|
||||
"type": "module",
|
||||
"engines": {
|
||||
"node": ">=18.12.0"
|
||||
@@ -43,8 +43,8 @@
|
||||
"dev": "yarn watch:lint"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@navikt/ds-css": "^8.22.1",
|
||||
"@navikt/ds-tokens": "^8.22.1",
|
||||
"@navikt/ds-css": "^8.23.0",
|
||||
"@navikt/ds-tokens": "^8.23.0",
|
||||
"concurrently": "10.0.6",
|
||||
"postcss-selector-parser": "^7.1.7",
|
||||
"postcss-value-parser": "^4.2.0",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export default {
|
||||
plugins: ["."],
|
||||
plugins: ["./index.js"],
|
||||
rules: {
|
||||
"aksel/design-token-exists": true,
|
||||
"aksel/no-internal-tokens": true,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# @navikt/aksel
|
||||
|
||||
## 8.23.0
|
||||
|
||||
## 8.22.1
|
||||
|
||||
## 8.22.0
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@navikt/aksel",
|
||||
"version": "8.22.1",
|
||||
"version": "8.23.0",
|
||||
"description": "Aksel command line interface. Codemods and other utilities for Aksel users.",
|
||||
"author": "Aksel | Nav designsystem team",
|
||||
"license": "MIT",
|
||||
@@ -58,7 +58,7 @@
|
||||
"@types/lodash": "4.17.25",
|
||||
"rimraf": "6.1.3",
|
||||
"typescript": "6.0.3",
|
||||
"vitest": "5.0.5"
|
||||
"vitest": "5.1.0"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"engines": {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# @navikt/ds-css
|
||||
|
||||
## 8.23.0
|
||||
|
||||
## 8.22.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@navikt/ds-css",
|
||||
"version": "8.22.1",
|
||||
"version": "8.23.0",
|
||||
"description": "CSS for Nav Designsystem",
|
||||
"author": "Aksel | Nav designsystem team",
|
||||
"keywords": [
|
||||
@@ -32,7 +32,7 @@
|
||||
"css:get-version": "node config/get-version.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@navikt/ds-tokens": "^8.22.1",
|
||||
"@navikt/ds-tokens": "^8.23.0",
|
||||
"browserslist": "^4.28.7",
|
||||
"esbuild": "^0.28.2",
|
||||
"fast-glob": "3.3.3",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
.aksel-combobox2[data-disabled="true"] {
|
||||
.aksel-combo-box[data-disabled="true"] {
|
||||
opacity: var(--ax-opacity-disabled);
|
||||
pointer-events: none;
|
||||
}
|
||||
@@ -7,16 +7,16 @@
|
||||
* Label & description & error *
|
||||
************************************************/
|
||||
|
||||
.aksel-combobox2__label {
|
||||
.aksel-combo-box__label {
|
||||
display: flex;
|
||||
margin-bottom: var(--ax-space-8);
|
||||
}
|
||||
|
||||
.aksel-combobox2__description {
|
||||
.aksel-combo-box__description {
|
||||
margin-bottom: var(--ax-space-8);
|
||||
}
|
||||
|
||||
.aksel-combobox2__error {
|
||||
.aksel-combo-box__error {
|
||||
margin-top: var(--ax-space-8);
|
||||
}
|
||||
|
||||
@@ -24,11 +24,11 @@
|
||||
* Field *
|
||||
************************************************/
|
||||
|
||||
.aksel-combobox2__field-container {
|
||||
.aksel-combo-box__field-container {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.aksel-combobox2__field-btn {
|
||||
.aksel-combo-box__field-btn {
|
||||
background-color: var(--ax-bg-input);
|
||||
border-radius: var(--ax-radius-8);
|
||||
border: 1px solid var(--ax-border-neutral);
|
||||
@@ -62,7 +62,7 @@
|
||||
color: ButtonText;
|
||||
}
|
||||
|
||||
.aksel-combobox2[data-size="small"] & {
|
||||
.aksel-combo-box[data-size="small"] & {
|
||||
min-height: 2rem;
|
||||
padding-block: 0;
|
||||
}
|
||||
@@ -79,7 +79,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
.aksel-combobox2__field-chevron {
|
||||
.aksel-combo-box__field-chevron {
|
||||
position: absolute;
|
||||
right: var(--ax-space-8);
|
||||
top: 0;
|
||||
@@ -92,7 +92,7 @@
|
||||
color: ButtonText;
|
||||
}
|
||||
|
||||
.aksel-combobox2[data-size="small"] & {
|
||||
.aksel-combo-box[data-size="small"] & {
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
}
|
||||
@@ -101,7 +101,7 @@
|
||||
* Overlay *
|
||||
************************************************/
|
||||
|
||||
.aksel-combobox2__modal {
|
||||
.aksel-combo-box__modal {
|
||||
/**
|
||||
* We set the height of the content to the visible viewport, but the virtual
|
||||
* keyboard will still compensate for it's precence by adding some empty space
|
||||
@@ -119,7 +119,7 @@
|
||||
touch-action: pinch-zoom pan-x;
|
||||
}
|
||||
|
||||
.aksel-combobox2__modal-inner {
|
||||
.aksel-combo-box__modal-inner {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
@@ -129,7 +129,7 @@
|
||||
* Popup *
|
||||
************************************************/
|
||||
|
||||
.aksel-combobox2__popup {
|
||||
.aksel-combo-box__popup {
|
||||
/* stylelint-disable-next-line csstools/value-no-unknown-custom-properties */
|
||||
min-width: var(--__axc-floating-anchor-width);
|
||||
/* stylelint-disable-next-line csstools/value-no-unknown-custom-properties */
|
||||
@@ -142,7 +142,7 @@
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
|
||||
.aksel-combobox2:not(:has(.aksel-combobox2__modal)) & {
|
||||
.aksel-combo-box:not(:has(.aksel-combo-box__modal)) & {
|
||||
outline: 1px solid var(--ax-border-neutral-subtleA);
|
||||
outline-offset: -1px;
|
||||
border-radius: var(--ax-radius-8);
|
||||
@@ -154,11 +154,11 @@
|
||||
* Filter input *
|
||||
************************************************/
|
||||
|
||||
.aksel-combobox2__filter {
|
||||
.aksel-combo-box__filter {
|
||||
margin: -1px;
|
||||
}
|
||||
|
||||
.aksel-combobox2__filter .aksel-search__wrapper:has(.aksel-search__input:focus-visible) {
|
||||
.aksel-combo-box__filter .aksel-search__wrapper:has(.aksel-search__input:focus-visible) {
|
||||
outline: none;
|
||||
position: relative;
|
||||
|
||||
@@ -170,13 +170,13 @@
|
||||
border: 2px solid var(--ax-border-focus);
|
||||
}
|
||||
|
||||
.aksel-combobox2:not(:has(.aksel-combobox2__modal)) &::after {
|
||||
.aksel-combo-box:not(:has(.aksel-combo-box__modal)) &::after {
|
||||
border-top-left-radius: var(--ax-radius-8);
|
||||
border-top-right-radius: var(--ax-radius-8);
|
||||
}
|
||||
}
|
||||
|
||||
.aksel-combobox2__filter .aksel-search__input {
|
||||
.aksel-combo-box__filter .aksel-search__input {
|
||||
border-bottom-left-radius: 0;
|
||||
border-bottom-right-radius: 0;
|
||||
|
||||
@@ -184,11 +184,11 @@
|
||||
border-color: var(--ax-border-neutral-subtleA);
|
||||
}
|
||||
|
||||
.aksel-combobox2__popup[data-size="medium"] & {
|
||||
.aksel-combo-box__popup[data-size="medium"] & {
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.aksel-combobox2__modal & {
|
||||
.aksel-combo-box__modal & {
|
||||
border-radius: 0;
|
||||
}
|
||||
}
|
||||
@@ -197,10 +197,10 @@
|
||||
* List *
|
||||
************************************************/
|
||||
|
||||
.aksel-combobox2__list {
|
||||
.aksel-combo-box__list {
|
||||
padding-block: var(--ax-space-12);
|
||||
|
||||
.aksel-combobox2__modal & {
|
||||
.aksel-combo-box__modal & {
|
||||
padding-inline: var(--ax-space-16);
|
||||
|
||||
/* Prevents scrolling to area taken up by virtual keyboard.
|
||||
@@ -211,7 +211,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
.aksel-combobox2__no-results {
|
||||
.aksel-combo-box__no-results {
|
||||
padding: var(--ax-space-12) var(--ax-space-8);
|
||||
text-align: center;
|
||||
}
|
||||
@@ -220,7 +220,7 @@
|
||||
* Option *
|
||||
************************************************/
|
||||
|
||||
.aksel-combobox2__option:is([aria-selected="true"], [aria-selected="true"][data-virtual-focus="true"])
|
||||
.aksel-combo-box__option:is([aria-selected="true"], [aria-selected="true"][data-virtual-focus="true"])
|
||||
.aksel-listbox__option-inner {
|
||||
background-color: var(--ax-bg-moderate-pressedA);
|
||||
|
||||
@@ -231,30 +231,23 @@
|
||||
}
|
||||
}
|
||||
|
||||
.aksel-combobox2__option-checkmark {
|
||||
--__axc-combobox2-option-checkmark-size: 1.25rem;
|
||||
.aksel-combo-box__option-checkmark {
|
||||
--__axc-combo-box-option-checkmark-size: 1.25rem;
|
||||
|
||||
width: var(--__axc-combobox2-option-checkmark-size);
|
||||
height: var(--__axc-combobox2-option-checkmark-size);
|
||||
width: var(--__axc-combo-box-option-checkmark-size);
|
||||
height: var(--__axc-combo-box-option-checkmark-size);
|
||||
margin-top: var(--ax-space-2);
|
||||
float: left;
|
||||
|
||||
.aksel-combobox2__popup[data-size="small"] & {
|
||||
--__axc-combobox2-option-checkmark-size: 1rem;
|
||||
.aksel-combo-box__popup[data-size="small"] & {
|
||||
--__axc-combo-box-option-checkmark-size: 1rem;
|
||||
}
|
||||
|
||||
& svg {
|
||||
font-size: var(--__axc-combobox2-option-checkmark-size);
|
||||
font-size: var(--__axc-combo-box-option-checkmark-size);
|
||||
}
|
||||
}
|
||||
|
||||
.aksel-combobox2__option-label {
|
||||
.aksel-combo-box__option-label {
|
||||
padding-left: var(--ax-space-24);
|
||||
|
||||
/* &[data-nowrap="true"] {
|
||||
padding-left: var(--ax-space-2);
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
} */
|
||||
}
|
||||
@@ -1,5 +1,21 @@
|
||||
# @navikt/ds-react
|
||||
|
||||
## 8.23.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- DataGrid: Faster rendering when many details panels are expanded. ([#5494](https://github.com/navikt/aksel/pull/5494))
|
||||
|
||||
- DataGrid.Table: Keyboard navigation no longer rebuilds the internal grid map on every arrow key press, improving responsiveness in large tables. ([#5491](https://github.com/navikt/aksel/pull/5491))
|
||||
|
||||
- Combobox: Ignore option selection when an open Combobox becomes disabled. ([#5520](https://github.com/navikt/aksel/pull/5520))
|
||||
|
||||
- Timeline: Optimize period parsing. ([#5469](https://github.com/navikt/aksel/pull/5469))
|
||||
|
||||
- Updated dependencies [[`d9a529f`](https://github.com/navikt/aksel/commit/d9a529f3968581225579d935ab8d3df463d781d6)]:
|
||||
- @navikt/aksel-icons@8.23.0
|
||||
- @navikt/ds-tokens@8.23.0
|
||||
|
||||
## 8.22.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@navikt/ds-react",
|
||||
"version": "8.22.1",
|
||||
"version": "8.23.0",
|
||||
"description": "React components from the Norwegian Labour and Welfare Administration.",
|
||||
"author": "Aksel, a team part of the Norwegian Labour and Welfare Administration.",
|
||||
"license": "MIT",
|
||||
@@ -571,12 +571,12 @@
|
||||
},
|
||||
"./Combobox": {
|
||||
"import": {
|
||||
"types": "./esm/form/combobox/index.d.ts",
|
||||
"default": "./esm/form/combobox/index.js"
|
||||
"types": "./esm/legacy/combobox/index.d.ts",
|
||||
"default": "./esm/legacy/combobox/index.js"
|
||||
},
|
||||
"require": {
|
||||
"types": "./cjs/form/combobox/index.d.ts",
|
||||
"default": "./cjs/form/combobox/index.js"
|
||||
"types": "./cjs/legacy/combobox/index.d.ts",
|
||||
"default": "./cjs/legacy/combobox/index.js"
|
||||
}
|
||||
},
|
||||
"./ConfirmationPanel": {
|
||||
@@ -788,8 +788,8 @@
|
||||
"dependencies": {
|
||||
"@floating-ui/react": "0.27.20",
|
||||
"@floating-ui/react-dom": "^2.1.9",
|
||||
"@navikt/aksel-icons": "^8.22.1",
|
||||
"@navikt/ds-tokens": "^8.22.1",
|
||||
"@navikt/aksel-icons": "^8.23.0",
|
||||
"@navikt/ds-tokens": "^8.23.0",
|
||||
"date-fns": "^4.0.0",
|
||||
"react-day-picker": "10.0.2"
|
||||
},
|
||||
@@ -811,10 +811,10 @@
|
||||
"react-dom": "19.3.1",
|
||||
"rimraf": "6.1.3",
|
||||
"swr": "^2.4.2",
|
||||
"tsc-alias": "1.9.7",
|
||||
"tsc-alias": "1.9.10",
|
||||
"tsx": "^4.23.15",
|
||||
"typescript": "6.0.3",
|
||||
"vitest": "5.0.5"
|
||||
"vitest": "5.1.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@types/react": "^17.0.30 || ^18 || ^19",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { forwardRef, useContext, useMemo } from "react";
|
||||
import React, { forwardRef, useContext } from "react";
|
||||
import { omit } from "../../utils-external";
|
||||
import { cl } from "../../utils/helpers";
|
||||
import { useControllableState } from "../../utils/hooks";
|
||||
@@ -46,14 +46,6 @@ const AccordionItem = forwardRef<HTMLDivElement, AccordionItemProps>(
|
||||
console.error("<Accordion.Item> has to be used within an <Accordion>");
|
||||
}
|
||||
|
||||
const contextValue = useMemo(
|
||||
() => ({
|
||||
open: _open,
|
||||
toggleOpen: () => _setOpen((x) => !x),
|
||||
}),
|
||||
[_open, _setOpen],
|
||||
);
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cl("aksel-accordion__item", className, {
|
||||
@@ -63,7 +55,12 @@ const AccordionItem = forwardRef<HTMLDivElement, AccordionItemProps>(
|
||||
ref={ref}
|
||||
{...omit(rest, ["onClick"])}
|
||||
>
|
||||
<AccordionItemContext.Provider value={contextValue}>
|
||||
<AccordionItemContext.Provider
|
||||
value={{
|
||||
open: _open,
|
||||
toggleOpen: () => _setOpen((x) => !x),
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</AccordionItemContext.Provider>
|
||||
</div>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { forwardRef, useEffect, useMemo, useRef } from "react";
|
||||
import React, { forwardRef, useEffect, useRef } from "react";
|
||||
import type { AkselStatusColorRole } from "@navikt/ds-tokens/types";
|
||||
import type { AkselColor } from "../../types";
|
||||
import { omit } from "../../utils-external";
|
||||
@@ -95,17 +95,14 @@ const AccordionRoot = forwardRef<HTMLDivElement, AccordionProps>(
|
||||
}
|
||||
}, []);
|
||||
|
||||
const contextValue = useMemo(
|
||||
() => ({
|
||||
size,
|
||||
variant,
|
||||
mounted: true,
|
||||
}),
|
||||
[size, variant],
|
||||
);
|
||||
|
||||
return (
|
||||
<AccordionContext.Provider value={contextValue}>
|
||||
<AccordionContext.Provider
|
||||
value={{
|
||||
size,
|
||||
mounted: true,
|
||||
variant,
|
||||
}}
|
||||
>
|
||||
<Component
|
||||
{...omit(rest, ["headingSize"])}
|
||||
className={cl(
|
||||
|
||||
@@ -89,7 +89,12 @@ export const Button: OverridableComponent<ButtonProps, HTMLButtonElement> =
|
||||
disabled || loading ? omit(rest, ["href"]) : rest;
|
||||
|
||||
const handleKeyUp = (e: React.KeyboardEvent<HTMLButtonElement>) => {
|
||||
if (e.key === " " && !disabled && !loading) {
|
||||
if (
|
||||
e.key === " " &&
|
||||
e.currentTarget.tagName !== "BUTTON" &&
|
||||
!disabled &&
|
||||
!loading
|
||||
) {
|
||||
e.currentTarget.click();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,200 @@
|
||||
import type { Meta, StoryObj } from "@storybook/react-vite";
|
||||
import React, { useMemo, useState } from "react";
|
||||
import { DataGrid } from "..";
|
||||
import { Pagination } from "../../pagination";
|
||||
import { HStack, VStack } from "../../primitives/stack";
|
||||
import { Detail } from "../../typography";
|
||||
import {
|
||||
type DataGridPlugin,
|
||||
type DataGridPlugins,
|
||||
applyTableContext,
|
||||
resolveDataGridPlugins,
|
||||
} from "./dataGridPlugins";
|
||||
|
||||
type InvoiceRow = {
|
||||
id: string;
|
||||
invoiceNumber: string;
|
||||
category: string;
|
||||
status: string;
|
||||
amount: string;
|
||||
};
|
||||
|
||||
const DEMO_ROWS: InvoiceRow[] = [
|
||||
{
|
||||
id: "1",
|
||||
invoiceNumber: "INV-2026-001",
|
||||
category: "Cloud Hosting",
|
||||
status: "Paid",
|
||||
amount: "12 400 kr",
|
||||
},
|
||||
{
|
||||
id: "2",
|
||||
invoiceNumber: "INV-2026-002",
|
||||
category: "Software License",
|
||||
status: "Pending",
|
||||
amount: "4 850 kr",
|
||||
},
|
||||
{
|
||||
id: "3",
|
||||
invoiceNumber: "INV-2026-003",
|
||||
category: "Office Supplies",
|
||||
status: "Paid",
|
||||
amount: "1 290 kr",
|
||||
},
|
||||
{
|
||||
id: "4",
|
||||
invoiceNumber: "INV-2026-004",
|
||||
category: "Security Audit",
|
||||
status: "Overdue",
|
||||
amount: "28 000 kr",
|
||||
},
|
||||
{
|
||||
id: "5",
|
||||
invoiceNumber: "INV-2026-005",
|
||||
category: "Hardware",
|
||||
status: "Paid",
|
||||
amount: "19 990 kr",
|
||||
},
|
||||
{
|
||||
id: "6",
|
||||
invoiceNumber: "INV-2026-006",
|
||||
category: "Training",
|
||||
status: "Pending",
|
||||
amount: "7 500 kr",
|
||||
},
|
||||
{
|
||||
id: "7",
|
||||
invoiceNumber: "INV-2026-007",
|
||||
category: "Domain Renewal",
|
||||
status: "Paid",
|
||||
amount: "640 kr",
|
||||
},
|
||||
{
|
||||
id: "8",
|
||||
invoiceNumber: "INV-2026-008",
|
||||
category: "Monitoring",
|
||||
status: "Pending",
|
||||
amount: "3 200 kr",
|
||||
},
|
||||
];
|
||||
|
||||
const DEMO_COLUMNS: DataGrid.Columns<InvoiceRow> = [
|
||||
{
|
||||
id: "invoiceNumber",
|
||||
header: "Invoice",
|
||||
isRowHeader: true,
|
||||
bodyCell: (row) => row.invoiceNumber,
|
||||
},
|
||||
{ id: "category", header: "Category", bodyCell: (row) => row.category },
|
||||
{ id: "status", header: "Status", bodyCell: (row) => row.status },
|
||||
{ id: "amount", header: "Amount", bodyCell: (row) => row.amount },
|
||||
];
|
||||
|
||||
/**
|
||||
* Preview of how `DataGrid` will integrate the plugin API.
|
||||
* Only two lines are added around `DataGrid`'s children:
|
||||
* 1. `resolveDataGridPlugins(userPlugins)` to order and stabilize plugins
|
||||
* 2. `applyTableContext(plugins, children)` to wrap the grid output
|
||||
*/
|
||||
function PluginAwareDataGrid<RowT>({
|
||||
plugins: userPlugins,
|
||||
children,
|
||||
...dataGridProps
|
||||
}: DataGrid.Props<RowT> & { plugins?: DataGridPlugins }) {
|
||||
const plugins = resolveDataGridPlugins(userPlugins);
|
||||
|
||||
return (
|
||||
<DataGrid {...dataGridProps}>
|
||||
{applyTableContext(plugins, children)}
|
||||
</DataGrid>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Example first-party plugin hook.
|
||||
* The consumer owns pagination state; the hook returns a memoized `DataGridPlugin`
|
||||
* that wraps the table with Aksel's `<Pagination />`.
|
||||
*/
|
||||
function useDummyPaginationPlugin({
|
||||
page,
|
||||
pageSize,
|
||||
totalItems,
|
||||
onPageChange,
|
||||
}: {
|
||||
page: number;
|
||||
pageSize: number;
|
||||
totalItems: number;
|
||||
onPageChange: (nextPage: number) => void;
|
||||
}): DataGridPlugin {
|
||||
return useMemo(() => {
|
||||
const pageCount = Math.max(1, Math.ceil(totalItems / pageSize));
|
||||
const start = (page - 1) * pageSize + 1;
|
||||
const end = Math.min(page * pageSize, totalItems);
|
||||
|
||||
return {
|
||||
transformTableContext: (children) => (
|
||||
<VStack gap="space-12" data-plugin="pagination">
|
||||
{children}
|
||||
<HStack align="center" justify="space-between" gap="space-16" wrap>
|
||||
<Detail>
|
||||
Showing {start}–{end} of {totalItems}
|
||||
</Detail>
|
||||
<Pagination
|
||||
page={page}
|
||||
count={pageCount}
|
||||
onPageChange={onPageChange}
|
||||
size="small"
|
||||
/>
|
||||
</HStack>
|
||||
</VStack>
|
||||
),
|
||||
};
|
||||
}, [page, pageSize, totalItems, onPageChange]);
|
||||
}
|
||||
|
||||
const meta: Meta = {
|
||||
title: "ds-react/DataGrid/Plugins",
|
||||
parameters: {
|
||||
chromatic: { disable: true },
|
||||
layout: "padded",
|
||||
},
|
||||
};
|
||||
|
||||
export default meta;
|
||||
|
||||
type Story = StoryObj;
|
||||
|
||||
/**
|
||||
* Shows the intended consumer API for a first-party plugin hook:
|
||||
* state stays in consumer code, the hook returns a memoized `DataGridPlugin`,
|
||||
* and `DataGrid` renders it through `plugins={{ pagination }}`.
|
||||
*/
|
||||
export const PaginationPlugin: Story = {
|
||||
render: function PaginationPluginDemo() {
|
||||
const [page, setPage] = useState(1);
|
||||
const pageSize = 3;
|
||||
|
||||
const paginationPlugin = useDummyPaginationPlugin({
|
||||
page,
|
||||
pageSize,
|
||||
totalItems: DEMO_ROWS.length,
|
||||
onPageChange: setPage,
|
||||
});
|
||||
|
||||
const pageRows = useMemo(
|
||||
() => DEMO_ROWS.slice((page - 1) * pageSize, page * pageSize),
|
||||
[page],
|
||||
);
|
||||
|
||||
return (
|
||||
<PluginAwareDataGrid
|
||||
columns={DEMO_COLUMNS}
|
||||
data={pageRows}
|
||||
getRowId={(row) => row.id}
|
||||
plugins={{ pagination: paginationPlugin }}
|
||||
>
|
||||
<DataGrid.Table />
|
||||
</PluginAwareDataGrid>
|
||||
);
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,135 @@
|
||||
import { afterEach, describe, expect, test, vi } from "vitest";
|
||||
import * as consoleWarningModule from "../../utils/helpers/consoleWarning";
|
||||
import {
|
||||
type DataGridPlugin,
|
||||
type DataGridPlugins,
|
||||
applyTableContext,
|
||||
resolveDataGridPlugins,
|
||||
} from "./dataGridPlugins";
|
||||
|
||||
const createContextPlugin = (label: string): DataGridPlugin => ({
|
||||
transformTableContext: (children) => `${label}(${children})`,
|
||||
});
|
||||
|
||||
describe("resolveDataGridPlugins", () => {
|
||||
test("returns a stable empty array when plugins are undefined or empty", () => {
|
||||
const initialResult = resolveDataGridPlugins(undefined);
|
||||
expect(initialResult).toEqual([]);
|
||||
expect(resolveDataGridPlugins({})).toBe(initialResult);
|
||||
});
|
||||
|
||||
test("orders known plugins before unknown plugins, ignores prototype keys, and skips non-object entries", () => {
|
||||
const customFirst = createContextPlugin("first");
|
||||
const customSecond = createContextPlugin("second");
|
||||
const pagination = createContextPlugin("pagination");
|
||||
|
||||
expect(
|
||||
resolveDataGridPlugins({
|
||||
zCustom: customFirst,
|
||||
aCustom: customSecond,
|
||||
pagination,
|
||||
}),
|
||||
).toEqual([pagination, customFirst, customSecond]);
|
||||
|
||||
const inherited = Object.create({ pagination }) as DataGridPlugins;
|
||||
inherited.custom = customFirst;
|
||||
expect(resolveDataGridPlugins(inherited)).toEqual([customFirst]);
|
||||
|
||||
// Runtime guard: nullish or primitive entries on known or custom keys are skipped instead of crashing WeakMap
|
||||
expect(
|
||||
resolveDataGridPlugins({
|
||||
pagination: undefined,
|
||||
customUndefined: undefined,
|
||||
customNull: null,
|
||||
customPrimitive: "not-an-object",
|
||||
valid: customFirst,
|
||||
} as unknown as DataGridPlugins),
|
||||
).toEqual([customFirst]);
|
||||
});
|
||||
|
||||
test("interns array reference by plugin identity and order across inline objects", () => {
|
||||
const pagination = createContextPlugin("pagination");
|
||||
const customA = createContextPlugin("a");
|
||||
const customB = createContextPlugin("b");
|
||||
|
||||
const first = resolveDataGridPlugins({ customA, pagination });
|
||||
expect(Object.isFrozen(first)).toBe(true);
|
||||
|
||||
// New inline object with same plugin instances (even in different key order)
|
||||
expect(resolveDataGridPlugins({ pagination, customA })).toBe(first);
|
||||
|
||||
// Removing a plugin returns a new array; restoring it returns the interned array
|
||||
const paginationOnly = resolveDataGridPlugins({ pagination });
|
||||
expect(paginationOnly).not.toBe(first);
|
||||
expect(paginationOnly).toEqual([pagination]);
|
||||
|
||||
expect(resolveDataGridPlugins({ pagination, customA })).toBe(first);
|
||||
|
||||
// Changing plugin order or replacing an instance produces a new array
|
||||
const ab = resolveDataGridPlugins({ customA, customB });
|
||||
const ba = resolveDataGridPlugins({ customB, customA });
|
||||
expect(ba).not.toBe(ab);
|
||||
expect(ba).toEqual([customB, customA]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("applyTableContext", () => {
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
test("wraps children in reverse plugin order and skips plugins without a valid transform", () => {
|
||||
const pagination = createContextPlugin("pagination");
|
||||
const custom = createContextPlugin("custom");
|
||||
const noopPlugin = {} as DataGridPlugin;
|
||||
const invalidPlugin = {
|
||||
transformTableContext: "not-a-function",
|
||||
} as unknown as DataGridPlugin;
|
||||
|
||||
expect(applyTableContext([], "table")).toBe("table");
|
||||
expect(
|
||||
applyTableContext(
|
||||
[pagination, noopPlugin, invalidPlugin, custom],
|
||||
"table",
|
||||
),
|
||||
).toBe("pagination(custom(table))");
|
||||
});
|
||||
|
||||
test("preserves previous content and warns when transformTableContext returns undefined", () => {
|
||||
const warnSpy = vi
|
||||
.spyOn(consoleWarningModule, "consoleWarning")
|
||||
.mockImplementation(() => {});
|
||||
const outer = createContextPlugin("outer");
|
||||
const returnsUndefined: DataGridPlugin = {
|
||||
transformTableContext: () => undefined,
|
||||
};
|
||||
const inner = createContextPlugin("inner");
|
||||
|
||||
expect(applyTableContext([outer, returnsUndefined, inner], "table")).toBe(
|
||||
"outer(inner(table))",
|
||||
);
|
||||
expect(warnSpy).toHaveBeenCalledWith(
|
||||
expect.stringContaining("transformTableContext returned undefined"),
|
||||
);
|
||||
});
|
||||
|
||||
test("catches plugin errors, logs them, and continues applying remaining plugins", () => {
|
||||
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
const boom = new Error("plugin failure");
|
||||
const outer = createContextPlugin("outer");
|
||||
const broken: DataGridPlugin = {
|
||||
transformTableContext: () => {
|
||||
throw boom;
|
||||
},
|
||||
};
|
||||
const inner = createContextPlugin("inner");
|
||||
|
||||
expect(applyTableContext([outer, broken, inner], "table")).toBe(
|
||||
"outer(inner(table))",
|
||||
);
|
||||
expect(errorSpy).toHaveBeenCalledWith(
|
||||
"[Aksel] DataGrid: Plugin threw in transformTableContext:",
|
||||
boom,
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,201 @@
|
||||
import type { ReactNode } from "react";
|
||||
import { consoleWarning } from "../../utils/helpers/consoleWarning";
|
||||
|
||||
/**
|
||||
* Plugin that extends DataGrid rendering (e.g. wrapping the table in providers
|
||||
* or extra UI). Remember to memoize the plugin object (with `useMemo`) so
|
||||
* DataGrid can skip unnecessary re-renders.
|
||||
*/
|
||||
interface DataGridPlugin {
|
||||
/**
|
||||
* Wraps the table output in context providers or surrounding UI (e.g. pagination).
|
||||
* Runs as a plain function during render. Do not call React hooks directly
|
||||
* inside this function; render a component or provider that calls hooks instead.
|
||||
*/
|
||||
transformTableContext: (children: ReactNode) => ReactNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed order for built-in plugins so behavior doesn't depend on key order
|
||||
* in `plugins={{ ... }}`. Custom plugins are placed after these, in their
|
||||
* original order.
|
||||
*/
|
||||
const PLUGIN_ORDER = ["pagination"] as const;
|
||||
const KNOWN_PLUGINS = new Set<string>(PLUGIN_ORDER);
|
||||
|
||||
type BuiltInDataGridPluginKey = (typeof PLUGIN_ORDER)[number];
|
||||
|
||||
/**
|
||||
* Named plugins passed to DataGrid.
|
||||
*
|
||||
* Keep plugins always present rather than toggling entries conditionally:
|
||||
* adding or removing a plugin that wraps children changes React's tree depth and remounts the grid.
|
||||
* Control active/visible state inside the plugin instead.
|
||||
*/
|
||||
type DataGridPlugins = Partial<
|
||||
Record<BuiltInDataGridPluginKey, DataGridPlugin>
|
||||
> &
|
||||
Record<string, DataGridPlugin>;
|
||||
|
||||
/**
|
||||
* We freeze in dev-mode to enforce immutability of the empty plugin array.
|
||||
* Based on React best practices: https://react.dev/reference/react/createElement#caveats
|
||||
*/
|
||||
const EMPTY_PLUGINS: readonly never[] =
|
||||
process.env.NODE_ENV !== "production" ? Object.freeze([]) : [];
|
||||
|
||||
/**
|
||||
* Turns a `plugins={{ ... }}` object into an ordered, stable plugin array.
|
||||
*
|
||||
* - Orders built-in plugins consistently (`orderPlugins`).
|
||||
* - Keeps the same array reference even when the consumer passes an inline
|
||||
* `plugins={{ pagination }}` object on every render (`internByIdentity`).
|
||||
*/
|
||||
function resolveDataGridPlugins(
|
||||
userPlugins?: DataGridPlugins,
|
||||
): readonly DataGridPlugin[] {
|
||||
return internByIdentity(orderPlugins(userPlugins));
|
||||
}
|
||||
|
||||
// WeakMap keys must be objects; guard against nullish/primitive entries at runtime.
|
||||
function isPluginObject(value: unknown): value is DataGridPlugin {
|
||||
return typeof value === "object" && value !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Places known plugins first (in `PLUGIN_ORDER`), then unknown plugins in
|
||||
* insertion order.
|
||||
*/
|
||||
function orderPlugins(
|
||||
userPlugins?: DataGridPlugins,
|
||||
): readonly DataGridPlugin[] {
|
||||
if (!userPlugins) {
|
||||
return EMPTY_PLUGINS;
|
||||
}
|
||||
|
||||
const keys = Object.keys(userPlugins);
|
||||
if (keys.length === 0) {
|
||||
return EMPTY_PLUGINS;
|
||||
}
|
||||
|
||||
const ordered: DataGridPlugin[] = [];
|
||||
|
||||
for (const name of PLUGIN_ORDER) {
|
||||
/* TS target does not support Object.hasOwn */
|
||||
if (Object.prototype.hasOwnProperty.call(userPlugins, name)) {
|
||||
const plugin = userPlugins[name];
|
||||
if (isPluginObject(plugin)) {
|
||||
ordered.push(plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const name of keys) {
|
||||
if (!KNOWN_PLUGINS.has(name)) {
|
||||
const plugin = userPlugins[name];
|
||||
if (isPluginObject(plugin)) {
|
||||
ordered.push(plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ordered;
|
||||
}
|
||||
|
||||
interface InternNode {
|
||||
readonly next: WeakMap<object, InternNode>;
|
||||
array?: readonly object[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tree of WeakMaps where each path represents a sequence of plugin objects.
|
||||
* WeakMap lets unused paths be garbage-collected when plugins go away.
|
||||
*/
|
||||
const internRoot: InternNode = { next: new WeakMap() };
|
||||
|
||||
/**
|
||||
* Returns the same array instance whenever given the same objects in the same order
|
||||
* using a WeakMap trie (prefix tree keyed by object identity).
|
||||
*
|
||||
* Solves inline `plugins={{ pagination }}` props: `useMemo` on the outer object
|
||||
* would miss every render, and mutating a `useRef` during render is unsafe in
|
||||
* StrictMode / concurrent React.
|
||||
*
|
||||
* Each item walks one step down `internRoot`:
|
||||
* ```text
|
||||
* internRoot
|
||||
* └─ [pluginA] ──▶ nodeA (array: [pluginA])
|
||||
* └─ [pluginB] ──▶ nodeAB (array: [pluginA, pluginB])
|
||||
* └─ [pluginB] ──▶ nodeB
|
||||
* └─ [pluginA] ──▶ nodeBA (array: [pluginB, pluginA])
|
||||
* ```
|
||||
*
|
||||
* 1. Walk `internRoot` using each item as a `WeakMap` key, creating nodes as needed.
|
||||
* 2. Cache a copy at the terminal node so future calls with the same sequence return the exact same (`===`) array.
|
||||
* 3. Unused branches are garbage-collected automatically once any plugin object in the path is no longer referenced.
|
||||
*/
|
||||
function internByIdentity<T extends object>(items: readonly T[]): readonly T[] {
|
||||
if (items.length === 0) {
|
||||
return EMPTY_PLUGINS;
|
||||
}
|
||||
|
||||
let node = internRoot;
|
||||
for (const item of items) {
|
||||
let child = node.next.get(item);
|
||||
if (child === undefined) {
|
||||
child = { next: new WeakMap() };
|
||||
node.next.set(item, child);
|
||||
}
|
||||
node = child;
|
||||
}
|
||||
|
||||
if (node.array === undefined) {
|
||||
const copy = items.slice();
|
||||
/* Freeze in dev so accidental mutation fails fast instead of corrupting the shared cache. */
|
||||
node.array =
|
||||
process.env.NODE_ENV !== "production" ? Object.freeze(copy) : copy;
|
||||
}
|
||||
return node.array as readonly T[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps `children` with each plugin's `transformTableContext`.
|
||||
* Runs in reverse so the first plugin wraps outermost.
|
||||
* Synchronous errors are caught and logged, and an `undefined` return preserves
|
||||
* the previous content so one broken plugin doesn't blank or crash the grid.
|
||||
*/
|
||||
function applyTableContext(
|
||||
plugins: readonly DataGridPlugin[],
|
||||
children: ReactNode,
|
||||
): ReactNode {
|
||||
let content = children;
|
||||
|
||||
for (let i = plugins.length - 1; i >= 0; i--) {
|
||||
const transform = plugins[i].transformTableContext;
|
||||
|
||||
if (typeof transform !== "function") {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
const next = transform(content);
|
||||
if (next === undefined) {
|
||||
consoleWarning(
|
||||
"DataGrid: Plugin transformTableContext returned undefined. Preserving previous content.",
|
||||
);
|
||||
continue;
|
||||
}
|
||||
content = next;
|
||||
} catch (error) {
|
||||
console.error(
|
||||
"[Aksel] DataGrid: Plugin threw in transformTableContext:",
|
||||
error,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
export { applyTableContext, resolveDataGridPlugins };
|
||||
export type { DataGridPlugin, DataGridPlugins };
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { Meta, StoryObj } from "@storybook/react-vite";
|
||||
import React from "react";
|
||||
import { expect, userEvent, within } from "storybook/test";
|
||||
import { expect, fn, userEvent, within } from "storybook/test";
|
||||
import { DataGrid } from "../../data-grid";
|
||||
import type { ColumnDefinitions } from "../table/root/DataGridTable.types";
|
||||
import { DataGridTable } from "../table/root/DataGridTableRoot";
|
||||
@@ -228,3 +228,78 @@ export const SelectAllIncludesHiddenDescendantsForCollapsedParents: Story = {
|
||||
expect(getCheckboxes(canvasElement)[3].checked).toBe(false);
|
||||
},
|
||||
};
|
||||
|
||||
const detailsPanelData: TestRow[] = [
|
||||
{ id: "a", name: "Alpha" },
|
||||
{ id: "b", name: "Beta" },
|
||||
{ id: "c", name: "Gamma" },
|
||||
];
|
||||
|
||||
function ControlledDetailsPanel({
|
||||
onExpandedRowIdsChange,
|
||||
}: {
|
||||
onExpandedRowIdsChange: (ids: string[]) => void;
|
||||
}) {
|
||||
const [expandedRowIds, setExpandedRowIds] = React.useState(["a"]);
|
||||
|
||||
return (
|
||||
<DataGrid
|
||||
columns={columns}
|
||||
data={detailsPanelData}
|
||||
getRowId={(row) => row.id}
|
||||
>
|
||||
<DataGrid.Table<TestRow>
|
||||
detailsPanel={{
|
||||
getContent: (row) => `Detaljer for ${row.name}`,
|
||||
isRowExpandable: (row) => row.id !== "c",
|
||||
expandedRowIds,
|
||||
onExpandedRowIdsChange: (ids) => {
|
||||
onExpandedRowIdsChange(ids);
|
||||
setExpandedRowIds(ids);
|
||||
},
|
||||
showExpandAll: true,
|
||||
}}
|
||||
/>
|
||||
</DataGrid>
|
||||
);
|
||||
}
|
||||
|
||||
export const ControlledDetailsPanelExpansion: StoryObj<{
|
||||
onExpandedRowIdsChange: ReturnType<typeof fn>;
|
||||
}> = {
|
||||
args: {
|
||||
onExpandedRowIdsChange: fn(),
|
||||
},
|
||||
render: (props) => <ControlledDetailsPanel {...props} />,
|
||||
play: async ({ canvasElement, args }) => {
|
||||
args.onExpandedRowIdsChange.mockClear();
|
||||
const canvas = within(canvasElement);
|
||||
|
||||
expect(canvas.getByText("Detaljer for Alpha")).toBeInTheDocument();
|
||||
expect(canvas.queryByText("Detaljer for Beta")).not.toBeInTheDocument();
|
||||
expect(
|
||||
canvas.getByRole("button", { name: "Vis alle rader" }),
|
||||
).toHaveAttribute("aria-expanded", "false");
|
||||
|
||||
await userEvent.click(canvas.getByRole("button", { name: "Vis detaljer" }));
|
||||
|
||||
expect(args.onExpandedRowIdsChange).toHaveBeenLastCalledWith(["a", "b"]);
|
||||
expect(canvas.getByText("Detaljer for Beta")).toBeInTheDocument();
|
||||
|
||||
await userEvent.click(
|
||||
canvas.getByRole("button", { name: "Skjul alle rader" }),
|
||||
);
|
||||
|
||||
expect(args.onExpandedRowIdsChange).toHaveBeenLastCalledWith([]);
|
||||
expect(canvas.queryByText("Detaljer for Alpha")).not.toBeInTheDocument();
|
||||
expect(canvas.queryByText("Detaljer for Beta")).not.toBeInTheDocument();
|
||||
|
||||
await userEvent.click(
|
||||
canvas.getByRole("button", { name: "Vis alle rader" }),
|
||||
);
|
||||
|
||||
expect(args.onExpandedRowIdsChange).toHaveBeenLastCalledWith(["a", "b"]);
|
||||
expect(canvas.queryByText("Detaljer for Gamma")).not.toBeInTheDocument();
|
||||
expect(args.onExpandedRowIdsChange).toHaveBeenCalledTimes(3);
|
||||
},
|
||||
};
|
||||
@@ -5,7 +5,9 @@ import { type GridCache, buildTableGridMap } from "../helpers/table-grid-nav";
|
||||
/**
|
||||
* Manages the table grid cache and observes DOM changes that require grid rebuilding.
|
||||
* Watches for structural changes (rows/cells added/removed) and attribute changes
|
||||
* (colspan, rowspan, hidden, style) that affect grid layout and focusability.
|
||||
* (colspan, rowspan, hidden) that affect grid layout.
|
||||
* Inline `style` is intentionally not observed: focus navigation writes
|
||||
* scroll-margin on every move, and the grid never reads styles.
|
||||
*/
|
||||
function useGridCache(tableRef: HTMLTableElement | null, enabled: boolean) {
|
||||
const gridCacheRef = useRef<GridCache>({
|
||||
@@ -34,7 +36,7 @@ function useGridCache(tableRef: HTMLTableElement | null, enabled: boolean) {
|
||||
subtree: true,
|
||||
childList: true,
|
||||
attributes: true,
|
||||
attributeFilter: ["colspan", "rowspan", "hidden", "style"],
|
||||
attributeFilter: ["colspan", "rowspan", "hidden"],
|
||||
});
|
||||
|
||||
return () => {
|
||||
|
||||
@@ -76,10 +76,15 @@ function DataTableDetailsPanelProvider<T>({
|
||||
showExpandAll = false,
|
||||
} = detailsPanel || {};
|
||||
|
||||
const [expandedIds, setExpandedIds] = useControllableState({
|
||||
value: expandedRowIds,
|
||||
defaultValue: defaultExpandedRowIds,
|
||||
onChange: onExpandedRowIdsChange,
|
||||
const controlledExpandedIds = React.useMemo(
|
||||
() => (expandedRowIds ? new Set(expandedRowIds) : undefined),
|
||||
[expandedRowIds],
|
||||
);
|
||||
|
||||
const [expandedIds, setExpandedIds] = useControllableState<Set<string>>({
|
||||
value: controlledExpandedIds,
|
||||
defaultValue: () => new Set(defaultExpandedRowIds),
|
||||
onChange: (ids) => onExpandedRowIdsChange?.(Array.from(ids)),
|
||||
});
|
||||
|
||||
/* TODO: False is just fallback until auto and root is merged */
|
||||
@@ -116,8 +121,7 @@ function DataTableDetailsPanelProvider<T>({
|
||||
);
|
||||
|
||||
const isExpanded = useCallback(
|
||||
(id: string) =>
|
||||
isDetailsPanelExpandableById(id) && expandedIds.includes(id),
|
||||
(id: string) => isDetailsPanelExpandableById(id) && expandedIds.has(id),
|
||||
[expandedIds, isDetailsPanelExpandableById],
|
||||
);
|
||||
|
||||
@@ -127,21 +131,35 @@ function DataTableDetailsPanelProvider<T>({
|
||||
return;
|
||||
}
|
||||
|
||||
setExpandedIds((currentExpandedIds) =>
|
||||
currentExpandedIds.includes(id)
|
||||
? currentExpandedIds.filter((expandedId) => expandedId !== id)
|
||||
: [...currentExpandedIds, id],
|
||||
);
|
||||
setExpandedIds((currentExpandedIds) => {
|
||||
const nextExpandedIds = new Set(currentExpandedIds);
|
||||
if (nextExpandedIds.has(id)) {
|
||||
nextExpandedIds.delete(id);
|
||||
} else {
|
||||
nextExpandedIds.add(id);
|
||||
}
|
||||
return nextExpandedIds;
|
||||
});
|
||||
},
|
||||
[isDetailsPanelExpandableById, setExpandedIds],
|
||||
);
|
||||
|
||||
const isAllExpanded =
|
||||
expandableIds.size > 0 &&
|
||||
Array.from(expandableIds).every((key) => expandedIds.includes(key));
|
||||
const isAllExpanded = React.useMemo(() => {
|
||||
if (expandableIds.size === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const id of expandableIds) {
|
||||
if (!expandedIds.has(id)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}, [expandableIds, expandedIds]);
|
||||
|
||||
const toggleAll = useCallback(() => {
|
||||
setExpandedIds(isAllExpanded ? [] : Array.from(expandableIds));
|
||||
setExpandedIds(isAllExpanded ? new Set() : new Set(expandableIds));
|
||||
}, [expandableIds, isAllExpanded, setExpandedIds]);
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useMemo, useState } from "react";
|
||||
import React, { useState } from "react";
|
||||
import { useControllableState } from "../../utils/hooks";
|
||||
import { DropdownMenuDivider } from "../divider/DropdownMenuDivider";
|
||||
import { DropdownMenuGroupedListHeading } from "../grouped-list-heading/DropdownMenuGroupedListHeading";
|
||||
@@ -54,22 +54,19 @@ const DropdownRoot = ({
|
||||
onChange: onOpenChange,
|
||||
});
|
||||
|
||||
const contextValue = useMemo(
|
||||
() => ({
|
||||
isOpen: _open,
|
||||
handleToggle: _setOpen,
|
||||
anchorEl,
|
||||
setAnchorEl,
|
||||
onSelect: (event) => {
|
||||
onSelect?.(event);
|
||||
closeOnSelect && _setOpen(false);
|
||||
},
|
||||
}),
|
||||
[anchorEl, onSelect, closeOnSelect, _open, _setOpen],
|
||||
);
|
||||
|
||||
return (
|
||||
<DropdownContext.Provider value={contextValue}>
|
||||
<DropdownContext.Provider
|
||||
value={{
|
||||
isOpen: _open,
|
||||
handleToggle: _setOpen,
|
||||
anchorEl,
|
||||
setAnchorEl,
|
||||
onSelect: (event) => {
|
||||
onSelect?.(event);
|
||||
closeOnSelect && _setOpen(false);
|
||||
},
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</DropdownContext.Provider>
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { forwardRef, useCallback, useMemo } from "react";
|
||||
import React, { forwardRef } from "react";
|
||||
import type { AkselColor } from "../../types";
|
||||
import { cl } from "../../utils/helpers";
|
||||
import { useControllableState } from "../../utils/hooks";
|
||||
@@ -88,17 +88,14 @@ const ExpansionCardRoot = forwardRef<HTMLDivElement, ExpansionCardProps>(
|
||||
defaultValue: defaultOpen,
|
||||
});
|
||||
|
||||
const isOpen = open ?? _open;
|
||||
|
||||
const toggleOpen = useCallback(() => _setOpen((x) => !x), [_setOpen]);
|
||||
|
||||
const contextValue = useMemo(
|
||||
() => ({ open: isOpen, toggleOpen, size }),
|
||||
[isOpen, toggleOpen, size],
|
||||
);
|
||||
|
||||
return (
|
||||
<ExpansionCardContext.Provider value={contextValue}>
|
||||
<ExpansionCardContext.Provider
|
||||
value={{
|
||||
open: open ?? _open,
|
||||
toggleOpen: () => _setOpen((x) => !x),
|
||||
size,
|
||||
}}
|
||||
>
|
||||
<section
|
||||
data-color={color}
|
||||
{...rest}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { Meta, StoryObj } from "@storybook/react-vite";
|
||||
import React from "react";
|
||||
import { Button } from "../button";
|
||||
import { UNSAFE_Combobox } from "../legacy/combobox";
|
||||
import { HStack, VStack } from "../primitives/stack";
|
||||
import { Checkbox, CheckboxGroup } from "./checkbox";
|
||||
import { UNSAFE_Combobox } from "./combobox";
|
||||
import { Fieldset } from "./fieldset";
|
||||
import { FileUpload } from "./file-upload";
|
||||
import { Radio, RadioGroup } from "./radio";
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
import React, {
|
||||
forwardRef,
|
||||
useCallback,
|
||||
useContext,
|
||||
useMemo,
|
||||
useState,
|
||||
} from "react";
|
||||
import React, { forwardRef, useContext, useState } from "react";
|
||||
import { cl } from "../../utils/helpers";
|
||||
import { Fieldset, type FieldsetProps } from "../fieldset";
|
||||
import { FieldsetContext } from "../fieldset/context";
|
||||
@@ -59,26 +53,24 @@ export const CheckboxGroup = forwardRef<
|
||||
|
||||
const [state, setState] = useState<any[]>(defaultValue ?? []);
|
||||
|
||||
const toggleValue = useCallback(
|
||||
(v: any) => {
|
||||
const newValue = value ?? state;
|
||||
const newState = newValue.includes(v)
|
||||
? newValue.filter((x) => x !== v)
|
||||
: [...newValue, v];
|
||||
const toggleValue = (v: any) => {
|
||||
const newValue = value ?? state;
|
||||
const newState = newValue.includes(v)
|
||||
? newValue.filter((x) => x !== v)
|
||||
: [...newValue, v];
|
||||
|
||||
value === undefined && setState(newState);
|
||||
onChange(newState);
|
||||
},
|
||||
[value, state, onChange],
|
||||
);
|
||||
|
||||
const contextValue = useMemo(
|
||||
() => ({ value, defaultValue, toggleValue }),
|
||||
[value, defaultValue, toggleValue],
|
||||
);
|
||||
value === undefined && setState(newState);
|
||||
onChange(newState);
|
||||
};
|
||||
|
||||
return (
|
||||
<CheckboxGroupContext.Provider value={contextValue}>
|
||||
<CheckboxGroupContext.Provider
|
||||
value={{
|
||||
value,
|
||||
defaultValue,
|
||||
toggleValue,
|
||||
}}
|
||||
>
|
||||
<Fieldset
|
||||
{...rest}
|
||||
ref={ref}
|
||||
|
||||
+28
-8
@@ -18,7 +18,7 @@ import {
|
||||
import { ComboboxTrigger } from "./trigger/ComboboxTrigger";
|
||||
|
||||
const meta: Meta<typeof ComboboxSingle> = {
|
||||
title: "ds-react/Combobox2",
|
||||
title: "ds-react/Combobox",
|
||||
component: ComboboxSingle,
|
||||
parameters: {
|
||||
chromatic: { disable: true },
|
||||
@@ -61,7 +61,7 @@ type MyGroup = {
|
||||
options: MyOption[];
|
||||
};
|
||||
|
||||
const groupedCountries: (MyGroup | MyOption)[] = [
|
||||
const groupedCountries: MyGroup[] = [
|
||||
{
|
||||
label: "Norden",
|
||||
id: "group-1",
|
||||
@@ -72,11 +72,10 @@ const groupedCountries: (MyGroup | MyOption)[] = [
|
||||
id: "group-2",
|
||||
options: centralEuropeanCountries,
|
||||
},
|
||||
{ label: "Annet (ikke gruppert)", value: "opt-01" } satisfies MyOption,
|
||||
];
|
||||
|
||||
type DefaultProps = Pick<
|
||||
ComboboxSingle.Props<MyOption>,
|
||||
ComboboxSingle.Props<MyOption[]>,
|
||||
| "label"
|
||||
| "description"
|
||||
| "hideLabel"
|
||||
@@ -89,7 +88,11 @@ type DefaultProps = Pick<
|
||||
>;
|
||||
|
||||
export const Default: StoryFn<DefaultProps> = (props) => {
|
||||
return <ComboboxSingle options={countries} {...props} />;
|
||||
return (
|
||||
<div style={{ minHeight: "300px" }}>
|
||||
<ComboboxSingle options={countries} {...props} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
Default.args = {
|
||||
label: "Velg land",
|
||||
@@ -115,13 +118,29 @@ export const Multiselect = () => {
|
||||
};
|
||||
Multiselect.storyName = "Multiselect (WIP)";
|
||||
|
||||
export const MultiselectControlled = () => {
|
||||
const [value, setValue] = useState<MyOption["value"][]>(["opt-1"]);
|
||||
return (
|
||||
<ComboboxMulti
|
||||
label="Velg land"
|
||||
options={countries}
|
||||
value={value}
|
||||
onChange={setValue}
|
||||
onToggleOption={(option, isSelected) => {
|
||||
console.log("onToggleOption", option, isSelected);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
MultiselectControlled.storyName = "Multiselect controlled (WIP)";
|
||||
|
||||
function BasicCombobox<
|
||||
T extends ComboboxOptionData | ComboboxGroupData<ComboboxOptionData> =
|
||||
MyOption,
|
||||
T extends ComboboxOptionData[] | ComboboxGroupData<ComboboxOptionData>[] =
|
||||
MyOption[],
|
||||
>(props: Partial<ComboboxSingle.Props<T>>) {
|
||||
return (
|
||||
<ComboboxSingle
|
||||
options={countries as T[]}
|
||||
options={countries as T}
|
||||
defaultValue="opt-1"
|
||||
label="Velg land"
|
||||
description="Landet hvor du er født."
|
||||
@@ -272,6 +291,7 @@ export const Composition = () => {
|
||||
: [...prev, option.value],
|
||||
);
|
||||
},
|
||||
multiple: true,
|
||||
};
|
||||
|
||||
return (
|
||||
+4
-3
@@ -12,7 +12,7 @@ import {
|
||||
} from "./root/ComboboxRoot";
|
||||
|
||||
const meta: Meta<typeof ComboboxRoot> = {
|
||||
title: "ds-react/Combobox2/Tests",
|
||||
title: "ds-react/Combobox/Tests",
|
||||
component: ComboboxRoot,
|
||||
parameters: {
|
||||
chromatic: { disable: true },
|
||||
@@ -58,13 +58,13 @@ const groupedOptions = [
|
||||
];
|
||||
|
||||
function BaseCombobox<
|
||||
T extends ComboboxOptionData | ComboboxGroupData<ComboboxOptionData>,
|
||||
T extends ComboboxOptionData[] | ComboboxGroupData<ComboboxOptionData>[],
|
||||
>(props: Partial<ComboboxSingle.Props<T>>) {
|
||||
const [value, setValue] = useState<string | null>("opt-1");
|
||||
|
||||
return (
|
||||
<ComboboxSingle
|
||||
options={countries as T[]}
|
||||
options={countries as T}
|
||||
value={value}
|
||||
onChange={setValue}
|
||||
label="Velg land"
|
||||
@@ -126,6 +126,7 @@ export const OptionMemoization = () => {
|
||||
</div>
|
||||
<ComboboxRoot
|
||||
defaultOpen
|
||||
multiple
|
||||
options={groupedOptions}
|
||||
value={value}
|
||||
onToggleOption={(option) => {
|
||||
+22
-14
@@ -19,9 +19,16 @@ import { ComboboxRoot } from "./root/ComboboxRoot";
|
||||
import { ComboboxTrigger } from "./trigger/ComboboxTrigger";
|
||||
|
||||
interface ComboboxProps<
|
||||
T extends ComboboxOptionData | ComboboxGroupData<ComboboxOptionData>,
|
||||
T extends ComboboxOptionData[] | ComboboxGroupData<ComboboxOptionData>[],
|
||||
>
|
||||
extends Omit<ComboboxRootProps<T>, "children">, Omit<FormFieldProps, "size"> {
|
||||
extends
|
||||
Omit<ComboboxRootProps<T[number]>, "children" | "options">,
|
||||
Omit<FormFieldProps, "size"> {
|
||||
/**
|
||||
* Can be either an array of options ({@link ComboboxOptionData})
|
||||
* or an array of groups ({@link ComboboxGroupData}) containing options.
|
||||
*/
|
||||
options: T;
|
||||
/**
|
||||
* Label
|
||||
*/
|
||||
@@ -37,7 +44,7 @@ interface ComboboxProps<
|
||||
}
|
||||
|
||||
const Combobox = forwardRef(
|
||||
<T extends ComboboxOptionData | ComboboxGroupData<ComboboxOptionData>>(
|
||||
<T extends ComboboxOptionData[] | ComboboxGroupData<ComboboxOptionData>[]>(
|
||||
{
|
||||
label,
|
||||
hideLabel,
|
||||
@@ -92,7 +99,7 @@ const Combobox = forwardRef(
|
||||
{!!description && (
|
||||
<BodyShort
|
||||
className={cl(
|
||||
"aksel-form-field__description aksel-combobox2__description",
|
||||
"aksel-form-field__description aksel-combo-box__description",
|
||||
{ "aksel-sr-only": hideLabel },
|
||||
)}
|
||||
id={inputDescriptionId}
|
||||
@@ -106,7 +113,7 @@ const Combobox = forwardRef(
|
||||
<ComboboxField ref={ref} hasError={hasError} />
|
||||
</ComboboxTrigger>
|
||||
<div
|
||||
className="aksel-form-field__error aksel-combobox2__error"
|
||||
className="aksel-form-field__error aksel-combo-box__error"
|
||||
id={errorId}
|
||||
aria-relevant="additions removals"
|
||||
aria-live="polite"
|
||||
@@ -141,15 +148,16 @@ const Combobox = forwardRef(
|
||||
</ComboboxRoot>
|
||||
);
|
||||
},
|
||||
) as <T extends ComboboxOptionData | ComboboxGroupData<ComboboxOptionData>>(
|
||||
) as <T extends ComboboxOptionData[] | ComboboxGroupData<ComboboxOptionData>[]>(
|
||||
props: ComboboxProps<T> & React.RefAttributes<HTMLButtonElement>,
|
||||
) => React.ReactElement;
|
||||
|
||||
// ----------- ComboboxSingle ----------- //
|
||||
|
||||
interface ComboboxSingleProps<
|
||||
T extends ComboboxOptionData | ComboboxGroupData<ComboboxOptionData>,
|
||||
T extends ComboboxOptionData[] | ComboboxGroupData<ComboboxOptionData>[],
|
||||
> extends Omit<ComboboxProps<T>, "multiple" | "value" | "onToggleOption"> {
|
||||
// TODO: Vurder å eksponere onToggleOption
|
||||
/**
|
||||
* Called when selected option changes.
|
||||
*/
|
||||
@@ -184,7 +192,7 @@ interface ComboboxSingleProps<
|
||||
* ```
|
||||
*/
|
||||
const ComboboxSingle = forwardRef(
|
||||
<T extends ComboboxOptionData | ComboboxGroupData<ComboboxOptionData>>(
|
||||
<T extends ComboboxOptionData[] | ComboboxGroupData<ComboboxOptionData>[]>(
|
||||
{ onChange, value, defaultValue, ...rest }: ComboboxSingleProps<T>,
|
||||
ref: React.ForwardedRef<HTMLButtonElement>,
|
||||
) => {
|
||||
@@ -199,7 +207,7 @@ const ComboboxSingle = forwardRef(
|
||||
isSelected,
|
||||
) => {
|
||||
setLocalValue(isSelected ? option.value : null);
|
||||
}; // TODO: Dumt at ikke får hele option-objektet... Legge til i onChange? Hvis vi tilbyr onToggle så blir det så likt onChange...
|
||||
};
|
||||
|
||||
return (
|
||||
<Combobox
|
||||
@@ -212,21 +220,21 @@ const ComboboxSingle = forwardRef(
|
||||
/>
|
||||
);
|
||||
},
|
||||
) as <T extends ComboboxOptionData | ComboboxGroupData<ComboboxOptionData>>(
|
||||
) as <T extends ComboboxOptionData[] | ComboboxGroupData<ComboboxOptionData>[]>(
|
||||
props: ComboboxSingleProps<T> & React.RefAttributes<HTMLButtonElement>,
|
||||
) => React.ReactElement;
|
||||
|
||||
// oxlint-disable-next-line typescript/no-namespace
|
||||
export namespace ComboboxSingle {
|
||||
export type Props<
|
||||
T extends ComboboxOptionData | ComboboxGroupData<ComboboxOptionData>,
|
||||
T extends ComboboxOptionData[] | ComboboxGroupData<ComboboxOptionData>[],
|
||||
> = ComboboxSingleProps<T>;
|
||||
}
|
||||
|
||||
// ----------- ComboboxMulti ----------- //
|
||||
|
||||
interface ComboboxMultiProps<
|
||||
T extends ComboboxOptionData | ComboboxGroupData<ComboboxOptionData>,
|
||||
T extends ComboboxOptionData[] | ComboboxGroupData<ComboboxOptionData>[],
|
||||
>
|
||||
extends
|
||||
Omit<ComboboxProps<T>, "multiple" | "value" | "onToggleOption">,
|
||||
@@ -246,7 +254,7 @@ interface ComboboxMultiProps<
|
||||
}
|
||||
|
||||
function ComboboxMulti<
|
||||
T extends ComboboxOptionData | ComboboxGroupData<ComboboxOptionData>,
|
||||
T extends ComboboxOptionData[] | ComboboxGroupData<ComboboxOptionData>[],
|
||||
>({
|
||||
onChange,
|
||||
value,
|
||||
@@ -286,7 +294,7 @@ function ComboboxMulti<
|
||||
// oxlint-disable-next-line typescript/no-namespace
|
||||
export namespace ComboboxMulti {
|
||||
export type Props<
|
||||
T extends ComboboxOptionData | ComboboxGroupData<ComboboxOptionData>,
|
||||
T extends ComboboxOptionData[] | ComboboxGroupData<ComboboxOptionData>[],
|
||||
> = ComboboxMultiProps<T>;
|
||||
}
|
||||
|
||||
+3
-3
@@ -35,13 +35,13 @@ const ComboboxField = forwardRef<HTMLButtonElement, ComboboxFieldProps>(
|
||||
}, [label]);
|
||||
|
||||
return (
|
||||
<div className="aksel-combobox2__field-container">
|
||||
<div className="aksel-combo-box__field-container">
|
||||
<button
|
||||
type="button"
|
||||
ref={ref}
|
||||
data-error={hasError}
|
||||
className={cl(
|
||||
"aksel-combobox2__field-btn",
|
||||
"aksel-combo-box__field-btn",
|
||||
"aksel-body-short",
|
||||
`aksel-body-short--${size ?? "medium"}`,
|
||||
)}
|
||||
@@ -51,7 +51,7 @@ const ComboboxField = forwardRef<HTMLButtonElement, ComboboxFieldProps>(
|
||||
{label}
|
||||
</button>
|
||||
<ChevronDownIcon
|
||||
className="aksel-combobox2__field-chevron"
|
||||
className="aksel-combo-box__field-chevron"
|
||||
aria-hidden
|
||||
/>
|
||||
</div>
|
||||
+2
-2
@@ -21,7 +21,7 @@ export const ComboboxFilter = (props: ComboboxFilterProps) => {
|
||||
} = useComboboxPopupContext();
|
||||
|
||||
return (
|
||||
<div className="aksel-combobox2__filter">
|
||||
<div className="aksel-combo-box__filter">
|
||||
<Listbox.InputSlot virtuallyFocusedOptionId={virtuallyFocusedOptionValue}>
|
||||
<Search
|
||||
value={filterString}
|
||||
@@ -38,7 +38,7 @@ export const ComboboxFilter = (props: ComboboxFilterProps) => {
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
if (["ArrowLeft", "ArrowRight"].includes(event.key)) {
|
||||
setVirtuallyFocusedOptionValue("");
|
||||
setVirtuallyFocusedOptionValue(""); // Assume you want to edit the input, so remove virtual focus
|
||||
}
|
||||
}}
|
||||
aria-autocomplete="list"
|
||||
File renamed without changes.
+1
-1
@@ -23,7 +23,7 @@ const ComboboxLabel = ({
|
||||
return (
|
||||
<Label
|
||||
className={cl(
|
||||
"aksel-form-field__label aksel-combobox2__label",
|
||||
"aksel-form-field__label aksel-combo-box__label",
|
||||
className,
|
||||
{ "aksel-sr-only": hide },
|
||||
)}
|
||||
+50
-42
@@ -1,6 +1,6 @@
|
||||
import React, { useCallback } from "react";
|
||||
import React, { useRef } from "react";
|
||||
import { Listbox } from "../../../utils/components/Listbox/root/ListboxRoot";
|
||||
import { useDeferredValue, useEventCallback } from "../../../utils/hooks";
|
||||
import { useDeferredValue } from "../../../utils/hooks";
|
||||
import { useI18n } from "../../../utils/i18n/i18n.hooks";
|
||||
import { ComboboxGroup } from "../group/ComboboxGroup";
|
||||
import { ComboboxOption } from "../option/ComboboxOption";
|
||||
@@ -34,40 +34,47 @@ function ComboboxList<
|
||||
});
|
||||
}, []);*/
|
||||
|
||||
const liveRegionRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
return (
|
||||
<Listbox.Options className="aksel-combobox2__list">
|
||||
{/*isPending && (
|
||||
<div className="aksel-combobox2__loading" role="status">
|
||||
<>
|
||||
<Listbox.Options className="aksel-combo-box__list">
|
||||
{/*isPending && (
|
||||
<div className="aksel-combo-box__loading" role="status">
|
||||
Laster...
|
||||
</div>
|
||||
)*/}
|
||||
<ComboboxListContent<T>>{children}</ComboboxListContent>
|
||||
</Listbox.Options>
|
||||
<ComboboxListContent<T> liveRegionRef={liveRegionRef}>
|
||||
{children}
|
||||
</ComboboxListContent>
|
||||
</Listbox.Options>
|
||||
<div ref={liveRegionRef} className="aksel-sr-only" role="status" />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
interface ComboboxListContentProps<
|
||||
T extends ComboboxOptionData | ComboboxGroupData<ComboboxOptionData>,
|
||||
> extends ComboboxListProps<T> {
|
||||
liveRegionRef: React.RefObject<HTMLDivElement | null>;
|
||||
}
|
||||
|
||||
function ComboboxListContent<
|
||||
T extends ComboboxOptionData | ComboboxGroupData<ComboboxOptionData>,
|
||||
>({ children }: ComboboxListProps<T>) {
|
||||
>({ children, liveRegionRef }: ComboboxListContentProps<T>) {
|
||||
const { virtuallyFocusedOptionValue, filterString } =
|
||||
useComboboxPopupContext();
|
||||
const { setOpen, options, value, onToggleOption, multiple, triggerRef } =
|
||||
useComboboxRootContext();
|
||||
const memoizedOnToggleOption = useEventCallback(onToggleOption);
|
||||
const {
|
||||
options,
|
||||
value, // Selected options
|
||||
onToggleOption,
|
||||
} = useComboboxRootContext();
|
||||
const deferredFilterString = useDeferredValue(filterString);
|
||||
const maybeAnnouceHits = useHitsAnnouncer(deferredFilterString);
|
||||
const translate = useI18n("Combobox2");
|
||||
|
||||
const localOnToggleOption = useCallback(
|
||||
(option: ComboboxOptionData, isSelected: boolean) => {
|
||||
memoizedOnToggleOption(option, isSelected);
|
||||
if (!multiple) {
|
||||
setOpen(false);
|
||||
triggerRef.current?.focus();
|
||||
}
|
||||
},
|
||||
[memoizedOnToggleOption, multiple, triggerRef, setOpen],
|
||||
const maybeAnnouceHits = useHitsAnnouncer(
|
||||
deferredFilterString,
|
||||
liveRegionRef,
|
||||
);
|
||||
const translate = useI18n("Combobox2");
|
||||
|
||||
if (children && typeof children !== "function") {
|
||||
return children;
|
||||
@@ -82,7 +89,7 @@ function ComboboxListContent<
|
||||
if (filteredOptions.length === 0) {
|
||||
// TODO: Consider moving outside of role=listbox
|
||||
return (
|
||||
<div className="aksel-combobox2__no-results">{translate("noHits")}</div>
|
||||
<div className="aksel-combo-box__no-results">{translate("noHits")}</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -97,7 +104,7 @@ function ComboboxListContent<
|
||||
<ComboboxOption
|
||||
key={option.value}
|
||||
option={option}
|
||||
onToggleOption={localOnToggleOption}
|
||||
onToggleOption={onToggleOption}
|
||||
isSelected={value.includes(option.value)}
|
||||
hasVirtualFocus={virtuallyFocusedOptionValue === option.value}
|
||||
highlightText={deferredFilterString}
|
||||
@@ -110,7 +117,7 @@ function ComboboxListContent<
|
||||
<ComboboxOption
|
||||
key={optOrGroup.value}
|
||||
option={optOrGroup}
|
||||
onToggleOption={localOnToggleOption}
|
||||
onToggleOption={onToggleOption}
|
||||
isSelected={value.includes(optOrGroup.value)}
|
||||
hasVirtualFocus={virtuallyFocusedOptionValue === optOrGroup.value}
|
||||
highlightText={deferredFilterString} // TODO: Vurder å kunne slå av dette for bedre ytelse
|
||||
@@ -126,26 +133,27 @@ function filterOptions<T extends ComboboxOptionData>(
|
||||
filterString: string,
|
||||
): (T | ComboboxGroupData<T>)[] {
|
||||
const filterStringLowerCase = filterString.toLocaleLowerCase();
|
||||
const results: (T | ComboboxGroupData<T>)[] = [];
|
||||
|
||||
return options
|
||||
.map((optOrGroup) => {
|
||||
if ("options" in optOrGroup) {
|
||||
const matchingOptions = optOrGroup.options.filter((option) =>
|
||||
option.label.toLocaleLowerCase().includes(filterStringLowerCase),
|
||||
);
|
||||
if (matchingOptions.length > 0) {
|
||||
return { ...optOrGroup, options: matchingOptions };
|
||||
for (const optOrGroup of options) {
|
||||
if ("options" in optOrGroup) {
|
||||
const matchingOptions: T[] = [];
|
||||
for (const option of optOrGroup.options) {
|
||||
if (option.label.toLocaleLowerCase().includes(filterStringLowerCase)) {
|
||||
matchingOptions.push(option);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (
|
||||
optOrGroup.label.toLocaleLowerCase().includes(filterStringLowerCase)
|
||||
) {
|
||||
return optOrGroup;
|
||||
if (matchingOptions.length > 0) {
|
||||
results.push({ ...optOrGroup, options: matchingOptions });
|
||||
}
|
||||
return null;
|
||||
})
|
||||
.filter((option): option is T | ComboboxGroupData<T> => option !== null);
|
||||
} else if (
|
||||
optOrGroup.label.toLocaleLowerCase().includes(filterStringLowerCase)
|
||||
) {
|
||||
results.push(optOrGroup);
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
export type { ComboboxListProps };
|
||||
+3
-3
@@ -46,9 +46,9 @@ let regions: {
|
||||
function createRegion(politeness: Politeness) {
|
||||
const el = document.createElement("div");
|
||||
el.dataset.akselAnnouncer = "";
|
||||
el.className = "aksel-sr-only";
|
||||
el.className = "aksel-sr-only"; // TODO: Bruk inline style fra FocusGuards.tsx
|
||||
el.role = politeness === "assertive" ? "alert" : "status";
|
||||
document.body.appendChild(el);
|
||||
document.body.appendChild(el); // TODO Bruk root fra Provider (se Portal.tsx)
|
||||
return el;
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ function announce(message: string, politeness: Politeness = "polite") {
|
||||
}
|
||||
|
||||
/**
|
||||
* Speaks a message through a persistently-mounted, visually-hidden live region.
|
||||
* Announces a message through a persistently-mounted, visually-hidden live region.
|
||||
*
|
||||
* The polite and assertive regions are created once and kept mounted.
|
||||
*
|
||||
+24
-4
@@ -1,11 +1,11 @@
|
||||
import { useEffect, useMemo, useRef } from "react";
|
||||
import { useCallback, useEffect, useMemo, useRef } from "react";
|
||||
import { debounce } from "../../../utils-external";
|
||||
import { useTimeout } from "../../../utils/hooks";
|
||||
import { useI18n } from "../../../utils/i18n/i18n.hooks";
|
||||
import type {
|
||||
ComboboxGroupData,
|
||||
ComboboxOptionData,
|
||||
} from "../root/ComboboxRoot";
|
||||
import { useAnnounce } from "./useAnnounce";
|
||||
|
||||
function getNumberOfOptions<T extends ComboboxOptionData>(
|
||||
options: (T | ComboboxGroupData<T>)[],
|
||||
@@ -18,10 +18,30 @@ function getNumberOfOptions<T extends ComboboxOptionData>(
|
||||
}, 0);
|
||||
}
|
||||
|
||||
function useHitsAnnouncer(deferredFilterString: string) {
|
||||
function useHitsAnnouncer(
|
||||
deferredFilterString: string,
|
||||
liveRegionRef: React.RefObject<HTMLDivElement | null>,
|
||||
) {
|
||||
const translate = useI18n("Combobox2");
|
||||
const oldFilterStringRef = useRef(deferredFilterString);
|
||||
const announce = useAnnounce();
|
||||
const timeout = useTimeout();
|
||||
|
||||
const announce = useCallback(
|
||||
(message: string) => {
|
||||
if (!liveRegionRef.current) {
|
||||
return;
|
||||
}
|
||||
const target = liveRegionRef.current;
|
||||
// If the message is the same as the current text,
|
||||
// append a non-breaking space to force a re-announcement.
|
||||
target.textContent =
|
||||
message === target.textContent ? `${message} ` : message; // eslint-disable-line no-irregular-whitespace
|
||||
timeout.start(2000, () => {
|
||||
target.textContent = "";
|
||||
});
|
||||
},
|
||||
[liveRegionRef, timeout],
|
||||
);
|
||||
|
||||
const announceHits = useMemo(() => {
|
||||
return debounce((count: number) => {
|
||||
+3
-6
@@ -26,19 +26,16 @@ function ComboboxOptionComponent<T extends ComboboxOptionData>({
|
||||
|
||||
return (
|
||||
<Listbox.Option
|
||||
className="aksel-combobox2__option"
|
||||
className="aksel-combo-box__option"
|
||||
id={option.value}
|
||||
onClick={() => onToggleOption(option, !isSelected)}
|
||||
aria-selected={isSelected}
|
||||
hasVirtualFocus={hasVirtualFocus}
|
||||
>
|
||||
<div className="aksel-combobox2__option-checkmark" aria-hidden>
|
||||
<div className="aksel-combo-box__option-checkmark" aria-hidden>
|
||||
{isSelected && <CheckmarkHeavyIcon aria-hidden />}
|
||||
</div>
|
||||
<div
|
||||
className="aksel-combobox2__option-label"
|
||||
//data-nowrap={!children || typeof children === "string"}
|
||||
>
|
||||
<div className="aksel-combo-box__option-label">
|
||||
{typeof children === "function"
|
||||
? children(option)
|
||||
: (children ??
|
||||
File renamed without changes.
File renamed without changes.
+37
-29
@@ -1,4 +1,4 @@
|
||||
import React, { useEffect } from "react";
|
||||
import React, { useEffect, useRef } from "react";
|
||||
import { Dialog } from "../../../dialog";
|
||||
import { DismissableLayer } from "../../../utils/components/dismissablelayer/DismissableLayer";
|
||||
import {
|
||||
@@ -19,16 +19,7 @@ function ComboboxOverlay({ children, mobileHeader }: ComboboxOverlayProps) {
|
||||
|
||||
if (isMobile) {
|
||||
return (
|
||||
<ComboboxModal
|
||||
open={rootContext.open}
|
||||
onOpenChange={(open) => {
|
||||
rootContext.setOpen(open);
|
||||
!open && rootContext.triggerRef.current?.focus(); // This does not work when closing with button
|
||||
}}
|
||||
onOpenChangeComplete={(open) =>
|
||||
!open && rootContext.triggerRef.current?.focus()
|
||||
}
|
||||
>
|
||||
<ComboboxModal open={rootContext.open} onOpenChange={rootContext.setOpen}>
|
||||
{mobileHeader}
|
||||
{children}
|
||||
</ComboboxModal>
|
||||
@@ -42,20 +33,22 @@ function ComboboxOverlay({ children, mobileHeader }: ComboboxOverlayProps) {
|
||||
return (
|
||||
<DismissableLayer
|
||||
asChild
|
||||
//safeZone={{ anchor: rootContext.triggerRef.current }}
|
||||
onDismiss={(event) => {
|
||||
// We don't have trigger as `safeZone` because we want to close when trigger is focused.
|
||||
// To avoid immediately re-opening the popup when trigger is clicked (blur closes, click opens),
|
||||
// we avoid closing here if the click is on the trigger. The trigger will handle closing in that case.
|
||||
// (A connected <label> also acts like a trigger.)
|
||||
const trigger = rootContext.triggerRef.current;
|
||||
if (
|
||||
event.type === "AKSEL_POINTER_DOWN_OUTSIDE" &&
|
||||
event.target instanceof HTMLElement &&
|
||||
rootContext.triggerRef.current?.contains(event.target)
|
||||
(trigger?.contains(event.target) ||
|
||||
(event.target instanceof HTMLLabelElement &&
|
||||
document.getElementById(event.target.htmlFor) === trigger))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
rootContext.setOpen(false);
|
||||
rootContext.triggerRef.current?.focus();
|
||||
}}
|
||||
enabled={rootContext.open}
|
||||
>
|
||||
@@ -77,7 +70,6 @@ type ComboboxModalProps = {
|
||||
children: React.ReactNode;
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
onOpenChangeComplete: (open: boolean) => void;
|
||||
};
|
||||
|
||||
function subscribeToResize(callback: () => void) {
|
||||
@@ -89,16 +81,13 @@ function getVisualViewportHeight() {
|
||||
return visualViewport?.height; // Takes into account virtual keyboard etc.
|
||||
}
|
||||
|
||||
function ComboboxModal({
|
||||
children,
|
||||
open,
|
||||
onOpenChange,
|
||||
onOpenChangeComplete,
|
||||
}: ComboboxModalProps) {
|
||||
function ComboboxModal({ children, open, onOpenChange }: ComboboxModalProps) {
|
||||
const visualViewportHeight = useSyncExternalStore(
|
||||
subscribeToResize,
|
||||
getVisualViewportHeight,
|
||||
);
|
||||
const ref = useRef<HTMLDivElement | null>(null);
|
||||
const scrollOnResizeRef = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
// See "Overlay" section in CSS file for context. This handles the case when
|
||||
@@ -111,16 +100,35 @@ function ComboboxModal({
|
||||
}
|
||||
}, [open]);
|
||||
|
||||
/**
|
||||
* Scroll to first selected option after virtual keyboard has appeared.
|
||||
* See also useClientLayoutEffect in ComboboxPopup.
|
||||
*/
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
scrollOnResizeRef.current = true;
|
||||
setTimeout(() => {
|
||||
scrollOnResizeRef.current = false;
|
||||
}, 500); // We assume visual viewport stabilizes within 500ms
|
||||
}
|
||||
}, [open]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!ref.current || !open || !scrollOnResizeRef.current) {
|
||||
return;
|
||||
}
|
||||
const selectedOptionElm = ref.current?.querySelector<HTMLElement>(
|
||||
'[aria-selected="true"]',
|
||||
);
|
||||
selectedOptionElm?.scrollIntoView({ block: "center" }); // Don't use "nearest" (inconsistent)
|
||||
}, [visualViewportHeight, open]);
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
size="small"
|
||||
open={open}
|
||||
onOpenChange={onOpenChange}
|
||||
onOpenChangeComplete={onOpenChangeComplete}
|
||||
>
|
||||
<Dialog.Popup className="aksel-combobox2__modal" position="fullscreen">
|
||||
<Dialog size="small" open={open} onOpenChange={onOpenChange}>
|
||||
<Dialog.Popup className="aksel-combo-box__modal" position="fullscreen">
|
||||
<div
|
||||
className="aksel-combobox2__modal-inner"
|
||||
ref={ref}
|
||||
className="aksel-combo-box__modal-inner"
|
||||
// The reported height is sometimes a bit too small,
|
||||
// so we let the dialog fill the entire normal viewport,
|
||||
// and only limit the inner content's height.
|
||||
+81
-37
@@ -6,10 +6,15 @@ import { BodyShort } from "../../../typography";
|
||||
import { ComboboxFilter } from "../filter/ComboboxFilter";
|
||||
import { ComboboxList } from "../list/ComboboxList";
|
||||
import { ComboboxPopup } from "../popup/ComboboxPopup";
|
||||
import { ComboboxRoot } from "../root/ComboboxRoot";
|
||||
import {
|
||||
type ComboboxGroupData,
|
||||
type ComboboxOptionData,
|
||||
ComboboxRoot,
|
||||
type ComboboxRootProps,
|
||||
} from "../root/ComboboxRoot";
|
||||
|
||||
const meta: Meta<typeof ComboboxRoot> = {
|
||||
title: "ds-react/Combobox2/Popup",
|
||||
title: "ds-react/Combobox/Popup",
|
||||
component: ComboboxRoot,
|
||||
parameters: {
|
||||
chromatic: { disable: true },
|
||||
@@ -56,12 +61,17 @@ const groupedOptions: (MyGroup | MyOption)[] = [
|
||||
{ label: "Ikke gruppert", value: "opt-01" } satisfies MyOption,
|
||||
];
|
||||
|
||||
export const Default = () => {
|
||||
type DefaultProps = Pick<
|
||||
ComboboxRootProps<MyOption>,
|
||||
"size" | "id" | "disabled"
|
||||
>;
|
||||
export const Default: StoryFn<DefaultProps> = (props) => {
|
||||
const [value, setValue] = useState<MyOption["value"][]>(["opt-3"]);
|
||||
|
||||
return (
|
||||
<ComboboxRoot
|
||||
defaultOpen
|
||||
multiple
|
||||
options={options}
|
||||
value={value}
|
||||
onToggleOption={(option, newSelected) => {
|
||||
@@ -71,6 +81,7 @@ export const Default = () => {
|
||||
: prev.filter((v) => v !== option.value),
|
||||
);
|
||||
}}
|
||||
{...props}
|
||||
>
|
||||
<ComboboxPopup>
|
||||
<ComboboxFilter />
|
||||
@@ -79,54 +90,85 @@ export const Default = () => {
|
||||
</ComboboxRoot>
|
||||
);
|
||||
};
|
||||
Default.args = {
|
||||
disabled: false,
|
||||
};
|
||||
Default.argTypes = {
|
||||
size: {
|
||||
control: { type: "select" },
|
||||
options: ["small", "medium"],
|
||||
},
|
||||
id: {
|
||||
control: { type: "text" },
|
||||
},
|
||||
};
|
||||
|
||||
function BasicComboboxPopup<
|
||||
T extends ComboboxOptionData | ComboboxGroupData<ComboboxOptionData> =
|
||||
MyOption,
|
||||
>(props: Partial<ComboboxRootProps<T>>) {
|
||||
const [value, setValue] = useState(["opt-3"]);
|
||||
|
||||
return (
|
||||
<ComboboxRoot
|
||||
defaultOpen
|
||||
multiple
|
||||
options={options as T[]}
|
||||
value={value}
|
||||
onToggleOption={(option, newSelected) => {
|
||||
setValue((prev) =>
|
||||
newSelected
|
||||
? [...prev, option.value]
|
||||
: prev.filter((v) => v !== option.value),
|
||||
);
|
||||
}}
|
||||
{...props}
|
||||
>
|
||||
<ComboboxPopup>
|
||||
<ComboboxFilter />
|
||||
<ComboboxList />
|
||||
</ComboboxPopup>
|
||||
</ComboboxRoot>
|
||||
);
|
||||
}
|
||||
|
||||
export const SingleSelect = () => {
|
||||
const [selectedOption, setSelectedOption] = useState<MyOption>(options[2]);
|
||||
|
||||
return (
|
||||
<ComboboxRoot
|
||||
defaultOpen
|
||||
<BasicComboboxPopup
|
||||
multiple={false}
|
||||
options={options}
|
||||
value={[selectedOption.value]}
|
||||
onToggleOption={setSelectedOption}
|
||||
>
|
||||
<ComboboxPopup>
|
||||
<ComboboxFilter />
|
||||
<ComboboxList />
|
||||
</ComboboxPopup>
|
||||
</ComboboxRoot>
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export const Disabled = () => {
|
||||
// TODO: Support disabled
|
||||
const [disabled, setDisabled] = useState(true);
|
||||
return (
|
||||
<>
|
||||
<BasicComboboxPopup disabled={disabled} />
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => document.querySelector("input")?.focus()}
|
||||
>
|
||||
Fokuser input
|
||||
</button>
|
||||
<button type="button" onClick={() => setDisabled(!disabled)}>
|
||||
Toggle disabled
|
||||
</button>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export const Groups = () => {
|
||||
const [selectedOption, setSelectedOption] = useState<MyOption>(options[2]);
|
||||
|
||||
return (
|
||||
<HStack gap="space-56">
|
||||
<ComboboxRoot
|
||||
defaultOpen
|
||||
options={groupedOptions}
|
||||
value={[selectedOption.value]}
|
||||
onToggleOption={setSelectedOption}
|
||||
>
|
||||
<ComboboxPopup>
|
||||
<ComboboxFilter />
|
||||
<ComboboxList />
|
||||
</ComboboxPopup>
|
||||
</ComboboxRoot>
|
||||
|
||||
<ComboboxRoot
|
||||
size="small"
|
||||
defaultOpen
|
||||
options={groupedOptions}
|
||||
value={[selectedOption.value]}
|
||||
onToggleOption={setSelectedOption}
|
||||
>
|
||||
<ComboboxPopup>
|
||||
<ComboboxFilter />
|
||||
<ComboboxList />
|
||||
</ComboboxPopup>
|
||||
</ComboboxRoot>
|
||||
<BasicComboboxPopup options={groupedOptions} />
|
||||
<BasicComboboxPopup options={groupedOptions} size="small" />
|
||||
</HStack>
|
||||
);
|
||||
};
|
||||
@@ -173,6 +215,7 @@ export const CustomOptionRendering = () => {
|
||||
return (
|
||||
<ComboboxRoot
|
||||
defaultOpen
|
||||
multiple
|
||||
options={options}
|
||||
value={value}
|
||||
onToggleOption={(option, isSelected) => {
|
||||
@@ -259,6 +302,7 @@ export const ControlledInput = () => {
|
||||
return (
|
||||
<ComboboxRoot
|
||||
defaultOpen
|
||||
multiple
|
||||
options={filteredOptions}
|
||||
value={value}
|
||||
onToggleOption={(option) => {
|
||||
+5
-5
@@ -34,7 +34,7 @@ export const ComboboxPopup = ({ children }: ComboboxPopupProps) => {
|
||||
function onOpen() {
|
||||
const canHover = window.matchMedia("(hover: hover)").matches;
|
||||
|
||||
// Virtually focus and scroll to first (selected) option
|
||||
// Virtually focus (and scroll to) first (selected) option
|
||||
const selectedOptionElm = ref.current?.querySelector<HTMLElement>(
|
||||
'[aria-selected="true"]',
|
||||
);
|
||||
@@ -44,8 +44,8 @@ export const ComboboxPopup = ({ children }: ComboboxPopupProps) => {
|
||||
}
|
||||
const scrollToSelectedOption = () =>
|
||||
selectedOptionElm.scrollIntoView({ block: "nearest" });
|
||||
setTimeout(scrollToSelectedOption, 0); // For when opened in Floating
|
||||
queueMicrotask(scrollToSelectedOption); // For when opened in Dialog
|
||||
setTimeout(scrollToSelectedOption, 0); // Need a small delay to make it work in Floating
|
||||
// See also ComboboxOverlay (special logic to account for virtual keyboard on mobile)
|
||||
} else {
|
||||
const firstOptionElm =
|
||||
ref.current?.querySelector<HTMLElement>('[role="option"]');
|
||||
@@ -76,7 +76,7 @@ export const ComboboxPopup = ({ children }: ComboboxPopupProps) => {
|
||||
return (
|
||||
<Listbox
|
||||
ref={ref}
|
||||
className="aksel-combobox2__popup"
|
||||
className="aksel-combo-box__popup"
|
||||
setVirtuallyFocusedOptionId={setVirtuallyFocusedOptionValue}
|
||||
size={rootContext.size}
|
||||
>
|
||||
@@ -86,7 +86,7 @@ export const ComboboxPopup = ({ children }: ComboboxPopupProps) => {
|
||||
filterString={filterString}
|
||||
setFilterString={(newString) => {
|
||||
setFilterString(newString);
|
||||
setVirtuallyFocusedOptionValue("");
|
||||
setVirtuallyFocusedOptionValue(""); // Remove virtual focus when filter string changes
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
+29
-12
@@ -1,6 +1,7 @@
|
||||
import React, { useRef, useState } from "react";
|
||||
import React, { useCallback, useRef, useState } from "react";
|
||||
import { Floating } from "../../../utils/components/floating/Floating";
|
||||
import { cl, createStrictContext } from "../../../utils/helpers";
|
||||
import { useEventCallback } from "../../../utils/hooks";
|
||||
import type { FormFieldProps } from "../../useFormField";
|
||||
import type { ComboboxOptionProps } from "../option/ComboboxOption";
|
||||
|
||||
@@ -74,9 +75,8 @@ export interface ComboboxRootProps<
|
||||
defaultOpen?: boolean;
|
||||
/**
|
||||
* Whether multiple options can be selected.
|
||||
* @default true
|
||||
*/
|
||||
multiple?: boolean; // TODO: Hva skal være default?
|
||||
multiple?: boolean;
|
||||
}
|
||||
|
||||
export interface ComboboxRootContextProps {
|
||||
@@ -84,9 +84,10 @@ export interface ComboboxRootContextProps {
|
||||
setOpen: (newOpen: boolean) => void;
|
||||
triggerRef: React.RefObject<HTMLDivElement | null>;
|
||||
options: ComboboxRootProps["options"];
|
||||
/** Values of selected options */
|
||||
value: ComboboxRootProps["value"];
|
||||
/** Consumer callback */
|
||||
onToggleOption: ComboboxRootProps["onToggleOption"];
|
||||
multiple: boolean;
|
||||
size: Exclude<ComboboxRootProps["size"], undefined>;
|
||||
disabled: ComboboxRootProps["disabled"];
|
||||
}
|
||||
@@ -105,34 +106,50 @@ export function ComboboxRoot<
|
||||
children,
|
||||
options,
|
||||
value,
|
||||
onToggleOption,
|
||||
onToggleOption: originalOnToggleOption,
|
||||
defaultOpen = false,
|
||||
multiple = true,
|
||||
multiple = false,
|
||||
size = "medium",
|
||||
disabled,
|
||||
className,
|
||||
...rest
|
||||
}: ComboboxRootProps<T>) {
|
||||
const triggerRef = useRef<HTMLDivElement | null>(null);
|
||||
const onToggleOption = useEventCallback(originalOnToggleOption);
|
||||
const [open, setOpen] = useState(defaultOpen);
|
||||
|
||||
return (
|
||||
<div
|
||||
{...rest}
|
||||
className={cl("aksel-combobox2", className)}
|
||||
className={cl("aksel-combo-box", className)}
|
||||
data-size={size}
|
||||
data-disabled={disabled}
|
||||
>
|
||||
<ComboboxRootContextProvider
|
||||
open={open}
|
||||
setOpen={setOpen}
|
||||
setOpen={useCallback((newOpen) => {
|
||||
setOpen(newOpen);
|
||||
if (!newOpen) {
|
||||
// queueMicrotask is needed when closing with close button in Dialog
|
||||
queueMicrotask(() => triggerRef.current?.focus());
|
||||
}
|
||||
}, [])}
|
||||
triggerRef={triggerRef}
|
||||
options={options}
|
||||
value={value}
|
||||
onToggleOption={
|
||||
onToggleOption as ComboboxRootContextProps["onToggleOption"]
|
||||
}
|
||||
multiple={multiple}
|
||||
onToggleOption={useCallback(
|
||||
(...args) => {
|
||||
if (disabled) {
|
||||
return;
|
||||
}
|
||||
(onToggleOption as ComboboxRootProps["onToggleOption"])(...args);
|
||||
if (!multiple) {
|
||||
setOpen(false);
|
||||
triggerRef.current?.focus();
|
||||
}
|
||||
},
|
||||
[onToggleOption, multiple, disabled],
|
||||
)}
|
||||
size={size}
|
||||
disabled={disabled}
|
||||
>
|
||||
File renamed without changes.
@@ -2,7 +2,7 @@ import type { Meta, StoryObj } from "@storybook/react-vite";
|
||||
import React, { useRef } from "react";
|
||||
import { expect, userEvent, within } from "storybook/test";
|
||||
import { VStack } from "../../primitives/stack";
|
||||
import { ErrorSummary } from "./ErrorSummary";
|
||||
import { ErrorSummary } from "./root/ErrorSummaryRoot";
|
||||
|
||||
export default {
|
||||
title: "ds-react/ErrorSummary",
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
"use client";
|
||||
export {
|
||||
default as ErrorSummary,
|
||||
type ErrorSummaryProps,
|
||||
} from "./ErrorSummary";
|
||||
export {
|
||||
default as ErrorSummaryItem,
|
||||
type ErrorSummaryItemProps,
|
||||
} from "./ErrorSummaryItem";
|
||||
export { ErrorSummary, ErrorSummaryItem } from "./root/ErrorSummaryRoot";
|
||||
export type {
|
||||
ErrorSummaryItemProps,
|
||||
ErrorSummaryProps,
|
||||
} from "./root/ErrorSummaryRoot";
|
||||
+6
-5
@@ -1,8 +1,8 @@
|
||||
import React, { forwardRef } from "react";
|
||||
import type { OverridableComponent } from "../../utils-external";
|
||||
import { cl } from "../../utils/helpers";
|
||||
import type { OverridableComponent } from "../../../utils-external";
|
||||
import { cl } from "../../../utils/helpers";
|
||||
|
||||
export interface ErrorSummaryItemProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
|
||||
interface ErrorSummaryItemProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
|
||||
/**
|
||||
* Link text
|
||||
*/
|
||||
@@ -18,7 +18,7 @@ type ErrorSummaryItemType = OverridableComponent<
|
||||
HTMLAnchorElement
|
||||
>;
|
||||
|
||||
export const ErrorSummaryItem: ErrorSummaryItemType = forwardRef(
|
||||
const ErrorSummaryItem: ErrorSummaryItemType = forwardRef(
|
||||
({ children, as: Component = "a", className, ...rest }, ref) => {
|
||||
return (
|
||||
<li>
|
||||
@@ -34,4 +34,5 @@ export const ErrorSummaryItem: ErrorSummaryItemType = forwardRef(
|
||||
},
|
||||
);
|
||||
|
||||
export default ErrorSummaryItem;
|
||||
export { ErrorSummaryItem };
|
||||
export type { ErrorSummaryItemProps };
|
||||
+46
-46
@@ -1,11 +1,14 @@
|
||||
import React, { type HTMLAttributes, forwardRef, useRef } from "react";
|
||||
import { BodyShort, Heading } from "../../typography";
|
||||
import { cl, composeEventHandlers } from "../../utils/helpers";
|
||||
import { useMergeRefs } from "../../utils/hooks";
|
||||
import { useI18n } from "../../utils/i18n/i18n.hooks";
|
||||
import ErrorSummaryItem from "./ErrorSummaryItem";
|
||||
import { BodyShort, Heading } from "../../../typography";
|
||||
import { cl, composeEventHandlers } from "../../../utils/helpers";
|
||||
import { useMergeRefs } from "../../../utils/hooks";
|
||||
import { useI18n } from "../../../utils/i18n/i18n.hooks";
|
||||
import {
|
||||
ErrorSummaryItem,
|
||||
type ErrorSummaryItemProps,
|
||||
} from "../item/ErrorSummaryItem";
|
||||
|
||||
export interface ErrorSummaryProps extends Omit<
|
||||
interface ErrorSummaryProps extends Omit<
|
||||
HTMLAttributes<HTMLDivElement>,
|
||||
"tabIndex"
|
||||
> {
|
||||
@@ -30,43 +33,7 @@ export interface ErrorSummaryProps extends Omit<
|
||||
headingTag?: React.ElementType<any>;
|
||||
}
|
||||
|
||||
interface ErrorSummaryComponent extends React.ForwardRefExoticComponent<
|
||||
ErrorSummaryProps & React.RefAttributes<HTMLDivElement>
|
||||
> {
|
||||
/**
|
||||
* Error message with link to field.
|
||||
*
|
||||
* @see [🤖 OverridableComponent](https://aksel.nav.no/grunnleggende/kode/overridablecomponent) support
|
||||
*
|
||||
* @example
|
||||
* ```jsx
|
||||
* <ErrorSummary.Item href="#id-til-alderfelt">
|
||||
* Felt må fylles ut med alder
|
||||
* </ErrorSummary.Item>
|
||||
* ```
|
||||
*/
|
||||
Item: typeof ErrorSummaryItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Summary of errors in a form.
|
||||
*
|
||||
* @see [📝 Documentation](https://aksel.nav.no/komponenter/core/errorsummary)
|
||||
* @see 🏷️ {@link ErrorSummaryProps}
|
||||
*
|
||||
* @example
|
||||
* ```jsx
|
||||
* <ErrorSummary heading="Du må rette disse feilene før du kan sende inn søknaden:">
|
||||
* <ErrorSummary.Item href="#1">
|
||||
* Felt må fylles ut med alder
|
||||
* </ErrorSummary.Item>
|
||||
* <ErrorSummary.Item href="#2">
|
||||
* Tekstfeltet må ha en godkjent e-post
|
||||
* </ErrorSummary.Item>
|
||||
* </ErrorSummary>
|
||||
* ```
|
||||
*/
|
||||
export const ErrorSummary = forwardRef<HTMLDivElement, ErrorSummaryProps>(
|
||||
const ErrorSummaryRoot = forwardRef<HTMLDivElement, ErrorSummaryProps>(
|
||||
(
|
||||
{
|
||||
children,
|
||||
@@ -115,8 +82,41 @@ export const ErrorSummary = forwardRef<HTMLDivElement, ErrorSummaryProps>(
|
||||
</div>
|
||||
);
|
||||
},
|
||||
) as ErrorSummaryComponent;
|
||||
);
|
||||
|
||||
ErrorSummary.Item = ErrorSummaryItem;
|
||||
/**
|
||||
* Summary of errors in a form.
|
||||
*
|
||||
* @see [📝 Documentation](https://aksel.nav.no/komponenter/core/errorsummary)
|
||||
* @see 🏷️ {@link ErrorSummaryProps}
|
||||
*
|
||||
* @example
|
||||
* ```jsx
|
||||
* <ErrorSummary heading="Du må rette disse feilene før du kan sende inn søknaden:">
|
||||
* <ErrorSummary.Item href="#1">
|
||||
* Felt må fylles ut med alder
|
||||
* </ErrorSummary.Item>
|
||||
* <ErrorSummary.Item href="#2">
|
||||
* Tekstfeltet må ha en godkjent e-post
|
||||
* </ErrorSummary.Item>
|
||||
* </ErrorSummary>
|
||||
* ```
|
||||
*/
|
||||
const ErrorSummary = Object.assign(ErrorSummaryRoot, {
|
||||
/**
|
||||
* Error message with link to field.
|
||||
*
|
||||
* @see [🤖 OverridableComponent](https://aksel.nav.no/grunnleggende/kode/overridablecomponent) support
|
||||
*
|
||||
* @example
|
||||
* ```jsx
|
||||
* <ErrorSummary.Item href="#id-til-alderfelt">
|
||||
* Felt må fylles ut med alder
|
||||
* </ErrorSummary.Item>
|
||||
* ```
|
||||
*/
|
||||
Item: ErrorSummaryItem,
|
||||
});
|
||||
|
||||
export default ErrorSummary;
|
||||
export { ErrorSummary, ErrorSummaryItem };
|
||||
export type { ErrorSummaryProps, ErrorSummaryItemProps };
|
||||
@@ -2,7 +2,6 @@ import React, {
|
||||
type FieldsetHTMLAttributes,
|
||||
forwardRef,
|
||||
useContext,
|
||||
useMemo,
|
||||
} from "react";
|
||||
import { BodyShort, ErrorMessage, Label } from "../../typography";
|
||||
import { omit, useId } from "../../utils-external";
|
||||
@@ -77,27 +76,21 @@ export const Fieldset = forwardRef<HTMLFieldSetElement, FieldsetProps>(
|
||||
...rest
|
||||
} = props;
|
||||
|
||||
const contextError = errorPropagation
|
||||
? (props.error ?? fieldset?.error)
|
||||
: undefined;
|
||||
const contextErrorId = cl({
|
||||
[errorId]: showErrorMsg,
|
||||
[fieldset?.errorId ?? ""]: !!fieldset?.error,
|
||||
});
|
||||
|
||||
const contextValue = useMemo(
|
||||
() => ({
|
||||
error: contextError,
|
||||
errorId: contextErrorId,
|
||||
size,
|
||||
disabled,
|
||||
readOnly,
|
||||
}),
|
||||
[contextError, contextErrorId, size, disabled, readOnly],
|
||||
);
|
||||
|
||||
return (
|
||||
<FieldsetContext.Provider value={contextValue}>
|
||||
<FieldsetContext.Provider
|
||||
value={{
|
||||
error: errorPropagation
|
||||
? (props.error ?? fieldset?.error)
|
||||
: undefined,
|
||||
errorId: cl({
|
||||
[errorId]: showErrorMsg,
|
||||
[fieldset?.errorId ?? ""]: !!fieldset?.error,
|
||||
}),
|
||||
size,
|
||||
disabled,
|
||||
readOnly,
|
||||
}}
|
||||
>
|
||||
<fieldset
|
||||
{...omit(rest, ["errorId", "error", "size", "readOnly"])}
|
||||
{...inputProps}
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
export const fileRejectionReason = {
|
||||
const fileRejectionReason = {
|
||||
FileType: "fileType" as const,
|
||||
FileSize: "fileSize" as const,
|
||||
};
|
||||
|
||||
export type FileRejectionReason =
|
||||
type FileRejectionReason =
|
||||
(typeof fileRejectionReason)[keyof typeof fileRejectionReason];
|
||||
|
||||
export type FileRejected = {
|
||||
type FileRejected = {
|
||||
file: File;
|
||||
error: true;
|
||||
reasons: string[];
|
||||
};
|
||||
export type FileAccepted = { file: File; error: false };
|
||||
type FileAccepted = { file: File; error: false };
|
||||
|
||||
export type FileObject = FileRejected | FileAccepted;
|
||||
export type FileRejectedPartitioned = {
|
||||
type FileObject = FileRejected | FileAccepted;
|
||||
type FileRejectedPartitioned = {
|
||||
file: File;
|
||||
reasons: string[];
|
||||
};
|
||||
export type FilesPartitioned = {
|
||||
type FilesPartitioned = {
|
||||
accepted: File[];
|
||||
rejected: FileRejectedPartitioned[];
|
||||
};
|
||||
|
||||
export interface FileUploadBaseProps {
|
||||
interface FileUploadBaseProps {
|
||||
/**
|
||||
* Indicates if it is possible to select multiple files at once.
|
||||
* @default true
|
||||
@@ -55,3 +55,14 @@ export interface FileUploadBaseProps {
|
||||
current: number;
|
||||
};
|
||||
}
|
||||
|
||||
export { fileRejectionReason };
|
||||
export type {
|
||||
FileRejectionReason,
|
||||
FileRejected,
|
||||
FileAccepted,
|
||||
FileObject,
|
||||
FileRejectedPartitioned,
|
||||
FilesPartitioned,
|
||||
FileUploadBaseProps,
|
||||
};
|
||||
@@ -6,9 +6,9 @@ import { omit, useId } from "../../../utils-external";
|
||||
import { cl, composeEventHandlers } from "../../../utils/helpers";
|
||||
import { useI18n } from "../../../utils/i18n/i18n.hooks";
|
||||
import { useFormField } from "../../useFormField";
|
||||
import { useFileUpload } from "../hooks/useFileUpload";
|
||||
import { useFileUploadTranslation } from "../root/FileUploadRoot.context";
|
||||
import type { FileUploadDropzoneProps } from "./dropzone.types";
|
||||
import { useFileUpload } from "../root/useFileUpload";
|
||||
import type { FileUploadDropzoneProps } from "./FileUploadDropzone.types";
|
||||
import { useDropzone } from "./useDropzone";
|
||||
|
||||
const FileUploadDropzone = forwardRef<
|
||||
@@ -175,6 +175,5 @@ const FileUploadDropzone = forwardRef<
|
||||
);
|
||||
});
|
||||
|
||||
export default FileUploadDropzone;
|
||||
export { FileUploadDropzone };
|
||||
export type { FileUploadDropzoneProps };
|
||||
+3
-1
@@ -2,7 +2,7 @@ import type { ComponentTranslation } from "../../../utils/i18n/i18n.types";
|
||||
import type { FormFieldProps } from "../../useFormField";
|
||||
import type { FileUploadBaseProps } from "../FileUpload.types";
|
||||
|
||||
export interface FileUploadDropzoneProps
|
||||
interface FileUploadDropzoneProps
|
||||
extends
|
||||
FileUploadBaseProps,
|
||||
Omit<FormFieldProps, "size" | "readOnly">,
|
||||
@@ -24,3 +24,5 @@ export interface FileUploadDropzoneProps
|
||||
*/
|
||||
translations?: ComponentTranslation<"FileUpload">["dropzone"];
|
||||
}
|
||||
|
||||
export type { FileUploadDropzoneProps };
|
||||
@@ -1,12 +1,12 @@
|
||||
import { useState } from "react";
|
||||
import type { UseFileUploadProps } from "../hooks/useFileUpload";
|
||||
import type { UseFileUploadProps } from "../root/useFileUpload";
|
||||
|
||||
interface Props {
|
||||
upload: (fileList: FileList) => void;
|
||||
disabled: UseFileUploadProps["disabled"];
|
||||
}
|
||||
|
||||
export const useDropzone = ({ upload, disabled }: Props) => {
|
||||
const useDropzone = ({ upload, disabled }: Props) => {
|
||||
const [isDraggingOver, setIsDraggingOver] = useState(false);
|
||||
|
||||
const onDragEnter = () => {
|
||||
@@ -41,3 +41,5 @@ export const useDropzone = ({ upload, disabled }: Props) => {
|
||||
onDrop: disabled ? undefined : onDrop,
|
||||
};
|
||||
};
|
||||
|
||||
export { useDropzone };
|
||||
@@ -1,4 +1,4 @@
|
||||
export const downloadFile = (file: File): void => {
|
||||
const downloadFile = (file: File): void => {
|
||||
const a = document.createElement("a");
|
||||
const url = URL.createObjectURL(file);
|
||||
a.href = url;
|
||||
@@ -7,3 +7,5 @@ export const downloadFile = (file: File): void => {
|
||||
|
||||
URL.revokeObjectURL(url);
|
||||
};
|
||||
|
||||
export { downloadFile };
|
||||
@@ -1,4 +1,6 @@
|
||||
import type { FileItem } from "../item/FileUploadItem.types";
|
||||
|
||||
export const isNativeFile = (fileItem: FileItem): fileItem is File =>
|
||||
const isNativeFile = (fileItem: FileItem): fileItem is File =>
|
||||
"lastModified" in fileItem;
|
||||
|
||||
export { isNativeFile };
|
||||
@@ -2,7 +2,7 @@ import type { FileItem } from "../item/FileUploadItem.types";
|
||||
|
||||
const MAX_MEGA_BYTES = 500;
|
||||
|
||||
export function formatFileSize(file: FileItem): string | null {
|
||||
function formatFileSize(file: FileItem): string | null {
|
||||
if (!file.size) {
|
||||
return null;
|
||||
}
|
||||
@@ -23,3 +23,5 @@ const formatter = new Intl.NumberFormat("nb-NO", {
|
||||
// @ts-expect-error - Looks like roundingMode hasn't been added to TypeScript yet
|
||||
roundingMode: "ceil",
|
||||
});
|
||||
|
||||
export { formatFileSize };
|
||||
@@ -1,7 +1,4 @@
|
||||
export function isAcceptedFileType(
|
||||
file: File,
|
||||
accept: string | undefined,
|
||||
): boolean {
|
||||
function isAcceptedFileType(file: File, accept: string | undefined): boolean {
|
||||
if (!accept) {
|
||||
return true;
|
||||
}
|
||||
@@ -26,3 +23,5 @@ export function isAcceptedFileType(
|
||||
return mimeType === validType;
|
||||
});
|
||||
}
|
||||
|
||||
export { isAcceptedFileType };
|
||||
@@ -1,7 +1,9 @@
|
||||
export function isAcceptedSize(file: File, maxSize: number = -1): boolean {
|
||||
function isAcceptedSize(file: File, maxSize: number = -1): boolean {
|
||||
if (maxSize <= 0 || file.size <= maxSize) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export { isAcceptedSize };
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
import { isAcceptedFileType } from "./is-accepted-file-type";
|
||||
import { isAcceptedSize } from "./is-accepted-size";
|
||||
|
||||
export const validateFiles = (
|
||||
const validateFiles = (
|
||||
files: File[],
|
||||
accept?: string,
|
||||
validator?: FileUploadBaseProps["validator"],
|
||||
@@ -60,3 +60,5 @@ export const validateFiles = (
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export { validateFiles };
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
export {
|
||||
default as FileUpload,
|
||||
FileUpload,
|
||||
FileUploadTrigger,
|
||||
FileUploadDropzone,
|
||||
FileUploadItem,
|
||||
|
||||
+4
-4
@@ -5,7 +5,7 @@ import { Loader } from "../../../loader";
|
||||
import { Spacer } from "../../../primitives/stack";
|
||||
import type { TFunction } from "../../../utils/i18n/i18n.types";
|
||||
|
||||
interface ItemActionFieldProps {
|
||||
interface FileUploadItemActionFieldInternalProps {
|
||||
isLoading: boolean;
|
||||
button?:
|
||||
| {
|
||||
@@ -17,11 +17,11 @@ interface ItemActionFieldProps {
|
||||
translate: TFunction<"FileUpload">;
|
||||
}
|
||||
|
||||
function ItemActionField({
|
||||
function FileUploadItemActionFieldInternal({
|
||||
isLoading,
|
||||
button,
|
||||
translate,
|
||||
}: ItemActionFieldProps) {
|
||||
}: FileUploadItemActionFieldInternalProps) {
|
||||
if (isLoading) {
|
||||
return (
|
||||
<>
|
||||
@@ -83,4 +83,4 @@ function isCustomButton(
|
||||
return React.isValidElement(button);
|
||||
}
|
||||
|
||||
export { ItemActionField };
|
||||
export { FileUploadItemActionFieldInternal };
|
||||
+8
-8
@@ -3,7 +3,7 @@ import { useThemeInternal } from "../../../theme/Theme";
|
||||
import { LinkAnchor } from "../../../utils/components/link-anchor";
|
||||
import { downloadFile } from "../helpers/download-file";
|
||||
import { isNativeFile } from "../helpers/file-type-checker";
|
||||
import ItemIcon from "../item-icon/ItemIcon";
|
||||
import { FileUploadItemIconInternal } from "../item-icon/FileUploadItemIconInternal";
|
||||
import type { FileItem } from "../item/FileUploadItem.types";
|
||||
|
||||
interface Props {
|
||||
@@ -12,7 +12,7 @@ interface Props {
|
||||
onClick?: (event: React.MouseEvent<HTMLAnchorElement>) => void;
|
||||
}
|
||||
|
||||
const ItemHeader = ({ file, href, onClick }: Props) => {
|
||||
const FileUploadItemHeaderInternal = ({ file, href, onClick }: Props) => {
|
||||
const ctx = useThemeInternal();
|
||||
|
||||
if (onClick && href) {
|
||||
@@ -23,7 +23,7 @@ const ItemHeader = ({ file, href, onClick }: Props) => {
|
||||
className="aksel-file-item__link"
|
||||
data-color={ctx.color}
|
||||
>
|
||||
<ItemIcon file={file} />
|
||||
<FileUploadItemIconInternal file={file} />
|
||||
{file.name}
|
||||
</LinkAnchor>
|
||||
);
|
||||
@@ -40,7 +40,7 @@ const ItemHeader = ({ file, href, onClick }: Props) => {
|
||||
className="aksel-file-item__link"
|
||||
data-color={ctx.color}
|
||||
>
|
||||
<ItemIcon file={file} />
|
||||
<FileUploadItemIconInternal file={file} />
|
||||
{file.name}
|
||||
</LinkAnchor>
|
||||
);
|
||||
@@ -53,7 +53,7 @@ const ItemHeader = ({ file, href, onClick }: Props) => {
|
||||
className="aksel-file-item__link"
|
||||
data-color={ctx.color}
|
||||
>
|
||||
<ItemIcon file={file} />
|
||||
<FileUploadItemIconInternal file={file} />
|
||||
{file.name}
|
||||
</LinkAnchor>
|
||||
);
|
||||
@@ -71,7 +71,7 @@ const ItemHeader = ({ file, href, onClick }: Props) => {
|
||||
className="aksel-file-item__link"
|
||||
data-color={ctx.color}
|
||||
>
|
||||
<ItemIcon file={file} />
|
||||
<FileUploadItemIconInternal file={file} />
|
||||
{file.name}
|
||||
</LinkAnchor>
|
||||
);
|
||||
@@ -79,10 +79,10 @@ const ItemHeader = ({ file, href, onClick }: Props) => {
|
||||
|
||||
return (
|
||||
<span className="aksel-file-item__link">
|
||||
<ItemIcon file={file} />
|
||||
<FileUploadItemIconInternal file={file} />
|
||||
{file.name}
|
||||
</span>
|
||||
);
|
||||
};
|
||||
|
||||
export { ItemHeader };
|
||||
export { FileUploadItemHeaderInternal };
|
||||
+2
-2
@@ -19,7 +19,7 @@ const iconProps = {
|
||||
"aria-hidden": true,
|
||||
};
|
||||
|
||||
function ItemIcon({ file }: ItemIconProps) {
|
||||
function FileUploadItemIconInternal({ file }: ItemIconProps) {
|
||||
return (
|
||||
<div className="aksel-file-item__icon">
|
||||
<Icon file={file} />
|
||||
@@ -54,4 +54,4 @@ function Icon({ file }: { file: FileItem }) {
|
||||
}
|
||||
}
|
||||
|
||||
export default ItemIcon;
|
||||
export { FileUploadItemIconInternal };
|
||||
@@ -5,8 +5,8 @@ import { cl } from "../../../utils/helpers";
|
||||
import { useI18n } from "../../../utils/i18n/i18n.hooks";
|
||||
import type { ComponentTranslation } from "../../../utils/i18n/i18n.types";
|
||||
import { formatFileSize } from "../helpers/format-file-size";
|
||||
import { ItemActionField } from "../item-action-field/ItemActionField";
|
||||
import { ItemHeader } from "../item-header/ItemHeader";
|
||||
import { FileUploadItemActionFieldInternal } from "../item-action-field/FileUploadItemActionFieldInternal";
|
||||
import { FileUploadItemHeaderInternal } from "../item-header/FileUploadItemHeaderInternal";
|
||||
import { useFileUploadTranslation } from "../root/FileUploadRoot.context";
|
||||
import type { FileItem } from "./FileUploadItem.types";
|
||||
|
||||
@@ -62,7 +62,7 @@ interface FileUploadItemProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||
translations?: ComponentTranslation<"FileUpload">["item"];
|
||||
}
|
||||
|
||||
export const FileUploadItem: OverridableComponent<
|
||||
const FileUploadItem: OverridableComponent<
|
||||
FileUploadItemProps,
|
||||
HTMLDivElement
|
||||
> = forwardRef(
|
||||
@@ -111,7 +111,11 @@ export const FileUploadItem: OverridableComponent<
|
||||
>
|
||||
<div className="aksel-file-item__inner">
|
||||
<BodyLong as="div" className="aksel-file-item__file-info">
|
||||
<ItemHeader file={file} href={href} onClick={onFileClick} />
|
||||
<FileUploadItemHeaderInternal
|
||||
file={file}
|
||||
href={href}
|
||||
onClick={onFileClick}
|
||||
/>
|
||||
<BodyShort as="div" size="small">
|
||||
{getStatusText()}
|
||||
</BodyShort>
|
||||
@@ -127,7 +131,7 @@ export const FileUploadItem: OverridableComponent<
|
||||
)}
|
||||
</div>
|
||||
</BodyLong>
|
||||
<ItemActionField
|
||||
<FileUploadItemActionFieldInternal
|
||||
isLoading={status !== "idle"}
|
||||
button={button}
|
||||
translate={translate}
|
||||
@@ -138,5 +142,5 @@ export const FileUploadItem: OverridableComponent<
|
||||
},
|
||||
);
|
||||
|
||||
export default FileUploadItem;
|
||||
export { FileUploadItem };
|
||||
export type { FileUploadItemProps };
|
||||
@@ -1,6 +1,8 @@
|
||||
export interface FileMetadata {
|
||||
interface FileMetadata {
|
||||
name: string;
|
||||
size?: number;
|
||||
}
|
||||
|
||||
export type FileItem = FileMetadata | File;
|
||||
type FileItem = FileMetadata | File;
|
||||
|
||||
export type { FileItem, FileMetadata };
|
||||
+5
-2
@@ -1,13 +1,16 @@
|
||||
import { createStrictContext } from "../../../utils/helpers";
|
||||
import type { ComponentTranslation } from "../../../utils/i18n/i18n.types";
|
||||
|
||||
export type FileUploadLocaleContextProps = {
|
||||
type FileUploadLocaleContextProps = {
|
||||
translations?: ComponentTranslation<"FileUpload">;
|
||||
};
|
||||
|
||||
export const {
|
||||
const {
|
||||
Provider: FileUploadLocaleContextProvider,
|
||||
useContext: useFileUploadTranslation,
|
||||
} = createStrictContext<FileUploadLocaleContextProps>({
|
||||
name: "FileUploadLocaleContext",
|
||||
});
|
||||
|
||||
export { FileUploadLocaleContextProvider, useFileUploadTranslation };
|
||||
export type { FileUploadLocaleContextProps };
|
||||
@@ -26,9 +26,36 @@ interface FileUploadProps extends HTMLAttributes<HTMLDivElement> {
|
||||
translations?: ComponentTranslation<"FileUpload">;
|
||||
}
|
||||
|
||||
interface FileUploadComponent extends React.ForwardRefExoticComponent<
|
||||
FileUploadProps & React.RefAttributes<HTMLDivElement>
|
||||
> {
|
||||
const FileUploadRoot = forwardRef<HTMLDivElement, FileUploadProps>(
|
||||
({ children, className, translations, ...rest }: FileUploadProps, ref) => {
|
||||
return (
|
||||
<FileUploadLocaleContextProvider translations={translations}>
|
||||
<div ref={ref} {...rest} className={cl("aksel-file-upload", className)}>
|
||||
{children}
|
||||
</div>
|
||||
</FileUploadLocaleContextProvider>
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* A set of components used to upload and display files.
|
||||
* @see [📝 Documentation](https://aksel.nav.no/komponenter/core/fileupload)
|
||||
* @example Dropzone
|
||||
* ```jsx
|
||||
* <FileUpload.Dropzone />
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* Items
|
||||
* ```jsx
|
||||
* <VStack gap="space-16" as="ul">
|
||||
* <FileUpload.Item as="li" file={myFile} />
|
||||
* <FileUpload.Item as="li" file={mySecondFile} />
|
||||
* </VStack>
|
||||
* ```
|
||||
*/
|
||||
const FileUpload = Object.assign(FileUploadRoot, {
|
||||
/**
|
||||
* Framed area to drag-n-drop files, upload files with button-click or copy-paste.
|
||||
* @see 🏷️ {@link FileUploadDropzoneProps}
|
||||
@@ -62,7 +89,7 @@ interface FileUploadComponent extends React.ForwardRefExoticComponent<
|
||||
* />
|
||||
* ```
|
||||
*/
|
||||
Dropzone: typeof FileUploadDropzone;
|
||||
Dropzone: FileUploadDropzone,
|
||||
|
||||
/**
|
||||
* Displays a file with status, file size, action and error message.
|
||||
@@ -106,7 +133,7 @@ interface FileUploadComponent extends React.ForwardRefExoticComponent<
|
||||
* <FileUpload.Item file={file} button={{ action:"delete", onClick:... }} />
|
||||
* ```
|
||||
*/
|
||||
Item: typeof FileUploadItem;
|
||||
Item: FileUploadItem,
|
||||
/**
|
||||
* Wrapper for a button to trigger file select.
|
||||
* @see 🏷️ {@link FileUploadTriggerProps}
|
||||
@@ -117,46 +144,12 @@ interface FileUploadComponent extends React.ForwardRefExoticComponent<
|
||||
* </FileUpload.Trigger>
|
||||
* ```
|
||||
*/
|
||||
Trigger: typeof FileUploadTrigger;
|
||||
}
|
||||
Trigger: FileUploadTrigger,
|
||||
});
|
||||
|
||||
/**
|
||||
* A set of components used to upload and display files.
|
||||
* @see [📝 Documentation](https://aksel.nav.no/komponenter/core/fileupload)
|
||||
* @example Dropzone
|
||||
* ```jsx
|
||||
* <FileUpload.Dropzone />
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* Items
|
||||
* ```jsx
|
||||
* <VStack gap="space-16" as="ul">
|
||||
* <FileUpload.Item as="li" file={myFile} />
|
||||
* <FileUpload.Item as="li" file={mySecondFile} />
|
||||
* </VStack>
|
||||
* ```
|
||||
*/
|
||||
export const FileUpload = forwardRef<HTMLDivElement, FileUploadProps>(
|
||||
({ children, className, translations, ...rest }: FileUploadProps, ref) => {
|
||||
return (
|
||||
<FileUploadLocaleContextProvider translations={translations}>
|
||||
<div ref={ref} {...rest} className={cl("aksel-file-upload", className)}>
|
||||
{children}
|
||||
</div>
|
||||
</FileUploadLocaleContextProvider>
|
||||
);
|
||||
},
|
||||
) as FileUploadComponent;
|
||||
|
||||
FileUpload.Dropzone = FileUploadDropzone;
|
||||
FileUpload.Item = FileUploadItem;
|
||||
FileUpload.Trigger = FileUploadTrigger;
|
||||
|
||||
export default FileUpload;
|
||||
|
||||
export { FileUploadTrigger, FileUploadDropzone, FileUploadItem };
|
||||
export { FileUpload, FileUploadTrigger, FileUploadDropzone, FileUploadItem };
|
||||
export type {
|
||||
FileUploadProps,
|
||||
FileUploadTriggerProps,
|
||||
FileUploadDropzoneProps,
|
||||
FileUploadItemProps,
|
||||
|
||||
+5
-5
@@ -3,15 +3,12 @@ import { useMergeRefs } from "../../../utils/hooks";
|
||||
import type { FileUploadBaseProps } from "../FileUpload.types";
|
||||
import { validateFiles } from "../helpers/validate-files";
|
||||
|
||||
export interface UseFileUploadProps extends Omit<
|
||||
FileUploadBaseProps,
|
||||
"fileLimit"
|
||||
> {
|
||||
interface UseFileUploadProps extends Omit<FileUploadBaseProps, "fileLimit"> {
|
||||
ref: React.ForwardedRef<HTMLInputElement>;
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
export const useFileUpload = ({
|
||||
const useFileUpload = ({
|
||||
ref,
|
||||
accept,
|
||||
onSelect,
|
||||
@@ -54,3 +51,6 @@ export const useFileUpload = ({
|
||||
mergedRef,
|
||||
};
|
||||
};
|
||||
|
||||
export { useFileUpload };
|
||||
export type { UseFileUploadProps };
|
||||
@@ -1,7 +1,7 @@
|
||||
import React, { forwardRef } from "react";
|
||||
import { Slot } from "../../../utils/components/slot/Slot";
|
||||
import type { FileUploadBaseProps } from "../FileUpload.types";
|
||||
import { useFileUpload } from "../hooks/useFileUpload";
|
||||
import { useFileUpload } from "../root/useFileUpload";
|
||||
|
||||
interface FileUploadTriggerProps extends Omit<
|
||||
FileUploadBaseProps,
|
||||
@@ -47,6 +47,5 @@ const FileUploadTrigger = forwardRef<HTMLInputElement, FileUploadTriggerProps>(
|
||||
},
|
||||
);
|
||||
|
||||
export default FileUploadTrigger;
|
||||
export { FileUploadTrigger };
|
||||
export type { FileUploadTriggerProps };
|
||||
@@ -3,7 +3,7 @@ import React, { useState } from "react";
|
||||
import { Provider } from "../../provider";
|
||||
import en from "../../utils/i18n/locales/en";
|
||||
import { renderStoriesForChromatic } from "../../utils/renderStoriesForChromatic";
|
||||
import FormProgress, { type FormProgressProps } from "./FormProgress";
|
||||
import { FormProgress, type FormProgressProps } from "./index";
|
||||
|
||||
export default {
|
||||
title: "ds-react/FormProgress",
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"use client";
|
||||
export {
|
||||
default as FormProgress,
|
||||
type FormProgressProps,
|
||||
FormProgressStep,
|
||||
type FormProgressStepProps,
|
||||
} from "./FormProgress";
|
||||
export { FormProgress, FormProgressStep } from "./root/FormProgressRoot";
|
||||
export type {
|
||||
FormProgressProps,
|
||||
FormProgressStepProps,
|
||||
} from "./root/FormProgressRoot";
|
||||
+37
-39
@@ -1,15 +1,19 @@
|
||||
import React, { forwardRef } from "react";
|
||||
import { ChevronDownIcon } from "@navikt/aksel-icons";
|
||||
import { Button } from "../../button";
|
||||
import { Collapsible } from "../../collapsible";
|
||||
import { Stepper, type StepperStepProps } from "../../legacy/stepper";
|
||||
import { HStack } from "../../primitives/stack";
|
||||
import { ProgressBar } from "../../progress-bar";
|
||||
import { BodyShort } from "../../typography";
|
||||
import { useI18n } from "../../utils/i18n/i18n.hooks";
|
||||
import type { ComponentTranslation } from "../../utils/i18n/i18n.types";
|
||||
import { Button } from "../../../button";
|
||||
import { Collapsible } from "../../../collapsible";
|
||||
import { Stepper } from "../../../legacy/stepper";
|
||||
import { HStack } from "../../../primitives/stack";
|
||||
import { ProgressBar } from "../../../progress-bar";
|
||||
import { BodyShort } from "../../../typography";
|
||||
import { useI18n } from "../../../utils/i18n/i18n.hooks";
|
||||
import type { ComponentTranslation } from "../../../utils/i18n/i18n.types";
|
||||
import {
|
||||
FormProgressStep,
|
||||
type FormProgressStepProps,
|
||||
} from "../step/FormProgressStep";
|
||||
|
||||
export interface FormProgressProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||
interface FormProgressProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||
/**
|
||||
* Total number of steps.
|
||||
*/
|
||||
@@ -50,31 +54,7 @@ export interface FormProgressProps extends React.HTMLAttributes<HTMLDivElement>
|
||||
translations?: ComponentTranslation<"FormProgress">;
|
||||
}
|
||||
|
||||
export type FormProgressStepProps = StepperStepProps;
|
||||
|
||||
interface FormProgressComponent extends React.ForwardRefExoticComponent<
|
||||
FormProgressProps & React.RefAttributes<HTMLDivElement>
|
||||
> {
|
||||
/**
|
||||
* To be used inside `<FormProgress>`.
|
||||
*/
|
||||
Step: typeof Stepper.Step;
|
||||
}
|
||||
|
||||
/**
|
||||
* Component for visualizing progression in a form with multiple steps.
|
||||
*
|
||||
* @see [📝 Documentation](https://aksel.nav.no/komponenter/core/formprogress)
|
||||
* @see 🏷️ {@link FormProgressProps}
|
||||
*
|
||||
* @example
|
||||
* <FormProgress activeStep={2} totalSteps={3}>
|
||||
* <FormProgress.Step completed href="#">Children</FormProgress.Step>
|
||||
* <FormProgress.Step href="#">Personal information</FormProgress.Step>
|
||||
* <FormProgress.Step interactive={false}>Summary</FormProgress.Step>
|
||||
* </FormProgress>
|
||||
*/
|
||||
export const FormProgress = forwardRef<HTMLDivElement, FormProgressProps>(
|
||||
const FormProgressRoot = forwardRef<HTMLDivElement, FormProgressProps>(
|
||||
(
|
||||
{
|
||||
totalSteps,
|
||||
@@ -139,10 +119,28 @@ export const FormProgress = forwardRef<HTMLDivElement, FormProgressProps>(
|
||||
</div>
|
||||
);
|
||||
},
|
||||
) as FormProgressComponent;
|
||||
);
|
||||
|
||||
FormProgress.Step = Stepper.Step;
|
||||
/**
|
||||
* Component for visualizing progression in a form with multiple steps.
|
||||
*
|
||||
* @see [📝 Documentation](https://aksel.nav.no/komponenter/core/formprogress)
|
||||
* @see 🏷️ {@link FormProgressProps}
|
||||
*
|
||||
* @example
|
||||
* <FormProgress activeStep={2} totalSteps={3}>
|
||||
* <FormProgress.Step completed href="#">Children</FormProgress.Step>
|
||||
* <FormProgress.Step href="#">Personal information</FormProgress.Step>
|
||||
* <FormProgress.Step interactive={false}>Summary</FormProgress.Step>
|
||||
* </FormProgress>
|
||||
*/
|
||||
const FormProgress = Object.assign(FormProgressRoot, {
|
||||
/**
|
||||
* To be used inside `<FormProgress>`.
|
||||
* @see 🏷️ {@link FormProgressStepProps}
|
||||
*/
|
||||
Step: FormProgressStep,
|
||||
});
|
||||
|
||||
export const FormProgressStep = Stepper.Step;
|
||||
|
||||
export default FormProgress;
|
||||
export { FormProgress, FormProgressStep };
|
||||
export type { FormProgressProps, FormProgressStepProps };
|
||||
@@ -0,0 +1,8 @@
|
||||
import { Stepper, type StepperStepProps } from "../../../legacy/stepper";
|
||||
|
||||
type FormProgressStepProps = StepperStepProps;
|
||||
|
||||
const FormProgressStep = Stepper.Step;
|
||||
|
||||
export { FormProgressStep };
|
||||
export type { FormProgressStepProps };
|
||||
@@ -3,7 +3,7 @@ import React from "react";
|
||||
import { Link } from "../../link";
|
||||
import { VStack } from "../../primitives/stack";
|
||||
import { renderStoriesForChromatic } from "../../utils/renderStoriesForChromatic";
|
||||
import FormSummary from "./FormSummary";
|
||||
import { FormSummary } from "./root/FormSummaryRoot";
|
||||
|
||||
const meta: Meta<typeof FormSummary> = {
|
||||
title: "ds-react/FormSummary",
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
import React, { forwardRef } from "react";
|
||||
import { cl } from "../../utils/helpers";
|
||||
|
||||
/**
|
||||
* Footer slot for actions in `FormSummary`.
|
||||
*/
|
||||
export interface FormSummaryFooterProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||
/**
|
||||
* Should include `<FormSummary.EditLink>`.
|
||||
*/
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
export const FormSummaryFooter = forwardRef<
|
||||
HTMLDivElement,
|
||||
FormSummaryFooterProps
|
||||
>(({ children, className, ...rest }, ref) => {
|
||||
return (
|
||||
<div
|
||||
ref={ref}
|
||||
{...rest}
|
||||
className={cl("aksel-form-summary__footer", className)}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
export default FormSummaryFooter;
|
||||
@@ -1,29 +0,0 @@
|
||||
import React, { forwardRef } from "react";
|
||||
import { CompositionWarning } from "../../utils/components/composition-warning";
|
||||
import { cl } from "../../utils/helpers";
|
||||
|
||||
export interface FormSummaryHeaderProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||
/**
|
||||
* Must include `<FormSummary.Heading>`.
|
||||
*/
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
export const FormSummaryHeader = forwardRef<
|
||||
HTMLDivElement,
|
||||
FormSummaryHeaderProps
|
||||
>(({ children, className, ...rest }: FormSummaryHeaderProps, ref) => {
|
||||
return (
|
||||
<CompositionWarning.Root name="FormSummary.Header">
|
||||
<div
|
||||
ref={ref}
|
||||
{...rest}
|
||||
className={cl("aksel-form-summary__header", className)}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
</CompositionWarning.Root>
|
||||
);
|
||||
});
|
||||
|
||||
export default FormSummaryHeader;
|
||||
@@ -1,16 +0,0 @@
|
||||
import React, { forwardRef } from "react";
|
||||
import { Label } from "../../typography";
|
||||
|
||||
export interface FormSummaryLabelProps extends React.HTMLAttributes<HTMLElement> {
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
export const FormSummaryLabel = forwardRef<HTMLElement, FormSummaryLabelProps>(
|
||||
({ children, ...rest }, ref) => (
|
||||
<Label ref={ref} {...rest} as="dt">
|
||||
{children}
|
||||
</Label>
|
||||
),
|
||||
);
|
||||
|
||||
export default FormSummaryLabel;
|
||||
@@ -1,25 +0,0 @@
|
||||
import React, { forwardRef } from "react";
|
||||
import { BodyLong } from "../../typography";
|
||||
import { cl } from "../../utils/helpers";
|
||||
|
||||
export interface FormSummaryValueProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
export const FormSummaryValue = forwardRef<
|
||||
HTMLDivElement,
|
||||
FormSummaryValueProps
|
||||
>(({ children, className, ...rest }, ref) => {
|
||||
return (
|
||||
<BodyLong
|
||||
ref={ref}
|
||||
{...rest}
|
||||
as="dd"
|
||||
className={cl("aksel-form-summary__value", className)}
|
||||
>
|
||||
{children}
|
||||
</BodyLong>
|
||||
);
|
||||
});
|
||||
|
||||
export default FormSummaryValue;
|
||||
+6
-5
@@ -1,8 +1,8 @@
|
||||
import React from "react";
|
||||
import { useThemeInternal } from "../../theme/Theme";
|
||||
import { cl } from "../../utils/helpers";
|
||||
import { useThemeInternal } from "../../../theme/Theme";
|
||||
import { cl } from "../../../utils/helpers";
|
||||
|
||||
export interface FormSummaryAnswerProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||
interface FormSummaryAnswerProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||
/**
|
||||
* Must include:
|
||||
* - `<FormSummary.Label>`
|
||||
@@ -11,7 +11,7 @@ export interface FormSummaryAnswerProps extends React.HTMLAttributes<HTMLDivElem
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
export const FormSummaryAnswer = React.forwardRef<
|
||||
const FormSummaryAnswer = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
FormSummaryAnswerProps
|
||||
>(({ children, className, ...rest }, ref) => {
|
||||
@@ -29,4 +29,5 @@ export const FormSummaryAnswer = React.forwardRef<
|
||||
);
|
||||
});
|
||||
|
||||
export default FormSummaryAnswer;
|
||||
export { FormSummaryAnswer };
|
||||
export type { FormSummaryAnswerProps };
|
||||
+5
-4
@@ -1,16 +1,16 @@
|
||||
import React, { forwardRef } from "react";
|
||||
import { cl } from "../../utils/helpers";
|
||||
import { cl } from "../../../utils/helpers";
|
||||
|
||||
const FormSummaryAnswersContext = React.createContext(false);
|
||||
|
||||
export interface FormSummaryAnswersProps extends React.HTMLAttributes<HTMLDListElement> {
|
||||
interface FormSummaryAnswersProps extends React.HTMLAttributes<HTMLDListElement> {
|
||||
/**
|
||||
* Must include one or more of `<FormSummary.Answer>`.
|
||||
*/
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
export const FormSummaryAnswers = forwardRef<
|
||||
const FormSummaryAnswers = forwardRef<
|
||||
HTMLDListElement,
|
||||
FormSummaryAnswersProps
|
||||
>(({ children, className, ...rest }: FormSummaryAnswersProps, ref) => {
|
||||
@@ -30,4 +30,5 @@ export const FormSummaryAnswers = forwardRef<
|
||||
);
|
||||
});
|
||||
|
||||
export default FormSummaryAnswers;
|
||||
export { FormSummaryAnswers };
|
||||
export type { FormSummaryAnswersProps };
|
||||
+9
-8
@@ -1,12 +1,12 @@
|
||||
import React, { forwardRef } from "react";
|
||||
import { PencilIcon } from "@navikt/aksel-icons";
|
||||
import { Link } from "../../link";
|
||||
import type { OverridableComponent } from "../../utils-external";
|
||||
import { CompositionWarning } from "../../utils/components/composition-warning";
|
||||
import { cl } from "../../utils/helpers";
|
||||
import { useI18n } from "../../utils/i18n/i18n.hooks";
|
||||
import { Link } from "../../../link";
|
||||
import type { OverridableComponent } from "../../../utils-external";
|
||||
import { CompositionWarning } from "../../../utils/components/composition-warning";
|
||||
import { cl } from "../../../utils/helpers";
|
||||
import { useI18n } from "../../../utils/i18n/i18n.hooks";
|
||||
|
||||
export interface FormSummaryEditProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
|
||||
interface FormSummaryEditProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
|
||||
/**
|
||||
* URL to the relevant part of the form, where the answers can be edited.
|
||||
*/
|
||||
@@ -20,7 +20,7 @@ export interface FormSummaryEditProps extends React.AnchorHTMLAttributes<HTMLAnc
|
||||
children?: React.ReactNode;
|
||||
}
|
||||
|
||||
export const FormSummaryEditLink: OverridableComponent<
|
||||
const FormSummaryEditLink: OverridableComponent<
|
||||
FormSummaryEditProps,
|
||||
HTMLAnchorElement
|
||||
> = forwardRef(({ children, className, as = "a", ...rest }, ref) => {
|
||||
@@ -44,4 +44,5 @@ export const FormSummaryEditLink: OverridableComponent<
|
||||
);
|
||||
});
|
||||
|
||||
export default FormSummaryEditLink;
|
||||
export { FormSummaryEditLink };
|
||||
export type { FormSummaryEditProps };
|
||||
@@ -0,0 +1,29 @@
|
||||
import React, { forwardRef } from "react";
|
||||
import { cl } from "../../../utils/helpers";
|
||||
|
||||
interface FormSummaryFooterProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||
/**
|
||||
* Should include `<FormSummary.EditLink>`.
|
||||
*/
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Footer component for the form summary, if applicable this is a good place for `<FormSummary.EditLink>`.
|
||||
*/
|
||||
const FormSummaryFooter = forwardRef<HTMLDivElement, FormSummaryFooterProps>(
|
||||
({ children, className, ...rest }, ref) => {
|
||||
return (
|
||||
<div
|
||||
ref={ref}
|
||||
{...rest}
|
||||
className={cl("aksel-form-summary__footer", className)}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
export { FormSummaryFooter };
|
||||
export type { FormSummaryFooterProps };
|
||||
@@ -0,0 +1,29 @@
|
||||
import React, { forwardRef } from "react";
|
||||
import { CompositionWarning } from "../../../utils/components/composition-warning";
|
||||
import { cl } from "../../../utils/helpers";
|
||||
|
||||
interface FormSummaryHeaderProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||
/**
|
||||
* Must include `<FormSummary.Heading>`.
|
||||
*/
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
const FormSummaryHeader = forwardRef<HTMLDivElement, FormSummaryHeaderProps>(
|
||||
({ children, className, ...rest }: FormSummaryHeaderProps, ref) => {
|
||||
return (
|
||||
<CompositionWarning.Root name="FormSummary.Header">
|
||||
<div
|
||||
ref={ref}
|
||||
{...rest}
|
||||
className={cl("aksel-form-summary__header", className)}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
</CompositionWarning.Root>
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
export { FormSummaryHeader };
|
||||
export type { FormSummaryHeaderProps };
|
||||
+5
-4
@@ -1,7 +1,7 @@
|
||||
import React, { forwardRef } from "react";
|
||||
import { Heading, type HeadingProps } from "../../typography";
|
||||
import { Heading, type HeadingProps } from "../../../typography";
|
||||
|
||||
export interface FormSummaryHeadingProps extends React.HTMLAttributes<HTMLHeadingElement> {
|
||||
interface FormSummaryHeadingProps extends React.HTMLAttributes<HTMLHeadingElement> {
|
||||
/**
|
||||
* Heading text.
|
||||
*/
|
||||
@@ -12,11 +12,12 @@ export interface FormSummaryHeadingProps extends React.HTMLAttributes<HTMLHeadin
|
||||
level: Exclude<HeadingProps["level"], "1">;
|
||||
}
|
||||
|
||||
export const FormSummaryHeading = forwardRef<
|
||||
const FormSummaryHeading = forwardRef<
|
||||
HTMLHeadingElement,
|
||||
FormSummaryHeadingProps
|
||||
>((props: FormSummaryHeadingProps, ref) => (
|
||||
<Heading ref={ref} {...props} size="medium" />
|
||||
));
|
||||
|
||||
export default FormSummaryHeading;
|
||||
export { FormSummaryHeading };
|
||||
export type { FormSummaryHeadingProps };
|
||||
@@ -1,34 +1,23 @@
|
||||
"use client";
|
||||
export { default as FormSummary, type FormSummaryProps } from "./FormSummary";
|
||||
export {
|
||||
default as FormSummaryAnswer,
|
||||
type FormSummaryAnswerProps,
|
||||
} from "./FormSummaryAnswer";
|
||||
export {
|
||||
default as FormSummaryAnswers,
|
||||
type FormSummaryAnswersProps,
|
||||
} from "./FormSummaryAnswers";
|
||||
export {
|
||||
default as FormSummaryEditLink,
|
||||
type FormSummaryEditProps,
|
||||
} from "./FormSummaryEditLink";
|
||||
export {
|
||||
default as FormSummaryFooter,
|
||||
type FormSummaryFooterProps,
|
||||
} from "./FormSummaryFooter";
|
||||
export {
|
||||
default as FormSummaryHeader,
|
||||
type FormSummaryHeaderProps,
|
||||
} from "./FormSummaryHeader";
|
||||
export {
|
||||
default as FormSummaryHeading,
|
||||
type FormSummaryHeadingProps,
|
||||
} from "./FormSummaryHeading";
|
||||
export {
|
||||
default as FormSummaryLabel,
|
||||
type FormSummaryLabelProps,
|
||||
} from "./FormSummaryLabel";
|
||||
export {
|
||||
default as FormSummaryValue,
|
||||
type FormSummaryValueProps,
|
||||
} from "./FormSummaryValue";
|
||||
FormSummary,
|
||||
FormSummaryAnswer,
|
||||
FormSummaryAnswers,
|
||||
FormSummaryEditLink,
|
||||
FormSummaryFooter,
|
||||
FormSummaryHeader,
|
||||
FormSummaryHeading,
|
||||
FormSummaryLabel,
|
||||
FormSummaryValue,
|
||||
} from "./root/FormSummaryRoot";
|
||||
export type {
|
||||
FormSummaryAnswerProps,
|
||||
FormSummaryAnswersProps,
|
||||
FormSummaryEditProps,
|
||||
FormSummaryFooterProps,
|
||||
FormSummaryHeaderProps,
|
||||
FormSummaryHeadingProps,
|
||||
FormSummaryLabelProps,
|
||||
FormSummaryProps,
|
||||
FormSummaryValueProps,
|
||||
} from "./root/FormSummaryRoot";
|
||||
@@ -0,0 +1,17 @@
|
||||
import React, { forwardRef } from "react";
|
||||
import { Label } from "../../../typography";
|
||||
|
||||
interface FormSummaryLabelProps extends React.HTMLAttributes<HTMLElement> {
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
const FormSummaryLabel = forwardRef<HTMLElement, FormSummaryLabelProps>(
|
||||
({ children, ...rest }, ref) => (
|
||||
<Label ref={ref} {...rest} as="dt">
|
||||
{children}
|
||||
</Label>
|
||||
),
|
||||
);
|
||||
|
||||
export { FormSummaryLabel };
|
||||
export type { FormSummaryLabelProps };
|
||||
+103
-66
@@ -1,52 +1,39 @@
|
||||
import React, { type HTMLAttributes, forwardRef } from "react";
|
||||
import { cl } from "../../utils/helpers";
|
||||
import FormSummaryAnswer from "./FormSummaryAnswer";
|
||||
import FormSummaryAnswers from "./FormSummaryAnswers";
|
||||
import FormSummaryEditLink from "./FormSummaryEditLink";
|
||||
import FormSummaryFooter from "./FormSummaryFooter";
|
||||
import FormSummaryHeader from "./FormSummaryHeader";
|
||||
import FormSummaryHeading from "./FormSummaryHeading";
|
||||
import FormSummaryLabel from "./FormSummaryLabel";
|
||||
import FormSummaryValue from "./FormSummaryValue";
|
||||
import { cl } from "../../../utils/helpers";
|
||||
import {
|
||||
FormSummaryAnswer,
|
||||
type FormSummaryAnswerProps,
|
||||
} from "../answer/FormSummaryAnswer";
|
||||
import {
|
||||
FormSummaryAnswers,
|
||||
type FormSummaryAnswersProps,
|
||||
} from "../answers/FormSummaryAnswers";
|
||||
import {
|
||||
FormSummaryEditLink,
|
||||
type FormSummaryEditProps,
|
||||
} from "../edit-link/FormSummaryEditLink";
|
||||
import {
|
||||
FormSummaryFooter,
|
||||
type FormSummaryFooterProps,
|
||||
} from "../footer/FormSummaryFooter";
|
||||
import {
|
||||
FormSummaryHeader,
|
||||
type FormSummaryHeaderProps,
|
||||
} from "../header/FormSummaryHeader";
|
||||
import {
|
||||
FormSummaryHeading,
|
||||
type FormSummaryHeadingProps,
|
||||
} from "../heading/FormSummaryHeading";
|
||||
import {
|
||||
FormSummaryLabel,
|
||||
type FormSummaryLabelProps,
|
||||
} from "../label/FormSummaryLabel";
|
||||
import {
|
||||
FormSummaryValue,
|
||||
type FormSummaryValueProps,
|
||||
} from "../value/FormSummaryValue";
|
||||
|
||||
interface FormSummaryComponent extends React.ForwardRefExoticComponent<
|
||||
FormSummaryProps & React.RefAttributes<HTMLDivElement>
|
||||
> {
|
||||
/**
|
||||
* Must include `<FormSummary.Heading>`.
|
||||
*/
|
||||
Header: typeof FormSummaryHeader;
|
||||
/**
|
||||
* Typographic Heading to use in the `FormSummary.Header` component.
|
||||
*/
|
||||
Heading: typeof FormSummaryHeading;
|
||||
/**
|
||||
* Link to edit the answers to use in the `FormSummary.Footer` component. Should link to the relevant part of the form.
|
||||
*/
|
||||
EditLink: typeof FormSummaryEditLink;
|
||||
/**
|
||||
* Wrapper component for the answers.
|
||||
*/
|
||||
Answers: typeof FormSummaryAnswers;
|
||||
/**
|
||||
* Wrapper component for each answer. To be used in the `FormSummary.Answers` component.
|
||||
*/
|
||||
Answer: typeof FormSummaryAnswer;
|
||||
/**
|
||||
* Corresponds to the question in the form. To be used in the `FormSummary.Answer` component.
|
||||
*/
|
||||
Label: typeof FormSummaryLabel;
|
||||
/**
|
||||
* Corresponds to the answer in the form. To be used in the `FormSummary.Answer` component.
|
||||
*/
|
||||
Value: typeof FormSummaryValue;
|
||||
/**
|
||||
* Footer component for the form summary, if applicable this is a good place for `<FormSummary.EditLink>`.
|
||||
*/
|
||||
Footer: typeof FormSummaryFooter;
|
||||
}
|
||||
|
||||
export interface FormSummaryProps extends HTMLAttributes<HTMLDivElement> {
|
||||
interface FormSummaryProps extends HTMLAttributes<HTMLDivElement> {
|
||||
/**
|
||||
* Must include:
|
||||
*
|
||||
@@ -57,10 +44,21 @@ export interface FormSummaryProps extends HTMLAttributes<HTMLDivElement> {
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
const FormSummaryRoot = forwardRef<HTMLDivElement, FormSummaryProps>(
|
||||
({ children, className, ...rest }, ref) => {
|
||||
return (
|
||||
<div ref={ref} {...rest} className={cl("aksel-form-summary", className)}>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* A summary of a previously answered form.
|
||||
*
|
||||
* @see [📝 Documentation](https://aksel.nav.no/komponenter/core/formsummary)
|
||||
* @see 🏷️ {@link FormSummaryProps}
|
||||
*
|
||||
* @example
|
||||
* <FormSummary>
|
||||
@@ -78,23 +76,62 @@ export interface FormSummaryProps extends HTMLAttributes<HTMLDivElement> {
|
||||
* </FormSummary.Footer>
|
||||
* </FormSummary>
|
||||
*/
|
||||
export const FormSummary = forwardRef<HTMLDivElement, FormSummaryProps>(
|
||||
({ children, className, ...rest }, ref) => {
|
||||
return (
|
||||
<div ref={ref} {...rest} className={cl("aksel-form-summary", className)}>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
) as FormSummaryComponent;
|
||||
const FormSummary = Object.assign(FormSummaryRoot, {
|
||||
/**
|
||||
* Must include `<FormSummary.Heading>`.
|
||||
*/
|
||||
Header: FormSummaryHeader,
|
||||
/**
|
||||
* Typographic Heading to use in the `FormSummary.Header` component.
|
||||
* @see 🏷️ {@link FormSummaryHeadingProps}
|
||||
*/
|
||||
Heading: FormSummaryHeading,
|
||||
/**
|
||||
* Link to edit the answers to use in the `FormSummary.Footer` component. Should link to the relevant part of the form.
|
||||
* @see 🏷️ {@link FormSummaryEditProps}
|
||||
*/
|
||||
EditLink: FormSummaryEditLink,
|
||||
/**
|
||||
* Wrapper component for the answers.
|
||||
*/
|
||||
Answers: FormSummaryAnswers,
|
||||
/**
|
||||
* Wrapper component for each answer. To be used in the `FormSummary.Answers` component.
|
||||
*/
|
||||
Answer: FormSummaryAnswer,
|
||||
/**
|
||||
* Corresponds to the question in the form. To be used in the `FormSummary.Answer` component.
|
||||
*/
|
||||
Label: FormSummaryLabel,
|
||||
/**
|
||||
* Corresponds to the answer in the form. To be used in the `FormSummary.Answer` component.
|
||||
*/
|
||||
Value: FormSummaryValue,
|
||||
/**
|
||||
* Footer component for the form summary, if applicable this is a good place for `<FormSummary.EditLink>`.
|
||||
*/
|
||||
Footer: FormSummaryFooter,
|
||||
});
|
||||
|
||||
FormSummary.Header = FormSummaryHeader;
|
||||
FormSummary.Heading = FormSummaryHeading;
|
||||
FormSummary.EditLink = FormSummaryEditLink;
|
||||
FormSummary.Answers = FormSummaryAnswers;
|
||||
FormSummary.Answer = FormSummaryAnswer;
|
||||
FormSummary.Label = FormSummaryLabel;
|
||||
FormSummary.Value = FormSummaryValue;
|
||||
FormSummary.Footer = FormSummaryFooter;
|
||||
|
||||
export default FormSummary;
|
||||
export {
|
||||
FormSummary,
|
||||
FormSummaryAnswer,
|
||||
FormSummaryAnswers,
|
||||
FormSummaryEditLink,
|
||||
FormSummaryFooter,
|
||||
FormSummaryHeader,
|
||||
FormSummaryHeading,
|
||||
FormSummaryLabel,
|
||||
FormSummaryValue,
|
||||
};
|
||||
export type {
|
||||
FormSummaryAnswerProps,
|
||||
FormSummaryAnswersProps,
|
||||
FormSummaryEditProps,
|
||||
FormSummaryFooterProps,
|
||||
FormSummaryHeaderProps,
|
||||
FormSummaryHeadingProps,
|
||||
FormSummaryLabelProps,
|
||||
FormSummaryProps,
|
||||
FormSummaryValueProps,
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
import React, { forwardRef } from "react";
|
||||
import { BodyLong } from "../../../typography";
|
||||
import { cl } from "../../../utils/helpers";
|
||||
|
||||
interface FormSummaryValueProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
const FormSummaryValue = forwardRef<HTMLDivElement, FormSummaryValueProps>(
|
||||
({ children, className, ...rest }, ref) => {
|
||||
return (
|
||||
<BodyLong
|
||||
ref={ref}
|
||||
{...rest}
|
||||
as="dd"
|
||||
className={cl("aksel-form-summary__value", className)}
|
||||
>
|
||||
{children}
|
||||
</BodyLong>
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
export { FormSummaryValue };
|
||||
export type { FormSummaryValueProps };
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { forwardRef, useContext, useMemo } from "react";
|
||||
import React, { forwardRef, useContext } from "react";
|
||||
import { useId } from "../../utils-external";
|
||||
import { cl } from "../../utils/helpers";
|
||||
import { Fieldset, type FieldsetProps } from "../fieldset";
|
||||
@@ -65,21 +65,16 @@ export const RadioGroup = forwardRef<HTMLFieldSetElement, RadioGroupProps>(
|
||||
|
||||
const nameId = useId();
|
||||
|
||||
const contextName = name ?? `radioGroupName-${nameId}`;
|
||||
|
||||
const contextValue = useMemo(
|
||||
() => ({
|
||||
name: contextName,
|
||||
defaultValue,
|
||||
value,
|
||||
onChange,
|
||||
required,
|
||||
}),
|
||||
[contextName, defaultValue, value, onChange, required],
|
||||
);
|
||||
|
||||
return (
|
||||
<RadioGroupContext.Provider value={contextValue}>
|
||||
<RadioGroupContext.Provider
|
||||
value={{
|
||||
name: name ?? `radioGroupName-${nameId}`,
|
||||
defaultValue,
|
||||
value,
|
||||
onChange,
|
||||
required,
|
||||
}}
|
||||
>
|
||||
<Fieldset
|
||||
role="radiogroup"
|
||||
{...rest}
|
||||
|
||||
@@ -8,7 +8,7 @@ const metadata: ComponentMetadata = {
|
||||
"Search.Button": SearchButton,
|
||||
},
|
||||
keywords: ["search", "søk", "input", "filter", "find"],
|
||||
related: ["Combobox"],
|
||||
related: ["Combobox-legacy"],
|
||||
};
|
||||
|
||||
export { metadata };
|
||||
@@ -1,8 +1,6 @@
|
||||
import React, {
|
||||
type InputHTMLAttributes,
|
||||
forwardRef,
|
||||
useCallback,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
@@ -152,19 +150,9 @@ export const Search = forwardRef<HTMLInputElement, SearchProps>(
|
||||
searchRef.current?.focus?.();
|
||||
};
|
||||
|
||||
const handleClick = useCallback(() => {
|
||||
const handleClick = () => {
|
||||
onSearchClick?.(`${value ?? internalValue}`);
|
||||
}, [onSearchClick, value, internalValue]);
|
||||
|
||||
const searchContextValue = useMemo(
|
||||
() => ({
|
||||
size,
|
||||
disabled: inputProps.disabled,
|
||||
variant,
|
||||
handleClick,
|
||||
}),
|
||||
[size, inputProps.disabled, variant, handleClick],
|
||||
);
|
||||
};
|
||||
|
||||
const showClearButton =
|
||||
clearButton && !inputProps.disabled && (value ?? internalValue);
|
||||
@@ -246,7 +234,14 @@ export const Search = forwardRef<HTMLInputElement, SearchProps>(
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<SearchContext.Provider value={searchContextValue}>
|
||||
<SearchContext.Provider
|
||||
value={{
|
||||
size,
|
||||
disabled: inputProps.disabled,
|
||||
variant,
|
||||
handleClick,
|
||||
}}
|
||||
>
|
||||
{children
|
||||
? children
|
||||
: variant !== "simple" && <SearchButton data-color={dataColor} />}
|
||||
|
||||
@@ -7,7 +7,7 @@ const metadata: ComponentMetadata = {
|
||||
Select,
|
||||
},
|
||||
keywords: ["select", "nedtrekksliste", "dropdown", "form", "input"],
|
||||
related: ["Combobox"],
|
||||
related: ["Combobox-legacy"],
|
||||
};
|
||||
|
||||
export { metadata };
|
||||
@@ -119,7 +119,7 @@ export {
|
||||
type CheckboxGroupProps,
|
||||
type CheckboxProps,
|
||||
} from "./form/checkbox";
|
||||
export { UNSAFE_Combobox, type ComboboxProps } from "./form/combobox";
|
||||
export { UNSAFE_Combobox, type ComboboxProps } from "./legacy/combobox";
|
||||
export {
|
||||
ConfirmationPanel,
|
||||
type ConfirmationPanelProps,
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ import type { ComponentMetadata } from "../../utils/types/metadata";
|
||||
import { UNSAFE_Combobox } from "./index";
|
||||
|
||||
const metadata: ComponentMetadata = {
|
||||
name: "Combobox",
|
||||
name: "Combobox-legacy",
|
||||
components: {
|
||||
Combobox: UNSAFE_Combobox,
|
||||
},
|
||||
Loaded 100 of 165 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user