mirror of
https://github.com/navikt/aksel.git
synced 2026-10-13 09:12:03 +00:00
Compare commits
87
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dd03078e33 | ||
|
|
72321e3846 | ||
|
|
1cd8ac93ed | ||
|
|
48d6f14103 | ||
|
|
44da7fcdc6 | ||
|
|
e68ab5cb2c | ||
|
|
c721b392f9 | ||
|
|
1d0d0ce665 | ||
|
|
9d02940543 | ||
|
|
7ff63a2c63 | ||
|
|
49f33a78d8 | ||
|
|
06aaec70f0 | ||
|
|
5fbf230e47 | ||
|
|
53265c247e | ||
|
|
d78f33df79 | ||
|
|
4375c55ab6 | ||
|
|
0de8238ecf | ||
|
|
647b14a238 | ||
|
|
64901adccb | ||
|
|
49ddb2094c | ||
|
|
8a5f209735 | ||
|
|
d3bd1202ed | ||
|
|
4bf6027518 | ||
|
|
c8e203c523 | ||
|
|
267799ca0e | ||
|
|
42934af3a1 | ||
|
|
eff8a902c5 | ||
|
|
d34a8f45ef | ||
|
|
d1ceb40439 | ||
|
|
e033b34c3b | ||
|
|
de3991d0f0 | ||
|
|
9641215506 | ||
|
|
8a82e1c1f6 | ||
|
|
a2dfc8699b | ||
|
|
492cfc1801 | ||
|
|
9ca5932fed | ||
|
|
5950673fbf | ||
|
|
5b42ff07ee | ||
|
|
09ba52ea76 | ||
|
|
a82bccf707 | ||
|
|
89ae778c24 | ||
|
|
5b2669d35d | ||
|
|
8a82bb4a96 | ||
|
|
7871e0f95c | ||
|
|
3182888a07 | ||
|
|
f2742da085 | ||
|
|
92721aefa0 | ||
|
|
e6fdfdc9b4 | ||
|
|
93975bc935 | ||
|
|
3a0dac3997 | ||
|
|
1d43710af0 | ||
|
|
6df7c78e3c | ||
|
|
476d79e487 | ||
|
|
238a715c92 | ||
|
|
0fadd33e3e | ||
|
|
eadc0bce13 | ||
|
|
678db9b11b | ||
|
|
e3027cc196 | ||
|
|
ac0fd790e3 | ||
|
|
c344c9beb4 | ||
|
|
5cb5dea4ff | ||
|
|
054c63b161 | ||
|
|
f60ba32f97 | ||
|
|
54811b394d | ||
|
|
c6b0570c4c | ||
|
|
8baa1ab0b4 | ||
|
|
06ceeb3e6f | ||
|
|
02f19858c7 | ||
|
|
799e26a628 | ||
|
|
f5e5843916 | ||
|
|
4b8ed30554 | ||
|
|
28430f1345 | ||
|
|
d242325863 | ||
|
|
ae70bfa719 | ||
|
|
0aef861622 | ||
|
|
525b021e0f | ||
|
|
761344c34e | ||
|
|
a67f61c33f | ||
|
|
b05958863b | ||
|
|
883ae00dfa | ||
|
|
6eb8a79092 | ||
|
|
718b3204d8 | ||
|
|
45970ac0fb | ||
|
|
fe5e8ada74 | ||
|
|
3e625a5cb5 | ||
|
|
edc3495ce6 | ||
|
|
2520bc7ff5 |
No files matched your search
@@ -96,7 +96,7 @@ jobs:
|
||||
comment-id: ${{ steps.fc.outputs.comment-id }}
|
||||
issue-number: ${{ github.event.pull_request.number }}
|
||||
body: |
|
||||
### [<img id="github-comment-finder" src="https://raw.githubusercontent.com/storybookjs/brand/main/logo/logo-storybook-inverse.svg" height="32"/>](${{steps.storybook_url.outputs.replaced}})
|
||||
## [Storybook demo](${{steps.storybook_url.outputs.replaced}})
|
||||
|
||||
### [Endringer til review](${{steps.chromatic_tests.outputs.url}}): ${{steps.chromatic_tests.outputs.changeCount}}
|
||||
|
||||
|
||||
@@ -10,6 +10,11 @@ module.exports = (indexers) => {
|
||||
const exampleIndexer = async (fileName: string, opts) => {
|
||||
let code = readFileSync(fileName, "utf-8").toString();
|
||||
|
||||
code = code
|
||||
.split("\n")
|
||||
.filter((line) => !line.includes("withDsExample"))
|
||||
.join("\n");
|
||||
|
||||
code = code.replace("export const args =", "const args =");
|
||||
|
||||
code += `\nexport default { title: "Eksempler/${fileName
|
||||
|
||||
+3
-8
@@ -1,5 +1,4 @@
|
||||
const storyIndexers = require("./indexer");
|
||||
|
||||
const path = require("path");
|
||||
const { mergeConfig } = require("vite");
|
||||
|
||||
@@ -59,15 +58,11 @@ module.exports = {
|
||||
},
|
||||
async viteFinal(config) {
|
||||
return mergeConfig(config, {
|
||||
define: { "process.env": {} },
|
||||
define: {
|
||||
"process.env": {},
|
||||
},
|
||||
resolve: {
|
||||
alias: [
|
||||
/*
|
||||
// Example
|
||||
{
|
||||
find: "@components",
|
||||
replacement: path.resolve(__dirname, "./src/components"),
|
||||
}, */
|
||||
{
|
||||
find: "components",
|
||||
replacement: path.resolve(
|
||||
|
||||
@@ -4,7 +4,7 @@ import "./layout.css";
|
||||
export const parameters = {
|
||||
options: {
|
||||
storySort: {
|
||||
method: "",
|
||||
method: "alphabetical",
|
||||
order: ["Intro", "ds-react", ["form"], ["Default"], "ds-icons"],
|
||||
locales: "",
|
||||
},
|
||||
|
||||
@@ -1,5 +1,41 @@
|
||||
# @navikt/aksel-icons
|
||||
|
||||
## 4.11.2
|
||||
|
||||
## 4.11.1
|
||||
|
||||
## 4.11.0
|
||||
|
||||
## 4.10.2
|
||||
|
||||
## 4.10.1
|
||||
|
||||
## 4.10.0
|
||||
|
||||
## 4.9.1
|
||||
|
||||
## 4.9.0
|
||||
|
||||
## 4.8.0
|
||||
|
||||
## 4.7.4
|
||||
|
||||
## 4.7.3
|
||||
|
||||
## 4.7.2
|
||||
|
||||
## 4.7.1
|
||||
|
||||
## 4.7.0
|
||||
|
||||
## 4.6.1
|
||||
|
||||
## 4.6.0
|
||||
|
||||
## 4.5.0
|
||||
|
||||
## 4.4.2
|
||||
|
||||
## 4.4.1
|
||||
|
||||
## 4.1.5
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
.icon-button {
|
||||
min-height: 3rem;
|
||||
min-width: 3rem;
|
||||
border-radius: 2px;
|
||||
border-radius: var(--a-border-radius-small);
|
||||
display: grid;
|
||||
place-content: center;
|
||||
background-color: var(--a-surface-default);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import meta from "@navikt/aksel-icons/metadata";
|
||||
|
||||
const subCategorizeIcons = (
|
||||
icons: typeof meta[1][]
|
||||
): { sub_category: string; icons: typeof meta[1][] }[] => {
|
||||
const categories: { sub_category: string; icons: typeof meta[1][] }[] = [];
|
||||
icons: (typeof meta)[1][]
|
||||
): { sub_category: string; icons: (typeof meta)[1][] }[] => {
|
||||
const categories: { sub_category: string; icons: (typeof meta)[1][] }[] = [];
|
||||
|
||||
for (const icon of icons) {
|
||||
const i = categories.findIndex(
|
||||
@@ -19,14 +19,14 @@ const subCategorizeIcons = (
|
||||
};
|
||||
|
||||
export const categorizeIcons = (
|
||||
icons: typeof meta[1][]
|
||||
icons: (typeof meta)[1][]
|
||||
): {
|
||||
category: string;
|
||||
sub_categories: { sub_category: string; icons: typeof meta[1][] }[];
|
||||
sub_categories: { sub_category: string; icons: (typeof meta)[1][] }[];
|
||||
}[] => {
|
||||
const categories: {
|
||||
category: string;
|
||||
icons: typeof meta[1][];
|
||||
icons: (typeof meta)[1][];
|
||||
}[] = [];
|
||||
|
||||
for (const icon of icons) {
|
||||
@@ -42,14 +42,14 @@ export const categorizeIcons = (
|
||||
.map((x) => ({ ...x, sub_categories: subCategorizeIcons(x.icons) }));
|
||||
};
|
||||
|
||||
const noFill = (icon: typeof meta[1], icons: typeof meta[1][]) => {
|
||||
const noFill = (icon: (typeof meta)[1], icons: (typeof meta)[1][]) => {
|
||||
const foundFill = icons.find(
|
||||
(x) => x.name.endsWith("Fill") && x.name.replace("Fill", "") === icon.name
|
||||
);
|
||||
return !foundFill;
|
||||
};
|
||||
|
||||
export const getFillIcon = (icons: typeof meta[1][]) => {
|
||||
export const getFillIcon = (icons: (typeof meta)[1][]) => {
|
||||
return icons.filter(
|
||||
(x, _, z) => x.variant.toLowerCase() === "fill" || noFill(x, z)
|
||||
);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@navikt/aksel-icons",
|
||||
"version": "4.4.1",
|
||||
"version": "4.11.2",
|
||||
"author": "Aksel | NAV",
|
||||
"homepage": "https://aksel.nav.no/ikoner",
|
||||
"repository": {
|
||||
|
||||
@@ -1,5 +1,41 @@
|
||||
# @navikt/aksel-stylelint
|
||||
|
||||
## 4.11.2
|
||||
|
||||
## 4.11.1
|
||||
|
||||
## 4.11.0
|
||||
|
||||
## 4.10.2
|
||||
|
||||
## 4.10.1
|
||||
|
||||
## 4.10.0
|
||||
|
||||
## 4.9.1
|
||||
|
||||
## 4.9.0
|
||||
|
||||
## 4.8.0
|
||||
|
||||
## 4.7.4
|
||||
|
||||
## 4.7.3
|
||||
|
||||
## 4.7.2
|
||||
|
||||
## 4.7.1
|
||||
|
||||
## 4.7.0
|
||||
|
||||
## 4.6.1
|
||||
|
||||
## 4.6.0
|
||||
|
||||
## 4.5.0
|
||||
|
||||
## 4.4.2
|
||||
|
||||
## 4.4.1
|
||||
|
||||
## 4.1.0
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@navikt/aksel-stylelint",
|
||||
"version": "4.4.1",
|
||||
"version": "4.11.2",
|
||||
"author": "Aksel | NAV",
|
||||
"homepage": "https://aksel.nav.no/grunnleggende/kode/stylelint",
|
||||
"repository": {
|
||||
@@ -35,8 +35,8 @@
|
||||
"dev": "yarn watch:lint"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@navikt/ds-css": "^4.4.1",
|
||||
"@navikt/ds-tokens": "^4.4.1",
|
||||
"@navikt/ds-css": "^4.11.2",
|
||||
"@navikt/ds-tokens": "^4.11.2",
|
||||
"@types/jest": "^29.0.0",
|
||||
"concurrently": "7.2.1",
|
||||
"copyfiles": "2.4.1",
|
||||
|
||||
@@ -1,5 +1,131 @@
|
||||
# @navikt/aksel
|
||||
|
||||
## 4.11.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`72321e384`](https://github.com/navikt/aksel/commit/72321e3846f785318ebdba9f8e06cf13b09cd524)]:
|
||||
- @navikt/ds-css@4.11.2
|
||||
|
||||
## 4.11.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`e68ab5cb2`](https://github.com/navikt/aksel/commit/e68ab5cb2cd91c2f0234c864ee71821ed07a8203)]:
|
||||
- @navikt/ds-css@4.11.1
|
||||
|
||||
## 4.11.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`64901adcc`](https://github.com/navikt/aksel/commit/64901adccb8f19fbe06cdab4a70d47978e90e343), [`0de8238ec`](https://github.com/navikt/aksel/commit/0de8238ecf22e9f1fbc0e1b0cfe7a5cd7254901e), [`647b14a23`](https://github.com/navikt/aksel/commit/647b14a23888f82bacc4806d3afaacb5e39178fa)]:
|
||||
- @navikt/ds-css@4.11.0
|
||||
|
||||
## 4.10.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @navikt/ds-css@4.10.2
|
||||
|
||||
## 4.10.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`d3bd1202e`](https://github.com/navikt/aksel/commit/d3bd1202eddb23dd3f1f09c3e4086ff3b19737d6)]:
|
||||
- @navikt/ds-css@4.10.1
|
||||
|
||||
## 4.10.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`267799ca0`](https://github.com/navikt/aksel/commit/267799ca0ecc0c549e159f94124befb654e29331)]:
|
||||
- @navikt/ds-css@4.10.0
|
||||
|
||||
## 4.9.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`eff8a902c`](https://github.com/navikt/aksel/commit/eff8a902c50fd5ebc56616e866aa0a61b9eb5efc)]:
|
||||
- @navikt/ds-css@4.9.1
|
||||
|
||||
## 4.9.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`e033b34c3`](https://github.com/navikt/aksel/commit/e033b34c3b85fb98dd11dd0300bb20075e1b06e8)]:
|
||||
- @navikt/ds-css@4.9.0
|
||||
|
||||
## 4.8.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`8a82e1c1f`](https://github.com/navikt/aksel/commit/8a82e1c1f66ea38fca77b25d74b14926bd817dd9)]:
|
||||
- @navikt/ds-css@4.8.0
|
||||
|
||||
## 4.7.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`492cfc180`](https://github.com/navikt/aksel/commit/492cfc1801df4ab16306185345d5089e24a0d659)]:
|
||||
- @navikt/ds-css@4.7.4
|
||||
|
||||
## 4.7.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @navikt/ds-css@4.7.3
|
||||
|
||||
## 4.7.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`e6fdfdc9b`](https://github.com/navikt/aksel/commit/e6fdfdc9b44156b6eb8ebc0eda3a9259dce800ff)]:
|
||||
- @navikt/ds-css@4.7.2
|
||||
|
||||
## 4.7.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @navikt/ds-css@4.7.1
|
||||
|
||||
## 4.7.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`e3027cc19`](https://github.com/navikt/aksel/commit/e3027cc1966623433cfc2d28915273486c7bf611)]:
|
||||
- @navikt/ds-css@4.7.0
|
||||
|
||||
## 4.6.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`28430f134`](https://github.com/navikt/aksel/commit/28430f13455a8ecc10447e5e1ad75625d29c4bcb)]:
|
||||
- @navikt/ds-css@4.6.1
|
||||
|
||||
## 4.6.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`ae70bfa71`](https://github.com/navikt/aksel/commit/ae70bfa7192db46d8dea0dfb0222a857efc46be5)]:
|
||||
- @navikt/ds-css@4.6.0
|
||||
|
||||
## 4.5.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`b05958863`](https://github.com/navikt/aksel/commit/b05958863b1adadb1b6a3fcceb4477e7411b66b5), [`b05958863`](https://github.com/navikt/aksel/commit/b05958863b1adadb1b6a3fcceb4477e7411b66b5)]:
|
||||
- @navikt/ds-css@4.5.0
|
||||
|
||||
## 4.4.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @navikt/ds-css@4.4.2
|
||||
|
||||
## 4.4.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@navikt/aksel",
|
||||
"version": "4.4.1",
|
||||
"version": "4.11.2",
|
||||
"description": "Aksel command line interface. Handles css-imports, codemods and more",
|
||||
"author": "Aksel | NAV designsystem team",
|
||||
"license": "MIT",
|
||||
@@ -29,7 +29,7 @@
|
||||
},
|
||||
"homepage": "https://aksel.nav.no/grunnleggende/kode/kommandolinje",
|
||||
"dependencies": {
|
||||
"@navikt/ds-css": "4.4.1",
|
||||
"@navikt/ds-css": "4.11.2",
|
||||
"axios": "1.3.6",
|
||||
"chalk": "4.1.0",
|
||||
"clipboardy": "^2.3.0",
|
||||
|
||||
@@ -1,5 +1,105 @@
|
||||
# @navikt/ds-css
|
||||
|
||||
## 4.11.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- :lipstick: ToggleGroup: fjern semibold fra selected button ([#2167](https://github.com/navikt/aksel/pull/2167))
|
||||
|
||||
## 4.11.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Border-radius: Fikset hardkodet border-radius i Datepicker, ToggleGroup og Combobox. ([#2159](https://github.com/navikt/aksel/pull/2159))
|
||||
|
||||
## 4.11.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- HGrid: Ny komponent 'HGrid' er ute i Beta: [Dokumentasjon](https://aksel.nav.no/komponenter/core/hgrid) ([#1838](https://github.com/navikt/aksel/pull/1838))
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- List: Fikset alignment av ikoner ([#2149](https://github.com/navikt/aksel/pull/2149))
|
||||
|
||||
- Font: La til egen font for semibold italic for bedre skalering cross-browser ([#2150](https://github.com/navikt/aksel/pull/2150))
|
||||
|
||||
## 4.10.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Link: Fikset visited farger og inline SVG-reset ved bruk av tailwind
|
||||
|
||||
## 4.10.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- Link: La til 'variant', 'underline' og 'inlineText'-prop ([#2093](https://github.com/navikt/aksel/pull/2093))
|
||||
|
||||
## 4.9.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Tweaks to combobox - updated example, small bugfixes, better affordance for selected options and added flag for "isAddedByUser" to onToggleSelected ([#2144](https://github.com/navikt/aksel/pull/2144))
|
||||
|
||||
## 4.9.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- Table: ExpandableRow kan nå åpnes med 'expandOnRowClick'-prop ([#2127](https://github.com/navikt/aksel/pull/2127))
|
||||
|
||||
## 4.8.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- Nye komponenter `VStack`, `HStack` og `Spacer` for å enklere kunne lage layout med flexbox og spacing-variabler. ([#2040](https://github.com/navikt/aksel/pull/2040))
|
||||
|
||||
## 4.7.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Oppdatert bruk av REM i komponenter for forbedret utrykk ved font-scaling i browser ([#2126](https://github.com/navikt/aksel/pull/2126))
|
||||
|
||||
## 4.7.3
|
||||
|
||||
## 4.7.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Stepper: Fikset `hotizontal`-bug når step var `completed` ([#2116](https://github.com/navikt/aksel/pull/2116))
|
||||
|
||||
## 4.7.1
|
||||
|
||||
## 4.7.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- Ny komponent Combobox! ([#1868](https://github.com/navikt/aksel/pull/1868))
|
||||
|
||||
## 4.6.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Skjema: Labels og Legends bruker nå inline-flex når readOnly er satt ([#2089](https://github.com/navikt/aksel/pull/2089))
|
||||
|
||||
## 4.6.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- Skjema: De fleste skjemakomponenter har nå styling for `readOnly`-state ([#2080](https://github.com/navikt/aksel/pull/2080))
|
||||
|
||||
## 4.5.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- - Alert: La til `closeButton`-prop ([#2079](https://github.com/navikt/aksel/pull/2079))
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- - Button: Fikset outline-bug i tertiary-variant ved `:active`-state ([#2079](https://github.com/navikt/aksel/pull/2079))
|
||||
|
||||
## 4.4.2
|
||||
|
||||
## 4.4.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
font-size: 1.5rem;
|
||||
align-self: flex-start;
|
||||
height: var(--a-font-line-height-xlarge);
|
||||
margin: var(--a-spacing-1);
|
||||
background: radial-gradient(circle, var(--a-surface-default) 50%, 0, transparent);
|
||||
}
|
||||
|
||||
@@ -73,3 +74,11 @@
|
||||
border: none;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.navds-alert__button-wrapper {
|
||||
align-self: flex-start;
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-flow: row nowrap;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
@@ -5,6 +5,13 @@
|
||||
font-display: swap;
|
||||
src: url("https://cdn.nav.no/aksel/fonts/SourceSans3-italic.woff2") format("woff2");
|
||||
}
|
||||
@font-face {
|
||||
font-family: "Source Sans Pro";
|
||||
font-style: italic;
|
||||
font-weight: 600;
|
||||
font-display: swap;
|
||||
src: url("https://cdn.nav.no/aksel/fonts/SourceSans3-italic-latin-semibold") format("woff2");
|
||||
}
|
||||
@font-face {
|
||||
font-family: "Source Sans Pro";
|
||||
font-style: normal;
|
||||
|
||||
@@ -294,7 +294,6 @@
|
||||
.navds-button--tertiary:active {
|
||||
color: var(--ac-button-tertiary-active-text, var(--a-text-on-action));
|
||||
background-color: var(--ac-button-tertiary-active-bg, var(--a-surface-action-active));
|
||||
box-shadow: inset 0 0 0 1px var(--a-surface-default);
|
||||
}
|
||||
|
||||
.navds-button--tertiary:active:hover {
|
||||
@@ -346,7 +345,6 @@
|
||||
.navds-button--tertiary-neutral:active {
|
||||
color: var(--ac-button-tertiary-neutral-active-text, var(--a-text-on-neutral));
|
||||
background-color: var(--ac-button-tertiary-neutral-active-bg, var(--a-surface-neutral-active));
|
||||
box-shadow: inset 0 0 0 1px var(--a-surface-default);
|
||||
}
|
||||
|
||||
.navds-button--tertiary-neutral:active:hover {
|
||||
|
||||
@@ -25,11 +25,11 @@
|
||||
padding: 0 var(--a-spacing-3);
|
||||
text-decoration: none;
|
||||
border-radius: var(--a-border-radius-full);
|
||||
min-height: 32px;
|
||||
min-height: 2rem;
|
||||
}
|
||||
|
||||
.navds-chips--small .navds-chips__chip {
|
||||
min-height: 24px;
|
||||
min-height: 1.5rem;
|
||||
padding: 0 var(--a-spacing-2);
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,11 @@ const StyleMappings = {
|
||||
{ component: "Checkbox", main: formCss, dependencies: [typoCss] },
|
||||
{ component: "CheckboxGroup", main: formCss, dependencies: [typoCss] },
|
||||
{ component: "Chips", main: "chips.css", dependencies: [typoCss] },
|
||||
{
|
||||
component: "UNSAFE_Combobox",
|
||||
main: "combobox.css",
|
||||
dependencies: [typoCss, "chips.css"],
|
||||
},
|
||||
{
|
||||
component: "ConfirmationPanel",
|
||||
main: formCss,
|
||||
@@ -94,6 +99,10 @@ const StyleMappings = {
|
||||
main: "help-text.css",
|
||||
dependencies: ["popover.css"],
|
||||
},
|
||||
{
|
||||
component: "HGrid",
|
||||
main: "hgrid.css",
|
||||
},
|
||||
{ component: "Ingress", main: typoCss },
|
||||
{
|
||||
component: "InternalHeader",
|
||||
@@ -129,6 +138,18 @@ const StyleMappings = {
|
||||
{ component: "Select", main: formCss, dependencies: [typoCss] },
|
||||
{ component: "Skeleton", main: "skeleton.css", dependencies: [] },
|
||||
{ component: "Stepper", main: "stepper.css", dependencies: [typoCss] },
|
||||
{
|
||||
component: "HStack",
|
||||
main: "stack.css",
|
||||
},
|
||||
{
|
||||
component: "VStack",
|
||||
main: "stack.css",
|
||||
},
|
||||
{
|
||||
component: "Spacer",
|
||||
main: "stack.css",
|
||||
},
|
||||
{ component: "Switch", main: formCss, dependencies: [typoCss] },
|
||||
{ component: "Table", main: "table.css", dependencies: [typoCss] },
|
||||
{ component: "Tabs", main: "tabs.css", dependencies: [typoCss] },
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
.navds-copybutton__icon {
|
||||
font-size: 1.5rem;
|
||||
display: flex;
|
||||
margin-left: -4px;
|
||||
margin-left: -0.25rem;
|
||||
}
|
||||
|
||||
.navds-copybutton__icon:only-child {
|
||||
@@ -60,7 +60,7 @@
|
||||
}
|
||||
|
||||
:where(.navds-copybutton--small, .navds-copybutton--xsmall):where(:not(:only-child)) {
|
||||
margin: -2px;
|
||||
margin: -0.125rem;
|
||||
}
|
||||
|
||||
.navds-copybutton:focus-visible {
|
||||
|
||||
@@ -223,7 +223,7 @@
|
||||
|
||||
.navds-date__field-button {
|
||||
position: absolute;
|
||||
right: 1px;
|
||||
right: 0.0625rem;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
color: var(--ac-date-input-button-text, var(--a-text-default));
|
||||
@@ -233,12 +233,12 @@
|
||||
text-decoration: none;
|
||||
border: none;
|
||||
background: none;
|
||||
border-radius: 3px;
|
||||
border-radius: calc(var(--a-border-radius-medium) - 1px);
|
||||
padding: var(--a-spacing-3);
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 1.5rem;
|
||||
height: calc(100% - 2px);
|
||||
height: calc(100% - 0.125rem);
|
||||
border-start-start-radius: 0;
|
||||
border-end-start-radius: 0;
|
||||
}
|
||||
@@ -282,3 +282,8 @@
|
||||
.navds-date__popover:where(.navds-popover) {
|
||||
border: none;
|
||||
}
|
||||
|
||||
/* Readonly */
|
||||
.navds-date__field--readonly .navds-date__field-button {
|
||||
cursor: default;
|
||||
}
|
||||
@@ -66,7 +66,7 @@
|
||||
*************************/
|
||||
|
||||
.navds-expansioncard__title--small {
|
||||
margin-top: 10px;
|
||||
margin-top: 0.625rem;
|
||||
}
|
||||
|
||||
.navds-expansioncard__title--medium {
|
||||
|
||||
@@ -0,0 +1,305 @@
|
||||
.navds-combobox__wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.navds-combobox__wrapper-inner {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
width: 100%;
|
||||
padding: calc(var(--a-spacing-2) - 2px) var(--a-spacing-2);
|
||||
}
|
||||
|
||||
.navds-combobox__wrapper-inner > :first-child {
|
||||
flex: 2;
|
||||
}
|
||||
|
||||
.navds-combobox__wrapper-inner > :last-child {
|
||||
display: flex;
|
||||
flex-flow: row nowrap;
|
||||
}
|
||||
|
||||
.navds-form-field--small .navds-combobox__wrapper-inner {
|
||||
padding: var(--a-spacing-1) calc(var(--a-spacing-3) / 2);
|
||||
}
|
||||
|
||||
.navds-combobox__wrapper-inner:hover {
|
||||
cursor: text;
|
||||
}
|
||||
|
||||
.navds-combobox__selected-options {
|
||||
gap: var(--a-spacing-2);
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.navds-combobox__selected-options > li {
|
||||
margin: auto 0;
|
||||
border-radius: var(--a-border-radius-full);
|
||||
}
|
||||
|
||||
.navds-combobox__selected-options > li:last-of-type {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.navds-combobox__selected-options--no-bg {
|
||||
font-family: inherit;
|
||||
font-size: var(--a-font-size-large);
|
||||
font-weight: var(--a-font-weight-regular);
|
||||
letter-spacing: 0;
|
||||
line-height: var(--a-font-line-height-large);
|
||||
margin: 0;
|
||||
padding-left: 0.25rem;
|
||||
}
|
||||
|
||||
.navds-combobox__input-wrapper {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.navds-combobox__input {
|
||||
z-index: 1;
|
||||
flex: 1;
|
||||
border: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
min-width: 10ch;
|
||||
width: 100%;
|
||||
height: 2rem;
|
||||
}
|
||||
|
||||
.navds-combobox__input:focus-visible {
|
||||
outline: none;
|
||||
border: none;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.navds-combobox__wrapper-inner:has(.navds-combobox__input:focus-visible) {
|
||||
box-shadow: 0 0 0 1px var(--a-surface-default) inset, var(--a-shadow-focus);
|
||||
box-shadow: var(--a-shadow-focus);
|
||||
}
|
||||
|
||||
.navds-combobox__wrapper-inner:has(.navds-combobox__input:focus-visible).navds-combobox__wrapper-inner--virtually-unfocused {
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
@supports not selector(:focus-visible) {
|
||||
.navds-combobox__input:focus {
|
||||
outline: none;
|
||||
border: none;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.navds-combobox__wrapper-inner:has(.navds-combobox__input:focus) {
|
||||
box-shadow: 0 0 0 1px var(--a-surface-default) inset, var(--a-shadow-focus);
|
||||
box-shadow: var(--a-shadow-focus);
|
||||
}
|
||||
|
||||
.navds-combobox__wrapper-inner:has(.navds-combobox__input:focus).navds-combobox__wrapper-inner--virtually-unfocused {
|
||||
box-shadow: none;
|
||||
}
|
||||
}
|
||||
|
||||
@supports not selector(:has) {
|
||||
.navds-combobox--focused .navds-combobox__wrapper-inner {
|
||||
box-shadow: 0 0 0 1px var(--a-surface-default) inset, var(--a-shadow-focus);
|
||||
box-shadow: var(--a-shadow-focus);
|
||||
}
|
||||
|
||||
.navds-combobox--focused .navds-combobox__wrapper-inner.navds-combobox__wrapper-inner--virtually-unfocused {
|
||||
box-shadow: none;
|
||||
}
|
||||
}
|
||||
|
||||
.navds-combobox__button-clear {
|
||||
border-radius: var(--a-border-radius-medium);
|
||||
color: var(--ac-combobox-clear-icon, var(--a-text-subtle));
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
background: none;
|
||||
border: none;
|
||||
font-size: 1rem;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.navds-combobox__button-clear svg {
|
||||
width: 1.5rem;
|
||||
height: 1.5rem;
|
||||
}
|
||||
|
||||
.navds-combobox__input::-webkit-search-cancel-button {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.navds-combobox__button-toggle-list {
|
||||
border-radius: var(--a-border-radius-medium);
|
||||
color: var(--a-text-default);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
background: none;
|
||||
border: none;
|
||||
font-size: 1rem;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.navds-combobox__button-clear:active:hover,
|
||||
.navds-combobox__button-toggle-list:active:hover {
|
||||
color: var(--ac-combobox-clear-icon-active, var(--a-text-action));
|
||||
}
|
||||
|
||||
.navds-combobox__button-clear:hover,
|
||||
.navds-combobox__button-toggle-list:hover {
|
||||
color: var(--ac-combobox-clear-icon-hover, var(--a-text-action-selected));
|
||||
}
|
||||
|
||||
.navds-combobox__button-toggle-list:focus-visible {
|
||||
box-shadow: 0 0 0 1px var(--a-surface-default) inset, var(--a-shadow-focus);
|
||||
box-shadow: var(--a-shadow-focus);
|
||||
outline: none;
|
||||
}
|
||||
|
||||
@supports not selector(:focus-visible) {
|
||||
.navds-combobox__button-toggle-list:focus {
|
||||
box-shadow: 0 0 0 1px var(--a-surface-default) inset, var(--a-shadow-focus);
|
||||
box-shadow: var(--a-shadow-focus);
|
||||
outline: none;
|
||||
}
|
||||
}
|
||||
|
||||
.navds-combobox__button-toggle-list svg {
|
||||
width: 1.5rem;
|
||||
height: 1.5rem;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.navds-form-field--small .navds-combobox__button-toggle-list svg,
|
||||
.navds-form-field--small .navds-combobox__button-clear svg {
|
||||
width: 1.25rem;
|
||||
height: 1.25rem;
|
||||
}
|
||||
|
||||
/* dropdown list */
|
||||
|
||||
.navds-combobox__list {
|
||||
max-height: 290px;
|
||||
overflow-y: auto;
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
z-index: 9999;
|
||||
top: calc(100% + var(--a-spacing-2));
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
border: 1px solid var(--ac-combobox-list-border-color, var(--a-border-divider));
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
padding: 0;
|
||||
box-shadow: var(--a-shadow-small);
|
||||
border-radius: var(--a-border-radius-medium);
|
||||
gap: var(--a-spacing-1) 0;
|
||||
background-color: var(--ac-combobox-list-bg, var(--a-surface-default));
|
||||
color: var(--ac-combobox-list-text, var(--a-text-default));
|
||||
}
|
||||
|
||||
.navds-combobox__list--closed {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.navds-combobox__list svg {
|
||||
height: 1.5rem;
|
||||
width: 1.5rem;
|
||||
}
|
||||
|
||||
.navds-combobox__list-item,
|
||||
.navds-combobox__list-item__no-options,
|
||||
.navds-combobox__list-item__new-option {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: var(--a-spacing-3);
|
||||
width: 100%;
|
||||
background-color: var(--ac-combobox-list-item-bg, var(--a-surface-default));
|
||||
}
|
||||
|
||||
.navds-form-field--small .navds-combobox__list-item,
|
||||
.navds-form-field--small .navds-combobox__list-item__no-options,
|
||||
.navds-form-field--small .navds-combobox__list-item__new-option {
|
||||
padding: calc(var(--a-spacing-3) / 2) var(--a-spacing-2);
|
||||
}
|
||||
|
||||
.navds-combobox__list-item--loading {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
padding: var(--a-spacing-3);
|
||||
background-color: var(--ac-combobox-list-item-loading-bg, var(--a-surface-default));
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.navds-combobox__list-item--focus,
|
||||
.navds-combobox__list-item:hover {
|
||||
background-color: var(--ac-combobox-list-item-hover-bg, var(--a-surface-hover));
|
||||
cursor: pointer;
|
||||
border-left: 4px solid var(--ac-combobox-list-item-hover-border-left, var(--a-border-strong));
|
||||
padding-left: calc(var(--a-spacing-3) - 4px);
|
||||
}
|
||||
|
||||
.navds-combobox__list-item--selected {
|
||||
background-color: var(--ac-combobox-list-item-selected-bg, var(--a-surface-selected));
|
||||
}
|
||||
|
||||
.navds-combobox__list-item--selected p {
|
||||
font-weight: var(--a-font-weight-bold);
|
||||
}
|
||||
|
||||
.navds-combobox__list-item--selected.navds-combobox__list-item--focus,
|
||||
.navds-combobox__list-item--selected:hover {
|
||||
background-color: var(--ac-combobox-list-item-selected-hover-bg, var(--a-surface-action-subtle-hover));
|
||||
border-left: 4px solid var(--ac-combobox-list-item-selected-hover-border-left, var(--a-border-focus));
|
||||
padding-left: calc(var(--a-spacing-3) - 4px);
|
||||
}
|
||||
|
||||
.navds-combobox__list-item__new-option {
|
||||
border-bottom: 1px solid var(--a-border-divider);
|
||||
background: var(--a-surface-neutral-subtle);
|
||||
cursor: pointer;
|
||||
justify-content: flex-start;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.navds-combobox__list-item__new-option:hover {
|
||||
border-bottom: 1px solid var(--a-border-divider);
|
||||
background: var(--a-surface-neutral-subtle-hover);
|
||||
}
|
||||
|
||||
.navds-combobox__list-item__new-option--focus {
|
||||
box-shadow: var(--a-shadow-focus) inset, var(--a-border-action) 0 0 0 5px inset;
|
||||
border-radius: calc(var(--a-border-radius-medium) - 1px);
|
||||
}
|
||||
|
||||
/* Mobile */
|
||||
|
||||
@media (max-width: 479px) {
|
||||
.navds-combobox__button-toggle-list {
|
||||
right: 0.5rem;
|
||||
}
|
||||
|
||||
/* add bigger click area for input */
|
||||
.navds-combobox__input {
|
||||
min-width: min-content;
|
||||
padding: 0.75rem 0;
|
||||
}
|
||||
|
||||
.navds-combobox__selected-options {
|
||||
gap: var(--a-spacing-1);
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,10 @@
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.navds-fieldset--readonly > :where(.navds-fieldset__legend) {
|
||||
display: inline-flex;
|
||||
}
|
||||
|
||||
.navds-fieldset:disabled > .navds-fieldset__legend,
|
||||
.navds-fieldset:disabled > .navds-fieldset__description {
|
||||
opacity: 0.3;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
}
|
||||
|
||||
.navds-form-field__description {
|
||||
margin-top: -6px;
|
||||
margin-top: -0.375rem;
|
||||
color: var(--ac-form-description, var(--a-text-subtle));
|
||||
}
|
||||
|
||||
@@ -36,3 +36,14 @@
|
||||
.navds-form-field__subdescription {
|
||||
color: var(--ac-form-subdescription, var(--a-text-subtle));
|
||||
}
|
||||
|
||||
.navds-form-field--readonly > :where(.navds-form-field__label) {
|
||||
display: inline-flex;
|
||||
}
|
||||
|
||||
.navds-form-field__readonly-icon {
|
||||
margin-top: var(--a-spacing-05);
|
||||
margin-right: var(--a-spacing-2);
|
||||
flex-shrink: 0;
|
||||
align-self: flex-start;
|
||||
}
|
||||
@@ -11,3 +11,4 @@
|
||||
@import "text-field.css";
|
||||
@import "textarea.css";
|
||||
@import "search.css";
|
||||
@import "combobox.css";
|
||||
@@ -7,10 +7,10 @@
|
||||
.navds-checkbox__input,
|
||||
.navds-radio__input {
|
||||
position: absolute;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
width: 3rem;
|
||||
height: 3rem;
|
||||
top: 0;
|
||||
left: -12px;
|
||||
left: -0.75rem;
|
||||
z-index: 1;
|
||||
opacity: 0;
|
||||
cursor: pointer;
|
||||
@@ -22,6 +22,9 @@
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
gap: var(--a-spacing-2);
|
||||
|
||||
--__ac-radio-checkbox-readonly-bg: var(--a-surface-subtle);
|
||||
--__ac-radio-checkbox-readonly-border: var(--a-border-subtle);
|
||||
}
|
||||
|
||||
.navds-checkbox__label::before,
|
||||
@@ -48,15 +51,15 @@
|
||||
|
||||
.navds-checkbox--small > .navds-checkbox__input,
|
||||
.navds-radio--small > .navds-radio__input {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
top: 0;
|
||||
left: -6px;
|
||||
left: -0.375rem;
|
||||
}
|
||||
|
||||
.navds-checkbox--small > .navds-checkbox__label,
|
||||
.navds-radio--small > .navds-radio__label {
|
||||
padding: 6px 0;
|
||||
padding: 0.375rem 0;
|
||||
}
|
||||
|
||||
.navds-checkbox--small > .navds-checkbox__label::before,
|
||||
@@ -102,7 +105,7 @@
|
||||
background-color: var(--ac-radio-checkbox-bg, var(--a-surface-default));
|
||||
width: 0.75rem;
|
||||
height: 0.25rem;
|
||||
border-radius: 1px; /* Custom value OK */
|
||||
border-radius: 1px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
@@ -112,15 +115,15 @@
|
||||
|
||||
.navds-checkbox__input:checked + .navds-checkbox__label::before {
|
||||
background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMyAxMCI+ICAgIDxnPiAgICA8cGF0aCBmaWxsPSIjRkZGRkZGIiBkPSJNNCwxMGMtMC40LDAtMC44LTAuMS0xLjEtMC40TDAuNCw3LjFDMC4xLDYuOCwwLDYuNCwwLDZzMC4yLTAuOCwwLjUtMS4xQzEsNC40LDIsNC40LDIuNSw0LjlMNCw2LjRsNi40LTYgICAgQzEwLjgsMC4xLDExLjEsMCwxMS41LDBjMC40LDAsMC44LDAuMiwxLDAuNWMwLjYsMC42LDAuNSwxLjYtMC4xLDIuMXYwTDUsOS42QzQuNyw5LjksNC40LDEwLDQsMTB6IE0xMS44LDEuOUwxMS44LDEuOSAgICBDMTEuOCwxLjksMTEuOCwxLjksMTEuOCwxLjl6IE0xMS4yLDEuMUMxMS4yLDEuMSwxMS4yLDEuMSwxMS4yLDEuMUwxMS4yLDEuMXoiLz4gICAgPC9nPjwvc3ZnPg==);
|
||||
background-position: 6px center;
|
||||
background-position: 0.375rem center;
|
||||
background-repeat: no-repeat;
|
||||
background-size: 13px;
|
||||
background-size: 0.8125rem;
|
||||
box-shadow: none;
|
||||
background-color: var(--ac-radio-checkbox-action, var(--a-surface-action));
|
||||
}
|
||||
|
||||
.navds-checkbox--small > .navds-checkbox__input:checked + .navds-checkbox__label::before {
|
||||
background-position: 4px center;
|
||||
background-position: 0.25rem center;
|
||||
}
|
||||
|
||||
.navds-checkbox__input:indeterminate:focus-visible + .navds-checkbox__label::before,
|
||||
@@ -244,3 +247,57 @@
|
||||
.navds-radio--disabled > .navds-radio__label {
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
/* Readonly */
|
||||
.navds-checkbox--readonly > :where(.navds-checkbox__input, .navds-checkbox__label),
|
||||
.navds-radio--readonly > :where(.navds-radio__input, .navds-radio__label) {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.navds-checkbox--readonly .navds-checkbox__label-text {
|
||||
display: inline-flex;
|
||||
}
|
||||
|
||||
.navds-checkbox--readonly > .navds-checkbox__input:hover + .navds-checkbox__label,
|
||||
.navds-radio--readonly > .navds-radio__input:hover + .navds-radio__label {
|
||||
color: var(--a-text-default);
|
||||
}
|
||||
|
||||
.navds-checkbox--readonly
|
||||
> .navds-checkbox__input:not(:disabled):not(:checked):not(:indeterminate)
|
||||
+ .navds-checkbox__label::before,
|
||||
.navds-checkbox--readonly
|
||||
> .navds-checkbox__input:hover:not(:checked):not(:indeterminate):not(:focus-visible)
|
||||
+ .navds-checkbox__label::before,
|
||||
.navds-radio--readonly > .navds-radio__input:not(:disabled):not(:checked):not(:indeterminate) + .navds-radio__label::before,
|
||||
.navds-radio--readonly
|
||||
> .navds-radio__input:hover:not(:checked):not(:indeterminate):not(:focus-visible)
|
||||
+ .navds-radio__label::before {
|
||||
background-color: var(--__ac-radio-checkbox-readonly-bg);
|
||||
box-shadow: inset 0 0 0 2px var(--__ac-radio-checkbox-readonly-border);
|
||||
}
|
||||
|
||||
.navds-checkbox--readonly > .navds-checkbox__input:focus-visible + .navds-checkbox__label::before,
|
||||
.navds-radio--readonly > .navds-radio__input:focus-visible + .navds-radio__label::before {
|
||||
--__ac-radio-checkbox-readonly-border: var(--a-border-subtle), var(--a-shadow-focus);
|
||||
}
|
||||
|
||||
.navds-checkbox--readonly > .navds-checkbox__input:checked + .navds-checkbox__label::before {
|
||||
background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMyAxMCI+ICAgIDxnPiAgICA8cGF0aCBmaWxsPSJyZ2JhKDAsIDAsIDAsIDAuNjUpIiBkPSJNNCwxMGMtMC40LDAtMC44LTAuMS0xLjEtMC40TDAuNCw3LjFDMC4xLDYuOCwwLDYuNCwwLDZzMC4yLTAuOCwwLjUtMS4xQzEsNC40LDIsNC40LDIuNSw0LjlMNCw2LjRsNi40LTYgICAgQzEwLjgsMC4xLDExLjEsMCwxMS41LDBjMC40LDAsMC44LDAuMiwxLDAuNWMwLjYsMC42LDAuNSwxLjYtMC4xLDIuMXYwTDUsOS42QzQuNyw5LjksNC40LDEwLDQsMTB6IE0xMS44LDEuOUwxMS44LDEuOSAgICBDMTEuOCwxLjksMTEuOCwxLjksMTEuOCwxLjl6IE0xMS4yLDEuMUMxMS4yLDEuMSwxMS4yLDEuMSwxMS4yLDEuMUwxMS4yLDEuMXoiLz4gICAgPC9nPjwvc3ZnPg==);
|
||||
box-shadow: inset 0 0 0 2px var(--__ac-radio-checkbox-readonly-border);
|
||||
background-color: var(--__ac-radio-checkbox-readonly-bg);
|
||||
}
|
||||
|
||||
.navds-radio--readonly > .navds-radio__input:checked + .navds-radio__label::before {
|
||||
box-shadow: inset 0 0 0 2px var(--__ac-radio-checkbox-readonly-border), inset 0 0 0 4px var(--__ac-radio-checkbox-readonly-bg);
|
||||
background-color: var(--a-icon-subtle);
|
||||
}
|
||||
|
||||
.navds-checkbox--readonly > .navds-checkbox__input:indeterminate + .navds-checkbox__label::before {
|
||||
box-shadow: inset 0 0 0 2px var(--__ac-radio-checkbox-readonly-border);
|
||||
background-color: var(--__ac-radio-checkbox-readonly-bg);
|
||||
}
|
||||
|
||||
.navds-checkbox--readonly > .navds-checkbox__input:indeterminate + .navds-checkbox__label::after {
|
||||
background-color: var(--a-icon-subtle);
|
||||
}
|
||||
@@ -104,8 +104,8 @@
|
||||
|
||||
.navds-search__button-search {
|
||||
flex-shrink: 0;
|
||||
min-width: 64px;
|
||||
min-height: 32px;
|
||||
min-width: 4rem;
|
||||
min-height: 2rem;
|
||||
border-radius: 0;
|
||||
border-top-right-radius: var(--a-border-radius-medium);
|
||||
border-bottom-right-radius: var(--a-border-radius-medium);
|
||||
@@ -116,7 +116,7 @@
|
||||
}
|
||||
|
||||
.navds-form-field--small .navds-search__button-search {
|
||||
min-width: 40px;
|
||||
min-width: 2.5rem;
|
||||
}
|
||||
|
||||
.navds-search__button-search.navds-button--secondary {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
color: var(--ac-select-text, var(--a-text-default));
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
min-height: 48px;
|
||||
min-height: 3rem;
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
padding: 0.5rem;
|
||||
@@ -45,7 +45,7 @@
|
||||
}
|
||||
|
||||
.navds-form-field--small .navds-select__input {
|
||||
min-height: 32px;
|
||||
min-height: 2rem;
|
||||
padding: 0 2rem 0 0.25rem;
|
||||
}
|
||||
|
||||
@@ -79,3 +79,9 @@
|
||||
.navds-select__input:disabled > option {
|
||||
color: var(--a-text-default);
|
||||
}
|
||||
|
||||
.navds-select--readonly .navds-select__input {
|
||||
background-color: var(--a-surface-subtle);
|
||||
border-color: var(--a-border-subtle);
|
||||
cursor: default;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
.navds-switch {
|
||||
position: relative;
|
||||
min-height: 48px;
|
||||
min-height: 3rem;
|
||||
width: fit-content;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
.navds-switch--small {
|
||||
position: relative;
|
||||
min-height: 32px;
|
||||
min-height: 2rem;
|
||||
}
|
||||
|
||||
/* Input */
|
||||
@@ -18,14 +18,14 @@
|
||||
cursor: pointer;
|
||||
position: absolute;
|
||||
z-index: 1;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
width: 3rem;
|
||||
height: 3rem;
|
||||
opacity: 0;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
.navds-switch--small > .navds-switch__input {
|
||||
height: 32px;
|
||||
height: 2rem;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
@@ -47,11 +47,11 @@
|
||||
}
|
||||
|
||||
.navds-switch--small > .navds-switch__label-wrapper > .navds-switch__content {
|
||||
padding: calc(var(--a-spacing-2) - 2px) 0 calc(var(--a-spacing-2) - 2px) 3.25rem;
|
||||
padding: calc(var(--a-spacing-2) - var(--a-spacing-05)) 0 calc(var(--a-spacing-2) - var(--a-spacing-05)) 3.25rem;
|
||||
}
|
||||
|
||||
.navds-switch--right.navds-switch--small > .navds-switch__label-wrapper > .navds-switch__content {
|
||||
padding: calc(var(--a-spacing-2) - 2px) 3.25rem calc(var(--a-spacing-2) - 2px) 0;
|
||||
padding: calc(var(--a-spacing-2) - var(--a-spacing-05)) 3.25rem calc(var(--a-spacing-2) - var(--a-spacing-05)) 0;
|
||||
}
|
||||
|
||||
.navds-switch--with-description,
|
||||
@@ -70,8 +70,8 @@
|
||||
|
||||
/* Track */
|
||||
.navds-switch__track {
|
||||
width: 44px;
|
||||
height: 24px;
|
||||
width: 2.75rem;
|
||||
height: 1.5rem;
|
||||
background-color: var(--ac-switch-bg, var(--a-surface-neutral));
|
||||
position: absolute;
|
||||
top: var(--a-spacing-3);
|
||||
@@ -125,12 +125,12 @@
|
||||
background-color: var(--ac-switch-thumb-bg, var(--a-surface-default));
|
||||
color: var(--ac-switch-thumb-icon, var(--a-icon-subtle));
|
||||
border-radius: var(--a-border-radius-full);
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
width: 1.25rem;
|
||||
height: 1.25rem;
|
||||
position: absolute;
|
||||
transform: translateX(0);
|
||||
left: 2px;
|
||||
top: 2px;
|
||||
left: var(--a-spacing-05);
|
||||
top: var(--a-spacing-05);
|
||||
transition: transform 250ms cubic-bezier(0.4, 0, 0.2, 1);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -138,17 +138,17 @@
|
||||
}
|
||||
|
||||
.navds-switch__input:checked ~ .navds-switch__track > .navds-switch__thumb {
|
||||
transform: translateX(20px);
|
||||
transform: translateX(1.25rem);
|
||||
color: var(--ac-switch-thumb-icon-checked, var(--a-icon-success));
|
||||
}
|
||||
|
||||
@media (hover: hover) and (pointer: fine) {
|
||||
.navds-switch__input:hover ~ .navds-switch__track > .navds-switch__thumb {
|
||||
transform: translateX(2px);
|
||||
transform: translateX(0.125rem);
|
||||
}
|
||||
|
||||
.navds-switch__input:checked:hover ~ .navds-switch__track > .navds-switch__thumb {
|
||||
transform: translateX(18px);
|
||||
transform: translateX(1.125rem);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@
|
||||
}
|
||||
|
||||
.navds-switch__input:checked:disabled:hover ~ .navds-switch__track > .navds-switch__thumb {
|
||||
transform: translateX(20px);
|
||||
transform: translateX(1.25rem);
|
||||
}
|
||||
|
||||
/* Loader */
|
||||
@@ -178,3 +178,44 @@
|
||||
.navds-switch__input:disabled ~ .navds-switch__label-wrapper {
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
/* Readonly */
|
||||
.navds-switch--readonly > .navds-switch__track,
|
||||
.navds-switch--readonly > .navds-switch__input:hover ~ .navds-switch__track,
|
||||
.navds-switch--readonly > .navds-switch__input:checked ~ .navds-switch__track,
|
||||
.navds-switch--readonly > .navds-switch__input:checked:hover ~ .navds-switch__track {
|
||||
background-color: var(--a-surface-neutral-moderate);
|
||||
}
|
||||
|
||||
.navds-switch--readonly > .navds-switch__label-wrapper,
|
||||
.navds-switch--readonly > .navds-switch__input {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.navds-switch--readonly > .navds-switch__input:hover ~ .navds-switch__label-wrapper,
|
||||
.navds-switch--readonly .navds-switch__label-wrapper:hover {
|
||||
color: var(--a-text-default);
|
||||
}
|
||||
|
||||
.navds-switch--readonly .navds-switch__label {
|
||||
display: inline-flex;
|
||||
}
|
||||
|
||||
.navds-switch--readonly .navds-switch__thumb {
|
||||
background-color: var(--a-surface-subtle);
|
||||
box-shadow: 0 0 0 2px var(--a-border-default);
|
||||
}
|
||||
|
||||
.navds-switch--readonly > .navds-switch__input:checked ~ .navds-switch__track > .navds-switch__thumb {
|
||||
color: var(--a-icon-subtle);
|
||||
}
|
||||
|
||||
@media (hover: hover) and (pointer: fine) {
|
||||
.navds-switch--readonly > .navds-switch__input:hover ~ .navds-switch__track > .navds-switch__thumb {
|
||||
transform: translateX(0);
|
||||
}
|
||||
|
||||
.navds-switch--readonly > .navds-switch__input:checked:hover ~ .navds-switch__track > .navds-switch__thumb {
|
||||
transform: translateX(1.25rem);
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@
|
||||
background-color: var(--ac-textfield-bg, var(--a-surface-default));
|
||||
border-radius: var(--a-border-radius-medium);
|
||||
border: 1px solid var(--ac-textfield-border, var(--a-border-default));
|
||||
min-height: 48px;
|
||||
min-height: 3rem;
|
||||
width: 100%;
|
||||
color: var(--ac-textfield-text, var(--a-text-default));
|
||||
}
|
||||
@@ -27,8 +27,8 @@
|
||||
}
|
||||
|
||||
.navds-form-field--small .navds-text-field__input {
|
||||
padding: 0 0.5rem;
|
||||
min-height: 32px;
|
||||
padding: 0 var(--a-spacing-2);
|
||||
min-height: 2rem;
|
||||
}
|
||||
|
||||
.navds-text-field__input:hover {
|
||||
@@ -73,11 +73,10 @@
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.navds-text-field__input[readonly] {
|
||||
background-color: var(--ac-textfield-bg, var(--a-surface-default));
|
||||
border-color: var(--ac-textfield-border, var(--a-border-default));
|
||||
box-shadow: none;
|
||||
cursor: not-allowed;
|
||||
.navds-text-field--readonly .navds-text-field__input {
|
||||
background-color: var(--a-surface-subtle);
|
||||
border-color: var(--a-border-subtle);
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
}
|
||||
|
||||
.navds-form-field--small .navds-textarea__input {
|
||||
padding: 6px;
|
||||
padding: 0.375rem;
|
||||
}
|
||||
|
||||
.navds-form-field--small .navds-textarea--counter.navds-textarea__input {
|
||||
@@ -64,8 +64,8 @@
|
||||
font-style: italic;
|
||||
position: absolute;
|
||||
text-align: left;
|
||||
left: 1px;
|
||||
bottom: 1px;
|
||||
left: 0.0625rem;
|
||||
bottom: 0.0625rem;
|
||||
padding: var(--a-spacing-1) var(--a-spacing-2);
|
||||
}
|
||||
|
||||
@@ -99,9 +99,8 @@
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.navds-textarea__input[readonly] {
|
||||
background-color: var(--ac-textarea-bg, var(--a-surface-default));
|
||||
border-color: var(--ac-textarea-border, var(--a-border-default));
|
||||
box-shadow: none;
|
||||
cursor: not-allowed;
|
||||
.navds-textarea--readonly .navds-textarea__input {
|
||||
background-color: var(--a-surface-subtle);
|
||||
border-color: var(--a-border-subtle);
|
||||
cursor: default;
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
.navds-hgrid {
|
||||
--__ac-hgrid-columns-xs: initial;
|
||||
--__ac-hgrid-columns-sm: initial;
|
||||
--__ac-hgrid-columns-md: initial;
|
||||
--__ac-hgrid-columns-lg: initial;
|
||||
--__ac-hgrid-columns-xl: initial;
|
||||
--__ac-hgrid-columns: var(--__ac-hgrid-columns-xs);
|
||||
--__ac-hgrid-gap-xs: initial;
|
||||
--__ac-hgrid-gap-sm: initial;
|
||||
--__ac-hgrid-gap-md: initial;
|
||||
--__ac-hgrid-gap-lg: initial;
|
||||
--__ac-hgrid-gap-xl: initial;
|
||||
--__ac-hgrid-gap: var(--__ac-hgrid-gap-xs);
|
||||
|
||||
display: grid;
|
||||
grid-template-columns: var(--__ac-hgrid-columns);
|
||||
gap: var(--__ac-hgrid-gap);
|
||||
}
|
||||
|
||||
@media (min-width: 480px) {
|
||||
.navds-hgrid {
|
||||
--__ac-hgrid-columns: var(--__ac-hgrid-columns-sm, var(--__ac-hgrid-columns-xs));
|
||||
--__ac-hgrid-gap: var(--__ac-hgrid-gap-sm, var(--__ac-hgrid-gap-xs));
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.navds-hgrid {
|
||||
--__ac-hgrid-columns: var(--__ac-hgrid-columns-md, var(--__ac-hgrid-columns-sm, var(--__ac-hgrid-columns-xs)));
|
||||
--__ac-hgrid-gap: var(--__ac-hgrid-gap-md, var(--__ac-hgrid-gap-sm, var(--__ac-hgrid-gap-xs)));
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 1024px) {
|
||||
.navds-hgrid {
|
||||
--__ac-hgrid-columns: var(
|
||||
--__ac-hgrid-columns-lg,
|
||||
var(--__ac-hgrid-columns-md, var(--__ac-hgrid-columns-sm, var(--__ac-hgrid-columns-xs)))
|
||||
);
|
||||
--__ac-hgrid-gap: var(--__ac-hgrid-gap-lg, var(--__ac-hgrid-gap-md, var(--__ac-hgrid-gap-sm, var(--__ac-hgrid-gap-xs))));
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 1280px) {
|
||||
.navds-hgrid {
|
||||
--__ac-hgrid-columns: var(
|
||||
--__ac-hgrid-columns-xl,
|
||||
var(--__ac-hgrid-columns-lg, var(--__ac-hgrid-columns-md, var(--__ac-hgrid-columns-sm, var(--__ac-hgrid-columns-xs))))
|
||||
);
|
||||
--__ac-hgrid-gap: var(
|
||||
--__ac-hgrid-gap-xl,
|
||||
var(--__ac-hgrid-gap-lg, var(--__ac-hgrid-gap-md, var(--__ac-hgrid-gap-sm, var(--__ac-hgrid-gap-xs))))
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@
|
||||
@import "guide-panel.css";
|
||||
@import "form/index.css";
|
||||
@import "help-text.css";
|
||||
@import "hgrid.css";
|
||||
@import "internalheader.css";
|
||||
@import "link.css";
|
||||
@import "loader.css";
|
||||
@@ -29,6 +30,7 @@
|
||||
@import "link-panel.css";
|
||||
@import "read-more.css";
|
||||
@import "skeleton.css";
|
||||
@import "stack.css";
|
||||
@import "stepper.css";
|
||||
@import "table.css";
|
||||
@import "tabs.css";
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
display: flex;
|
||||
align-self: stretch;
|
||||
background: var(--ac-internalheader-bg, var(--a-surface-inverted));
|
||||
min-height: var(--a-spacing-12);
|
||||
min-height: 3rem;
|
||||
|
||||
--navds-internalheader-focus: inset 0 0 0 2px var(--a-border-focus-on-inverted);
|
||||
}
|
||||
|
||||
@@ -6,15 +6,35 @@
|
||||
gap: var(--a-spacing-1);
|
||||
}
|
||||
|
||||
.navds-alert .navds-link,
|
||||
.navds-confirmation-panel .navds-link {
|
||||
color: var(--a-text-default);
|
||||
.navds-link.navds-link--inline-text {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.navds-link.navds-link--inline-text > svg {
|
||||
/* stylelint-disable-next-line plugin/declaration-block-no-ignored-properties */
|
||||
margin: 0.1em 0.1em -0.1em;
|
||||
transform: translateY(0.05em);
|
||||
display: inline;
|
||||
vertical-align: baseline;
|
||||
}
|
||||
|
||||
.navds-link:hover {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.navds-link.navds-link--remove-underline {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.navds-link.navds-link--remove-underline:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.navds-alert .navds-link,
|
||||
.navds-confirmation-panel .navds-link {
|
||||
color: var(--a-text-default);
|
||||
}
|
||||
|
||||
.navds-link:focus-visible {
|
||||
outline: none;
|
||||
color: var(--ac-link-focus-text, var(--a-text-on-action));
|
||||
@@ -45,3 +65,15 @@
|
||||
color: inherit;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.navds-link--action {
|
||||
color: var(--ac-link-action-text, var(--a-text-action));
|
||||
}
|
||||
|
||||
.navds-link--neutral {
|
||||
color: var(--ac-link-neutral-text, var(--a-text-default));
|
||||
}
|
||||
|
||||
.navds-link--subtle {
|
||||
color: var(--ac-link-subtle-text, var(--a-text-subtle));
|
||||
}
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
.navds-list .navds-list__item-marker--bullet {
|
||||
display: flex;
|
||||
margin-top: 6px;
|
||||
margin-top: 0.375rem;
|
||||
grid-column: 1 / 2;
|
||||
/* stylelint-disable-next-line csstools/value-no-unknown-custom-properties */
|
||||
color: var(--ac-list-marker-ul-color, var(--ac-list-marker-color, var(--a-icon-default)));
|
||||
@@ -43,6 +43,13 @@
|
||||
.navds-list__item-marker--icon {
|
||||
/* stylelint-disable-next-line csstools/value-no-unknown-custom-properties */
|
||||
color: var(--ac-list-marker-icon-color, var(--ac-list-marker-color, var(--a-icon-default)));
|
||||
display: flex;
|
||||
align-items: center;
|
||||
height: var(--a-font-line-height-medium);
|
||||
}
|
||||
|
||||
.navds-list__item-marker--icon svg {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.navds-list ul .navds-list__item-content {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@navikt/ds-css",
|
||||
"version": "4.4.1",
|
||||
"version": "4.11.2",
|
||||
"description": "CSS for NAV Designsystem",
|
||||
"author": "Aksel | NAV designsystem team",
|
||||
"keywords": [
|
||||
@@ -27,11 +27,11 @@
|
||||
"css:get-version": "node config/get-version.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@navikt/ds-tokens": "^4.4.1",
|
||||
"@navikt/ds-tokens": "^4.11.2",
|
||||
"cssnano": "6.0.0",
|
||||
"fast-glob": "3.2.11",
|
||||
"lodash": "4.17.21",
|
||||
"nodemon": "^2.0.12",
|
||||
"nodemon": "^3.0.1",
|
||||
"normalize.css": "^8.0.1",
|
||||
"postcss": "^8.4.0",
|
||||
"postcss-cli": "^9.0.0",
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
gap: var(--a-spacing-05);
|
||||
color: var(--ac-read-more-text, var(--a-text-action));
|
||||
border-radius: var(--a-border-radius-small);
|
||||
padding: var(--a-spacing-1) var(--a-spacing-1) var(--a-spacing-1) 2px;
|
||||
padding: var(--a-spacing-1) var(--a-spacing-1) var(--a-spacing-1) var(--a-spacing-05);
|
||||
text-align: start;
|
||||
}
|
||||
|
||||
.navds-read-more--small .navds-read-more__button {
|
||||
padding: 2px var(--a-spacing-1) 2px 2px;
|
||||
padding: var(--a-spacing-05) var(--a-spacing-1) var(--a-spacing-05) var(--a-spacing-05);
|
||||
}
|
||||
|
||||
.navds-read-more__button:hover {
|
||||
@@ -39,14 +39,14 @@
|
||||
.navds-read-more__content {
|
||||
margin-top: var(--a-spacing-1);
|
||||
border-left: 2px solid var(--ac-read-more-line, var(--a-border-divider));
|
||||
margin-left: 13px;
|
||||
padding-left: 13px;
|
||||
margin-left: 0.8125rem;
|
||||
padding-left: 0.8125rem;
|
||||
color: var(--a-text-default);
|
||||
}
|
||||
|
||||
.navds-read-more--small .navds-read-more__content {
|
||||
margin-left: 11px;
|
||||
padding-left: 11px;
|
||||
margin-left: 0.6875rem;
|
||||
padding-left: 0.6875rem;
|
||||
}
|
||||
|
||||
.navds-read-more__content--closed {
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
.navds-stack {
|
||||
--__ac-stack-align: initial;
|
||||
--__ac-stack-justify: initial;
|
||||
--__ac-stack-direction: initial;
|
||||
--__ac-stack-wrap: initial;
|
||||
--__ac-stack-gap-xs: initial;
|
||||
--__ac-stack-gap-sm: initial;
|
||||
--__ac-stack-gap-md: initial;
|
||||
--__ac-stack-gap-lg: initial;
|
||||
--__ac-stack-gap-xl: initial;
|
||||
--__ac-stack-gap: var(--__ac-stack-gap-xs);
|
||||
|
||||
gap: var(--__ac-stack-gap);
|
||||
display: flex;
|
||||
align-items: var(--__ac-stack-align);
|
||||
justify-content: var(--__ac-stack-justify);
|
||||
flex-flow: var(--__ac-stack-direction) var(--__ac-stack-wrap);
|
||||
}
|
||||
|
||||
.navds-stack__spacer {
|
||||
flex: 1;
|
||||
justify-self: stretch;
|
||||
align-self: stretch;
|
||||
}
|
||||
|
||||
.navds-stack > .navds-stack__spacer {
|
||||
margin-block-start: calc(var(--__ac-stack-gap) * -1);
|
||||
}
|
||||
|
||||
.navds-hstack > .navds-stack__spacer {
|
||||
margin-inline-start: calc(var(--__ac-stack-gap) * -1);
|
||||
}
|
||||
|
||||
@media (min-width: 480px) {
|
||||
.navds-stack {
|
||||
--__ac-stack-gap: var(--__ac-stack-gap-sm, var(--__ac-stack-gap-xs));
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.navds-stack {
|
||||
--__ac-stack-gap: var(--__ac-stack-gap-md, var(--__ac-stack-gap-sm, var(--__ac-stack-gap-xs)));
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 1024px) {
|
||||
.navds-stack {
|
||||
--__ac-stack-gap: var(--__ac-stack-gap-lg, var(--__ac-stack-gap-md, var(--__ac-stack-gap-sm, var(--__ac-stack-gap-xs))));
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 1280px) {
|
||||
.navds-stack {
|
||||
--__ac-stack-gap: var(
|
||||
--__ac-stack-gap-xl,
|
||||
var(--__ac-stack-gap-lg, var(--__ac-stack-gap-md, var(--__ac-stack-gap-sm, var(--__ac-stack-gap-xs))))
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,10 @@
|
||||
background-color: var(--ac-stepper-line-completed, var(--a-border-selected));
|
||||
}
|
||||
|
||||
.navds-stepper__item--behind.navds-stepper__item--completed + .navds-stepper__item > .navds-stepper__line--1 {
|
||||
background-color: var(--ac-stepper-line-completed, var(--a-border-selected));
|
||||
}
|
||||
|
||||
.navds-stepper__line--1 {
|
||||
grid-row: line-1;
|
||||
display: none;
|
||||
@@ -109,7 +113,7 @@ button.navds-stepper__step {
|
||||
.navds-stepper__circle--success {
|
||||
border: none;
|
||||
background: none;
|
||||
font-size: 28px;
|
||||
font-size: 1.75rem;
|
||||
color: var(--a-text-on-action);
|
||||
background-color: var(--ac-stepper-text, var(--a-surface-action));
|
||||
}
|
||||
@@ -213,6 +217,12 @@ button.navds-stepper__step {
|
||||
background-color: var(--ac-stepper-non-interactive-line-completed, var(--a-border-strong));
|
||||
}
|
||||
|
||||
.navds-stepper__item--non-interactive.navds-stepper__item--behind.navds-stepper__item--completed
|
||||
+ .navds-stepper__item
|
||||
> .navds-stepper__line--1 {
|
||||
background-color: var(--ac-stepper-non-interactive-line-completed, var(--a-border-strong));
|
||||
}
|
||||
|
||||
:where(.navds-stepper__step--non-interactive.navds-stepper__step--active) .navds-stepper__circle {
|
||||
background-color: var(--ac-stepper-non-interactive-active-bg, var(--a-surface-inverted));
|
||||
border-color: var(--ac-stepper-non-interactive-active-border, var(--a-surface-inverted));
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
display: table-row;
|
||||
}
|
||||
|
||||
.navds-table__body .navds-table__row--shade-on-hover:hover {
|
||||
.navds-table__body .navds-table__row--shade-on-hover:not(.navds-table__expandable-row--expansion-disabled):hover {
|
||||
background-color: var(--ac-table-row-hover, var(--a-bg-subtle));
|
||||
}
|
||||
|
||||
@@ -80,11 +80,11 @@
|
||||
}
|
||||
|
||||
.navds-table .navds-checkbox .navds-checkbox__input {
|
||||
top: -12px;
|
||||
top: -0.75rem;
|
||||
}
|
||||
|
||||
.navds-table .navds-checkbox--small .navds-checkbox__input {
|
||||
top: -6px;
|
||||
top: -0.375rem;
|
||||
}
|
||||
|
||||
.navds-table .navds-checkbox .navds-checkbox__label {
|
||||
@@ -154,6 +154,10 @@
|
||||
transition: border-bottom-color 190ms cubic-bezier(0.6, 0.04, 0.98, 0.335);
|
||||
}
|
||||
|
||||
.navds-table__expandable-row:not(.navds-table__expandable-row--expansion-disabled):hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.navds-table__expandable-row--open .navds-table__data-cell {
|
||||
border-bottom-color: transparent;
|
||||
}
|
||||
@@ -168,12 +172,12 @@
|
||||
|
||||
.navds-table__toggle-expand-cell {
|
||||
padding: 0;
|
||||
width: 56px;
|
||||
width: 3.5rem;
|
||||
}
|
||||
|
||||
.navds-table--small .navds-table__toggle-expand-cell {
|
||||
padding: 0;
|
||||
width: 36px;
|
||||
width: 2.25rem;
|
||||
}
|
||||
|
||||
.navds-table__toggle-expand-button {
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
.navds-tabs__scroll-button {
|
||||
padding: var(--a-spacing-3) var(--a-spacing-4);
|
||||
width: 44px;
|
||||
width: 2.75rem;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
@@ -38,11 +38,11 @@
|
||||
|
||||
.navds-tabs--small .navds-tabs__scroll-button {
|
||||
padding: 0.375rem var(--a-spacing-4);
|
||||
width: 32px;
|
||||
width: 2rem;
|
||||
}
|
||||
|
||||
.navds-tabs__tab {
|
||||
min-height: 48px;
|
||||
min-height: 3rem;
|
||||
padding: var(--a-spacing-3) var(--a-spacing-4);
|
||||
display: inline-flex;
|
||||
justify-content: center;
|
||||
@@ -92,7 +92,7 @@
|
||||
}
|
||||
|
||||
.navds-tabs__tab--small {
|
||||
min-height: 32px;
|
||||
min-height: 2rem;
|
||||
padding: 0.375rem var(--a-spacing-4);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,17 +5,17 @@
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: var(--a-spacing-05) var(--a-spacing-2);
|
||||
min-height: 32px;
|
||||
min-height: 2rem;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.navds-tag--small {
|
||||
min-height: 24px;
|
||||
min-height: 1.5rem;
|
||||
padding: 0 0.375rem;
|
||||
}
|
||||
|
||||
.navds-tag--xsmall {
|
||||
min-height: 20px;
|
||||
min-height: 1.25rem;
|
||||
padding: 0 var(--a-spacing-1);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
height: 1rem;
|
||||
box-sizing: content-box;
|
||||
grid-column: 2;
|
||||
margin-bottom: var(--a-spacing-1);
|
||||
}
|
||||
|
||||
.navds-timeline__row-label {
|
||||
@@ -181,7 +182,7 @@
|
||||
0 0 0 4px var(--ac-timeline-pin-bg, var(--a-surface-danger)), 0 0 0 5px var(--a-surface-default);
|
||||
z-index: 2;
|
||||
border-radius: var(--a-border-radius-full);
|
||||
padding: 3.5px;
|
||||
padding: var(--a-spacing-1);
|
||||
position: relative;
|
||||
}
|
||||
|
||||
@@ -232,7 +233,7 @@
|
||||
.navds-timeline__pin-wrapper::before {
|
||||
content: "";
|
||||
top: var(--navdsc-timeline-pin-size);
|
||||
height: calc(94% - var(--navdsc-timeline-pin-size));
|
||||
height: calc(88% - var(--navdsc-timeline-pin-size));
|
||||
width: 1px;
|
||||
margin: 0 auto;
|
||||
background: var(--a-surface-inverted);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
border-radius: var(--a-border-radius-medium);
|
||||
background-color: var(--ac-toggle-group-bg, var(--a-surface-transparent));
|
||||
box-shadow: inset 0 0 0 1px var(--ac-toggle-group-border, var(--a-border-default));
|
||||
padding: calc(var(--a-spacing-1) + 1px);
|
||||
padding: calc(var(--a-spacing-1) + 0.0625rem);
|
||||
gap: var(--a-spacing-1);
|
||||
display: inline-grid;
|
||||
grid-auto-flow: column;
|
||||
@@ -16,7 +16,7 @@
|
||||
}
|
||||
|
||||
.navds-toggle-group--small {
|
||||
padding: calc(var(--a-spacing-05) + 1px);
|
||||
padding: calc(var(--a-spacing-05) + 0.0625rem);
|
||||
}
|
||||
|
||||
.navds-toggle-group--neutral {
|
||||
@@ -29,12 +29,12 @@
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: var(--a-spacing-1) var(--a-spacing-3);
|
||||
min-height: 38px;
|
||||
min-height: 2.375rem;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
background-color: var(--ac-toggle-group-button-bg, var(--a-surface-transparent));
|
||||
color: var(--ac-toggle-group-button-text, var(--a-text-default));
|
||||
border-radius: 2px;
|
||||
border-radius: var(--a-border-radius-small);
|
||||
min-width: fit-content;
|
||||
font-weight: var(--a-font-weight-regular);
|
||||
}
|
||||
@@ -113,7 +113,6 @@
|
||||
.navds-toggle-group__button[aria-checked="true"] {
|
||||
background-color: var(--ac-toggle-group-selected-bg, var(--a-surface-action-selected));
|
||||
color: var(--ac-toggle-group-selected-text, var(--a-text-on-action));
|
||||
font-weight: var(--a-font-weight-bold);
|
||||
}
|
||||
|
||||
.navds-toggle-group--neutral > .navds-toggle-group__button[aria-pressed="true"],
|
||||
@@ -124,7 +123,7 @@
|
||||
|
||||
.navds-toggle-group--small > .navds-toggle-group__button {
|
||||
padding: var(--a-spacing-05) var(--a-spacing-3);
|
||||
min-height: 26px;
|
||||
min-height: 1.625rem;
|
||||
min-width: fit-content;
|
||||
}
|
||||
|
||||
|
||||
@@ -175,7 +175,10 @@
|
||||
"--ac-link-focus-border": "--a-border-focus",
|
||||
"--ac-link-active-text": "--a-text-on-action",
|
||||
"--ac-link-active-bg": "--a-border-focus",
|
||||
"--ac-link-active-border": "--a-border-focus"
|
||||
"--ac-link-active-border": "--a-border-focus",
|
||||
"--ac-link-action-text": "--a-text-action",
|
||||
"--ac-link-neutral-text": "--a-text-default",
|
||||
"--ac-link-subtle-text": "--a-text-subtle"
|
||||
},
|
||||
"list": {
|
||||
"--ac-list-marker-ul-color": "--ac-list-marker-color",
|
||||
@@ -372,6 +375,21 @@
|
||||
"--ac-search-button-focus-active-border": "--a-surface-default",
|
||||
"--ac-search-error-border": "--a-border-danger"
|
||||
},
|
||||
"combobox": {
|
||||
"--ac-combobox-clear-icon": "--a-text-subtle",
|
||||
"--ac-combobox-clear-icon-hover": "--a-text-action-selected",
|
||||
"--ac-combobox-clear-icon-active": "--a-text-action",
|
||||
"--ac-combobox-list-bg": "--a-surface-default",
|
||||
"--ac-combobox-list-text": "--a-text-default",
|
||||
"--ac-combobox-list-border-color": "--a-border-divider",
|
||||
"--ac-combobox-list-item-bg": "--a-surface-default",
|
||||
"--ac-combobox-list-item-hover-bg": "--a-surface-hover",
|
||||
"--ac-combobox-list-item-selected-bg": "--a-surface-default",
|
||||
"--ac-combobox-list-item-selected-hover-bg": "--a-surface-action-subtle-hover",
|
||||
"--ac-combobox-list-item-loading-bg": "--a-surface-default",
|
||||
"--ac-combobox-list-item-hover-border-left": "--a-border-strong",
|
||||
"--ac-combobox-list-item-selected-hover-border-left": "--a-border-focus"
|
||||
},
|
||||
"select": {
|
||||
"--ac-select-bg": "--a-surface-default",
|
||||
"--ac-select-text": "--a-text-default",
|
||||
|
||||
@@ -25,8 +25,8 @@
|
||||
}
|
||||
|
||||
.navds-tooltip__arrow {
|
||||
height: 7px;
|
||||
width: 7px;
|
||||
height: 0.4375rem;
|
||||
width: 0.4375rem;
|
||||
transform: rotate(45deg);
|
||||
z-index: -1;
|
||||
background-color: var(--ac-tooltip-bg, var(--a-surface-inverted));
|
||||
@@ -45,8 +45,8 @@
|
||||
color: var(--ac-tooltip-key-text, var(--a-text-on-inverted));
|
||||
border-radius: var(--a-border-radius-small);
|
||||
padding: 0 var(--a-spacing-1);
|
||||
min-width: 18px;
|
||||
height: 18px;
|
||||
min-width: 1.125rem;
|
||||
height: 1.125rem;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
@@ -1,5 +1,183 @@
|
||||
# @navikt/ds-react
|
||||
|
||||
## 4.11.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @navikt/aksel-icons@4.11.2
|
||||
|
||||
## 4.11.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @navikt/aksel-icons@4.11.1
|
||||
|
||||
## 4.11.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- HGrid: Ny komponent 'HGrid' er ute i Beta: [Dokumentasjon](https://aksel.nav.no/komponenter/core/hgrid) ([#1838](https://github.com/navikt/aksel/pull/1838))
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Fixes bug where combobox list could not be closed after clicking a chip ([#2155](https://github.com/navikt/aksel/pull/2155))
|
||||
|
||||
- Grid: Markert som deprecated. Bruk nye 'HGrid' ([#2153](https://github.com/navikt/aksel/pull/2153))
|
||||
|
||||
- Updated dependencies []:
|
||||
- @navikt/aksel-icons@4.11.0
|
||||
|
||||
## 4.10.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @navikt/aksel-icons@4.10.2
|
||||
|
||||
## 4.10.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @navikt/aksel-icons@4.10.1
|
||||
|
||||
## 4.10.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- Link: La til 'variant', 'underline' og 'inlineText'-prop ([#2093](https://github.com/navikt/aksel/pull/2093))
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @navikt/aksel-icons@4.10.0
|
||||
|
||||
## 4.9.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Button: Fikset aria-live bug der knapp alltid ble lest opp av skjermleser ved render ([#2143](https://github.com/navikt/aksel/pull/2143))
|
||||
|
||||
- Tweaks to combobox - updated example, small bugfixes, better affordance for selected options and added flag for "isAddedByUser" to onToggleSelected ([#2144](https://github.com/navikt/aksel/pull/2144))
|
||||
|
||||
- Updated dependencies []:
|
||||
- @navikt/aksel-icons@4.9.1
|
||||
|
||||
## 4.9.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- Table: ExpandableRow kan nå åpnes med 'expandOnRowClick'-prop ([#2127](https://github.com/navikt/aksel/pull/2127))
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @navikt/aksel-icons@4.9.0
|
||||
|
||||
## 4.8.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- Nye komponenter `VStack`, `HStack` og `Spacer` for å enklere kunne lage layout med flexbox og spacing-variabler. ([#2040](https://github.com/navikt/aksel/pull/2040))
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @navikt/aksel-icons@4.8.0
|
||||
|
||||
## 4.7.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Textfield: La til type 'time' som tilgjengelig option ([#2137](https://github.com/navikt/aksel/pull/2137))
|
||||
|
||||
- Updated dependencies []:
|
||||
- @navikt/aksel-icons@4.7.4
|
||||
|
||||
## 4.7.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Chips: Removable Chips submitter ikke forms ved klikk lengre ([#2124](https://github.com/navikt/aksel/pull/2124))
|
||||
|
||||
- Updated dependencies []:
|
||||
- @navikt/aksel-icons@4.7.3
|
||||
|
||||
## 4.7.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Stepper: Fikset `hotizontal`-bug når step var `completed` ([#2116](https://github.com/navikt/aksel/pull/2116))
|
||||
|
||||
- Updated dependencies []:
|
||||
- @navikt/aksel-icons@4.7.2
|
||||
|
||||
## 4.7.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Datepicker: Fikset bug ved bruk dynamisk oppdatering av minDate. Vist `month` vil nå alltid være oppdatert når datepicker åpnes ([#2117](https://github.com/navikt/aksel/pull/2117))
|
||||
|
||||
- Updated dependencies []:
|
||||
- @navikt/aksel-icons@4.7.1
|
||||
|
||||
## 4.7.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- Ny komponent Combobox! ([#1868](https://github.com/navikt/aksel/pull/1868))
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Timeline: Har nå egen `axisLabelTemplates`-prop for axixlabel formatering ([#2109](https://github.com/navikt/aksel/pull/2109))
|
||||
|
||||
- Combobox post-release tweaks ([#2112](https://github.com/navikt/aksel/pull/2112))
|
||||
|
||||
- Updated dependencies []:
|
||||
- @navikt/aksel-icons@4.7.0
|
||||
|
||||
## 4.6.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Skjema: Labels og Legends bruker nå inline-flex når readOnly er satt ([#2089](https://github.com/navikt/aksel/pull/2089))
|
||||
|
||||
- Updated dependencies []:
|
||||
- @navikt/aksel-icons@4.6.1
|
||||
|
||||
## 4.6.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- Skjema: De fleste skjemakomponenter støtter nå `readOnly`-state ([#2080](https://github.com/navikt/aksel/pull/2080))
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @navikt/aksel-icons@4.6.0
|
||||
|
||||
## 4.5.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- - Alert: La til `closeButton`-prop ([#2079](https://github.com/navikt/aksel/pull/2079))
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @navikt/aksel-icons@4.5.0
|
||||
|
||||
## 4.4.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Textarea: Fikset i18n for counter ([`718b3204d`](https://github.com/navikt/aksel/commit/718b3204d8714c4fc515dcad484424214bdc0c77))
|
||||
|
||||
- Updated dependencies []:
|
||||
- @navikt/aksel-icons@4.4.2
|
||||
|
||||
## 4.4.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@navikt/ds-react",
|
||||
"version": "4.4.1",
|
||||
"version": "4.11.2",
|
||||
"description": "Aksel react-components for NAV designsystem",
|
||||
"author": "Aksel | NAV designsystem team",
|
||||
"license": "MIT",
|
||||
@@ -38,7 +38,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@floating-ui/react": "0.24.1",
|
||||
"@navikt/aksel-icons": "^4.4.1",
|
||||
"@navikt/aksel-icons": "^4.11.2",
|
||||
"@radix-ui/react-tabs": "1.0.0",
|
||||
"@radix-ui/react-toggle-group": "1.0.0",
|
||||
"clsx": "^1.2.1",
|
||||
|
||||
@@ -3,10 +3,12 @@ import {
|
||||
CheckmarkCircleFillIcon,
|
||||
ExclamationmarkTriangleFillIcon,
|
||||
XMarkOctagonFillIcon,
|
||||
XMarkIcon,
|
||||
} from "@navikt/aksel-icons";
|
||||
import cl from "clsx";
|
||||
import React, { forwardRef } from "react";
|
||||
import { BodyLong } from "../typography/BodyLong";
|
||||
import { Button } from "../button";
|
||||
|
||||
export interface AlertProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||
/**
|
||||
@@ -32,6 +34,17 @@ export interface AlertProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||
* @default false
|
||||
*/
|
||||
inline?: boolean;
|
||||
/**
|
||||
* Removes close-button(X) when false
|
||||
* Requires onClose to be set
|
||||
* @default true
|
||||
*/
|
||||
closeButton?: boolean;
|
||||
/**
|
||||
* Callback for alert wanting to close
|
||||
* requires closeButton to be true
|
||||
*/
|
||||
onClose?: () => void;
|
||||
}
|
||||
|
||||
const Icon = ({ variant, ...props }) => {
|
||||
@@ -71,27 +84,45 @@ export const Alert = forwardRef<HTMLDivElement, AlertProps>(
|
||||
size = "medium",
|
||||
fullWidth = false,
|
||||
inline = false,
|
||||
closeButton = false,
|
||||
onClose,
|
||||
...rest
|
||||
},
|
||||
ref
|
||||
) => (
|
||||
<div
|
||||
{...rest}
|
||||
ref={ref}
|
||||
className={cl(
|
||||
className,
|
||||
"navds-alert",
|
||||
`navds-alert--${variant}`,
|
||||
`navds-alert--${size}`,
|
||||
{ "navds-alert--full-width": fullWidth, "navds-alert--inline": inline }
|
||||
)}
|
||||
>
|
||||
<Icon variant={variant} className="navds-alert__icon" />
|
||||
<BodyLong as="div" size={size} className="navds-alert__wrapper">
|
||||
{children}
|
||||
</BodyLong>
|
||||
</div>
|
||||
)
|
||||
) => {
|
||||
return (
|
||||
<div
|
||||
{...rest}
|
||||
ref={ref}
|
||||
className={cl(
|
||||
className,
|
||||
"navds-alert",
|
||||
`navds-alert--${variant}`,
|
||||
`navds-alert--${size}`,
|
||||
{
|
||||
"navds-alert--full-width": fullWidth,
|
||||
"navds-alert--inline": inline,
|
||||
}
|
||||
)}
|
||||
>
|
||||
<Icon variant={variant} className="navds-alert__icon" />
|
||||
<BodyLong as="div" size={size} className="navds-alert__wrapper">
|
||||
{children}
|
||||
</BodyLong>
|
||||
{closeButton && !inline && (
|
||||
<div className="navds-alert__button-wrapper">
|
||||
<Button
|
||||
className="navds-alert__button"
|
||||
size="small"
|
||||
variant="tertiary-neutral"
|
||||
onClick={onClose}
|
||||
icon={<XMarkIcon title="Lukk Alert" />}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
export default Alert;
|
||||
@@ -2,6 +2,8 @@ import type { Meta, StoryObj } from "@storybook/react";
|
||||
import React from "react";
|
||||
import { Alert } from ".";
|
||||
import { BodyLong, Heading as DsHeading, Link } from "..";
|
||||
import { within, userEvent } from "@storybook/testing-library";
|
||||
import { expect } from "@storybook/jest";
|
||||
|
||||
const meta: Meta<typeof Alert> = {
|
||||
title: "ds-react/Alert",
|
||||
@@ -20,22 +22,14 @@ const variants: Array<"error" | "warning" | "info" | "success"> = [
|
||||
];
|
||||
|
||||
export const Default: Story = {
|
||||
render: (props) => (
|
||||
<Alert
|
||||
variant={props.variant}
|
||||
size={props.size}
|
||||
fullWidth={props.fullWidth}
|
||||
inline={props.inline}
|
||||
>
|
||||
{props.children}
|
||||
</Alert>
|
||||
),
|
||||
render: (props) => <Alert {...props} />,
|
||||
|
||||
args: {
|
||||
children: "Id elit esse enim reprehenderit enim nisi veniam nostrud.",
|
||||
fullWidth: false,
|
||||
variant: "info",
|
||||
size: "medium",
|
||||
closeButton: false,
|
||||
},
|
||||
argTypes: {
|
||||
variant: {
|
||||
@@ -50,21 +44,39 @@ export const Default: Story = {
|
||||
},
|
||||
options: ["medium", "small"],
|
||||
},
|
||||
closeButton: {
|
||||
type: "boolean",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const Small = () => {
|
||||
return (
|
||||
<div className="colgap">
|
||||
{variants.map((variant, i) => (
|
||||
<Alert key={variant} variant={variant} size="small">
|
||||
{new Array(i + 1).fill(
|
||||
"Id elit esse enim reprehenderit enim nisi veniam nostrud."
|
||||
)}
|
||||
</Alert>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
export const Small = {
|
||||
render: (props) => {
|
||||
return (
|
||||
<div className="colgap">
|
||||
{variants.map((variant, i) => (
|
||||
<Alert
|
||||
key={variant}
|
||||
variant={variant}
|
||||
size="small"
|
||||
closeButton={props.closeButton}
|
||||
>
|
||||
{new Array(i + 1).fill(
|
||||
"Id elit esse enim reprehenderit enim nisi veniam nostrud."
|
||||
)}
|
||||
</Alert>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
args: {
|
||||
closeButton: false,
|
||||
},
|
||||
argtypes: {
|
||||
closeButton: {
|
||||
type: "boolean",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const FullWidth = () => {
|
||||
@@ -147,3 +159,44 @@ export const Links = () => {
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const AlertWithCloseButton = ({ children }: { children?: React.ReactNode }) => {
|
||||
let [show, setShow] = React.useState(true);
|
||||
|
||||
return (
|
||||
show && (
|
||||
<Alert variant="success" closeButton onClose={() => setShow(false)}>
|
||||
{children || "Content"}
|
||||
</Alert>
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
export const WithCloseButton: Story = {
|
||||
render: () => {
|
||||
return (
|
||||
<div className="colgap">
|
||||
<AlertWithCloseButton />
|
||||
<AlertWithCloseButton>
|
||||
<BodyLong>
|
||||
Ullamco ullamco laborum et commodo sint culpa cupidatat culpa qui
|
||||
laboris ex. Labore ex occaecat proident qui qui fugiat magna. Fugiat
|
||||
sint commodo consequat eu aute.
|
||||
</BodyLong>
|
||||
<Link href="#">Id elit esse enim reprehenderit</Link>
|
||||
</AlertWithCloseButton>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
play: async ({ canvasElement, step }) => {
|
||||
const canvas = within(canvasElement);
|
||||
const buttons = canvas.getAllByTitle("Lukk Alert");
|
||||
|
||||
await step("click button", async () => {
|
||||
await userEvent.click(buttons[0]);
|
||||
});
|
||||
|
||||
const buttonsAfter = canvas.getAllByTitle("Lukk Alert");
|
||||
expect(buttonsAfter.length).toBe(1);
|
||||
},
|
||||
};
|
||||
@@ -126,11 +126,7 @@ export const Button: OverridableComponent<ButtonProps, HTMLButtonElement> =
|
||||
<span className="navds-button__icon">{icon}</span>
|
||||
)}
|
||||
{children && (
|
||||
<Label
|
||||
as="span"
|
||||
size={size === "medium" ? "medium" : "small"}
|
||||
aria-live="polite"
|
||||
>
|
||||
<Label as="span" size={size === "medium" ? "medium" : "small"}>
|
||||
{children}
|
||||
</Label>
|
||||
)}
|
||||
|
||||
@@ -148,8 +148,9 @@ export const Loading = {
|
||||
</div>
|
||||
),
|
||||
|
||||
args: { chromatic: { disableSnapshot: true } },
|
||||
chromatic: { disableSnapshot: true },
|
||||
parameters: {
|
||||
chromatic: { disableSnapshot: true },
|
||||
},
|
||||
};
|
||||
|
||||
export const Icon = () => (
|
||||
@@ -275,6 +276,7 @@ export const LoadingWithAs = {
|
||||
</div>
|
||||
),
|
||||
|
||||
args: { chromatic: { disableSnapshot: true } },
|
||||
chromatic: { disableSnapshot: true },
|
||||
parameters: {
|
||||
chromatic: { disableSnapshot: true },
|
||||
},
|
||||
};
|
||||
@@ -70,7 +70,7 @@ export const Chips: ChipsComponent = forwardRef<HTMLUListElement, ChipsProps>(
|
||||
})}
|
||||
>
|
||||
{React.Children.map(children, (chip, index) => {
|
||||
return <li key={index + (chip?.toString() ?? "")}>{chip}</li>;
|
||||
return <li key={chip?.toString() || index}>{chip}</li>;
|
||||
})}
|
||||
</ul>
|
||||
);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { XMarkIcon } from "@navikt/aksel-icons";
|
||||
import cl from "clsx";
|
||||
import React, { forwardRef } from "react";
|
||||
import { OverridableComponent } from "../util/OverridableComponent";
|
||||
|
||||
export interface RemovableChipsProps
|
||||
extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
||||
@@ -22,26 +21,27 @@ export interface RemovableChipsProps
|
||||
onDelete?: () => void;
|
||||
}
|
||||
|
||||
export const RemovableChips: OverridableComponent<
|
||||
RemovableChipsProps,
|
||||
HTMLButtonElement
|
||||
> = forwardRef(
|
||||
export const RemovableChips = forwardRef<
|
||||
HTMLButtonElement,
|
||||
RemovableChipsProps
|
||||
>(
|
||||
(
|
||||
{
|
||||
className,
|
||||
children,
|
||||
variant = "action",
|
||||
as: Component = "button",
|
||||
removeLabel = "slett",
|
||||
onDelete,
|
||||
type = "button",
|
||||
...rest
|
||||
},
|
||||
ref
|
||||
) => {
|
||||
return (
|
||||
<Component
|
||||
<button
|
||||
{...rest}
|
||||
ref={ref}
|
||||
type={type}
|
||||
className={cl(
|
||||
"navds-chips__chip navds-chips__removable navds-chips--icon-right",
|
||||
className,
|
||||
@@ -57,7 +57,7 @@ export const RemovableChips: OverridableComponent<
|
||||
<span className="navds-chips__removable-icon">
|
||||
<XMarkIcon aria-hidden />
|
||||
</span>
|
||||
</Component>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -4,6 +4,7 @@ import React, { forwardRef, InputHTMLAttributes } from "react";
|
||||
import { BodyShort, ErrorMessage, Label, omit } from "..";
|
||||
import { FormFieldProps, useFormField } from "../form/useFormField";
|
||||
import { useDateInputContext } from "./context";
|
||||
import { ReadOnlyIcon } from "../form/ReadOnlyIcon";
|
||||
|
||||
export interface DateInputProps
|
||||
extends FormFieldProps,
|
||||
@@ -57,6 +58,7 @@ const DateInput = forwardRef<HTMLInputElement, DateInputProps>((props, ref) => {
|
||||
errorId,
|
||||
showErrorMsg,
|
||||
hasError,
|
||||
readOnly,
|
||||
} = useFormField(props, conditionalVariables.prefix);
|
||||
|
||||
return (
|
||||
@@ -71,6 +73,9 @@ const DateInput = forwardRef<HTMLInputElement, DateInputProps>((props, ref) => {
|
||||
"navds-date__field--error": hasError,
|
||||
"navds-form-field--disabled": !!inputProps.disabled,
|
||||
"navds-text-field--disabled": !!inputProps.disabled,
|
||||
"navds-form-field--readonly": readOnly,
|
||||
"navds-text-field--readonly": readOnly,
|
||||
"navds-date__field--readonly": readOnly,
|
||||
}
|
||||
)}
|
||||
>
|
||||
@@ -81,6 +86,7 @@ const DateInput = forwardRef<HTMLInputElement, DateInputProps>((props, ref) => {
|
||||
"navds-sr-only": hideLabel,
|
||||
})}
|
||||
>
|
||||
<ReadOnlyIcon readOnly={readOnly} />
|
||||
{label}
|
||||
</Label>
|
||||
{!!description && (
|
||||
@@ -102,6 +108,7 @@ const DateInput = forwardRef<HTMLInputElement, DateInputProps>((props, ref) => {
|
||||
{...inputProps}
|
||||
autoComplete="off"
|
||||
aria-controls={ariaId}
|
||||
readOnly={readOnly}
|
||||
className={cl(
|
||||
"navds-date__field-input",
|
||||
"navds-text-field__input",
|
||||
@@ -111,8 +118,8 @@ const DateInput = forwardRef<HTMLInputElement, DateInputProps>((props, ref) => {
|
||||
size={14}
|
||||
/>
|
||||
<button
|
||||
disabled={inputProps.disabled}
|
||||
tabIndex={open ? -1 : 0}
|
||||
disabled={inputProps.disabled || readOnly}
|
||||
tabIndex={readOnly ? -1 : open ? -1 : 0}
|
||||
onClick={() => onOpen()}
|
||||
type="button"
|
||||
className="navds-date__field-button"
|
||||
|
||||
@@ -341,3 +341,25 @@ export const Size = () => {
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const Readonly = () => {
|
||||
const { datepickerProps, inputProps } = useDatepicker({
|
||||
fromDate: new Date("Aug 23 2019"),
|
||||
toDate: new Date("Feb 23 2024"),
|
||||
onDateChange: console.log,
|
||||
});
|
||||
|
||||
return (
|
||||
<div style={{ display: "flex", gap: "1rem" }}>
|
||||
<DatePicker {...datepickerProps} dropdownCaption>
|
||||
<DatePicker.Input
|
||||
size="medium"
|
||||
{...inputProps}
|
||||
value="01.02.2021"
|
||||
label="Velg dato"
|
||||
readOnly
|
||||
/>
|
||||
</DatePicker>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -166,8 +166,7 @@ export const useDatepicker = (
|
||||
const handleOpen = useCallback(
|
||||
(open: boolean) => {
|
||||
setOpen(open);
|
||||
!open &&
|
||||
setMonth(selectedDay ?? defaultSelected ?? defaultMonth ?? today);
|
||||
open && setMonth(selectedDay ?? defaultSelected ?? defaultMonth ?? today);
|
||||
},
|
||||
[defaultMonth, defaultSelected, selectedDay, today]
|
||||
);
|
||||
@@ -204,6 +203,9 @@ export const useDatepicker = (
|
||||
};
|
||||
|
||||
const handleFocus: React.FocusEventHandler<HTMLInputElement> = (e) => {
|
||||
if (e.target.readOnly) {
|
||||
return;
|
||||
}
|
||||
!open && openOnFocus && handleOpen(true);
|
||||
let day = parseDate(
|
||||
e.target.value,
|
||||
|
||||
@@ -163,8 +163,7 @@ export const useMonthpicker = (
|
||||
const handleOpen = useCallback(
|
||||
(open: boolean) => {
|
||||
setOpen(open);
|
||||
!open &&
|
||||
setYear(selectedMonth ?? defaultSelected ?? defaultYear ?? today);
|
||||
open && setYear(selectedMonth ?? defaultSelected ?? defaultYear ?? today);
|
||||
},
|
||||
[defaultSelected, defaultYear, selectedMonth, today]
|
||||
);
|
||||
@@ -201,6 +200,9 @@ export const useMonthpicker = (
|
||||
};
|
||||
|
||||
const handleFocus: React.FocusEventHandler<HTMLInputElement> = (e) => {
|
||||
if (e.target.readOnly) {
|
||||
return;
|
||||
}
|
||||
!open && openOnFocus && handleOpen(true);
|
||||
let day = parseDate(
|
||||
e.target.value,
|
||||
|
||||
@@ -321,6 +321,9 @@ export const useRangeDatepicker = (
|
||||
};
|
||||
|
||||
const handleFocus = (e, src: RangeT) => {
|
||||
if (e.target.readOnly) {
|
||||
return;
|
||||
}
|
||||
!open && openOnFocus && setOpen(true);
|
||||
let day = parseDate(
|
||||
e.target.value,
|
||||
|
||||
File renamed without changes.
File renamed without changes.
@@ -1,8 +1,8 @@
|
||||
import cl from "clsx";
|
||||
import React, { forwardRef } from "react";
|
||||
import { OverridableComponent } from "../../../util/OverridableComponent";
|
||||
import GroupedHeading, { GroupedHeadingProps } from "./Heading";
|
||||
import GroupedItem, { GroupedItemProps } from "./Item";
|
||||
import GroupedHeading, { GroupedHeadingProps } from "./GroupedHeading";
|
||||
import GroupedItem, { GroupedItemProps } from "./GroupedItem";
|
||||
|
||||
export interface GroupedListProps
|
||||
extends React.HTMLAttributes<HTMLDListElement> {
|
||||
|
||||
@@ -6,7 +6,7 @@ import { useFormField } from "./useFormField";
|
||||
export interface ConfirmationPanelProps
|
||||
extends Omit<
|
||||
CheckboxProps,
|
||||
"children" | "indeterminate" | "hideLabel" | "error"
|
||||
"children" | "indeterminate" | "hideLabel" | "error" | "readOnly"
|
||||
> {
|
||||
/**
|
||||
* Additional information on panel
|
||||
|
||||
@@ -3,6 +3,7 @@ import React, { FieldsetHTMLAttributes, forwardRef, useContext } from "react";
|
||||
import { BodyShort, ErrorMessage, Label, omit } from "../..";
|
||||
import { FormFieldProps } from "../useFormField";
|
||||
import { useFieldset } from "./useFieldset";
|
||||
import { ReadOnlyIcon } from "../ReadOnlyIcon";
|
||||
|
||||
export type FieldsetContextProps = {
|
||||
/**
|
||||
@@ -21,6 +22,10 @@ export type FieldsetContextProps = {
|
||||
* Sets fieldset and all form-children to disabled
|
||||
*/
|
||||
disabled: boolean;
|
||||
/**
|
||||
* Read only-state
|
||||
*/
|
||||
readOnly?: boolean;
|
||||
};
|
||||
|
||||
export const FieldsetContext = React.createContext<FieldsetContextProps | null>(
|
||||
@@ -47,6 +52,7 @@ export interface FieldsetProps
|
||||
* @default true
|
||||
*/
|
||||
errorPropagation?: boolean;
|
||||
nativeReadOnly?: boolean;
|
||||
}
|
||||
|
||||
export const Fieldset = forwardRef<HTMLFieldSetElement, FieldsetProps>(
|
||||
@@ -57,6 +63,7 @@ export const Fieldset = forwardRef<HTMLFieldSetElement, FieldsetProps>(
|
||||
showErrorMsg,
|
||||
hasError,
|
||||
size,
|
||||
readOnly,
|
||||
inputDescriptionId,
|
||||
} = useFieldset(props);
|
||||
|
||||
@@ -69,6 +76,7 @@ export const Fieldset = forwardRef<HTMLFieldSetElement, FieldsetProps>(
|
||||
legend,
|
||||
description,
|
||||
hideLegend,
|
||||
nativeReadOnly = true,
|
||||
...rest
|
||||
} = props;
|
||||
|
||||
@@ -82,17 +90,21 @@ export const Fieldset = forwardRef<HTMLFieldSetElement, FieldsetProps>(
|
||||
}),
|
||||
size,
|
||||
disabled: props.disabled ?? false,
|
||||
readOnly,
|
||||
}}
|
||||
>
|
||||
<fieldset
|
||||
{...omit(rest, ["errorId", "error", "size"])}
|
||||
{...omit(rest, ["errorId", "error", "size", "readOnly"])}
|
||||
{...inputProps}
|
||||
ref={ref}
|
||||
className={cl(
|
||||
className,
|
||||
"navds-fieldset",
|
||||
`navds-fieldset--${size}`,
|
||||
{ "navds-fieldset--error": hasError }
|
||||
{
|
||||
"navds-fieldset--error": hasError,
|
||||
"navds-fieldset--readonly": readOnly,
|
||||
}
|
||||
)}
|
||||
>
|
||||
<Label
|
||||
@@ -102,6 +114,7 @@ export const Fieldset = forwardRef<HTMLFieldSetElement, FieldsetProps>(
|
||||
"navds-sr-only": !!hideLegend,
|
||||
})}
|
||||
>
|
||||
<ReadOnlyIcon readOnly={readOnly} nativeReadOnly={nativeReadOnly} />
|
||||
{legend}
|
||||
</Label>
|
||||
{!!description && (
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import { PadlockLockedFillIcon } from "@navikt/aksel-icons";
|
||||
import React from "react";
|
||||
|
||||
export const ReadOnlyIcon = ({
|
||||
readOnly,
|
||||
nativeReadOnly = true,
|
||||
}: {
|
||||
readOnly?: boolean;
|
||||
nativeReadOnly?: boolean;
|
||||
}) => {
|
||||
if (readOnly) {
|
||||
return (
|
||||
<PadlockLockedFillIcon
|
||||
{...(nativeReadOnly ? { "aria-hidden": true } : { title: "readonly" })}
|
||||
className="navds-form-field__readonly-icon"
|
||||
/>
|
||||
);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
@@ -4,6 +4,7 @@ import React, { forwardRef, SelectHTMLAttributes } from "react";
|
||||
import { ChevronDownIcon } from "@navikt/aksel-icons";
|
||||
import { BodyShort, ErrorMessage, Label, omit } from "..";
|
||||
import { FormFieldProps, useFormField } from "./useFormField";
|
||||
import { ReadOnlyIcon } from "./ReadOnlyIcon";
|
||||
|
||||
export interface SelectProps
|
||||
extends FormFieldProps,
|
||||
@@ -55,7 +56,8 @@ export const Select = forwardRef<HTMLSelectElement, SelectProps>(
|
||||
hasError,
|
||||
size,
|
||||
inputDescriptionId,
|
||||
} = useFormField(props, "textField");
|
||||
readOnly,
|
||||
} = useFormField(props, "select");
|
||||
|
||||
const {
|
||||
children,
|
||||
@@ -68,6 +70,27 @@ export const Select = forwardRef<HTMLSelectElement, SelectProps>(
|
||||
...rest
|
||||
} = props;
|
||||
|
||||
const readOnlyEventHandlers = {
|
||||
onMouseDown: (evt) => {
|
||||
// NOTE: does not prevent click
|
||||
if (readOnly) {
|
||||
evt.preventDefault();
|
||||
// focus on the element as per readonly input behavior
|
||||
evt.target.focus();
|
||||
}
|
||||
},
|
||||
onKeyDown: (evt) => {
|
||||
if (
|
||||
readOnly &&
|
||||
["ArrowDown", "ArrowUp", "ArrowRight", "ArrowLeft", " "].includes(
|
||||
evt.key
|
||||
)
|
||||
) {
|
||||
evt.preventDefault();
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cl(
|
||||
@@ -76,7 +99,9 @@ export const Select = forwardRef<HTMLSelectElement, SelectProps>(
|
||||
`navds-form-field--${size}`,
|
||||
{
|
||||
"navds-form-field--disabled": !!inputProps.disabled,
|
||||
"navds-form-field--readonly": readOnly,
|
||||
"navds-select--error": hasError,
|
||||
"navds-select--readonly": readOnly,
|
||||
}
|
||||
)}
|
||||
>
|
||||
@@ -87,6 +112,7 @@ export const Select = forwardRef<HTMLSelectElement, SelectProps>(
|
||||
"navds-sr-only": hideLabel,
|
||||
})}
|
||||
>
|
||||
<ReadOnlyIcon readOnly={readOnly} nativeReadOnly={false} />
|
||||
{label}
|
||||
</Label>
|
||||
{!!description && (
|
||||
@@ -103,8 +129,9 @@ export const Select = forwardRef<HTMLSelectElement, SelectProps>(
|
||||
)}
|
||||
<div className="navds-select__container" style={style}>
|
||||
<select
|
||||
{...omit(rest, ["error", "errorId", "size"])}
|
||||
{...omit(rest, ["error", "errorId", "size", "readOnly"])}
|
||||
{...inputProps}
|
||||
{...readOnlyEventHandlers}
|
||||
ref={ref}
|
||||
className={cl(
|
||||
"navds-select__input",
|
||||
|
||||
@@ -7,6 +7,7 @@ import React, {
|
||||
} from "react";
|
||||
import { BodyShort, Loader, omit } from "..";
|
||||
import { FormFieldProps, useFormField } from "./useFormField";
|
||||
import { ReadOnlyIcon } from "./ReadOnlyIcon";
|
||||
|
||||
const SelectedIcon = () => (
|
||||
<svg
|
||||
@@ -63,12 +64,12 @@ export interface SwitchProps
|
||||
*
|
||||
* @example
|
||||
* ```jsx
|
||||
* <Switch>Slå på notifikasjoner</Switch>
|
||||
* <Switch>Varsle med SMS</Switch>
|
||||
* ```
|
||||
*/
|
||||
export const Switch = forwardRef<HTMLInputElement, SwitchProps>(
|
||||
(props, ref) => {
|
||||
const { inputProps, size } = useFormField(props, "switch");
|
||||
const { inputProps, size, readOnly } = useFormField(props, "switch");
|
||||
|
||||
const {
|
||||
children,
|
||||
@@ -90,11 +91,6 @@ export const Switch = forwardRef<HTMLInputElement, SwitchProps>(
|
||||
checkedProp !== undefined && setChecked(checkedProp);
|
||||
}, [checkedProp]);
|
||||
|
||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
setChecked(e.target.checked);
|
||||
props.onChange && props.onChange(e);
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cl(
|
||||
@@ -105,18 +101,32 @@ export const Switch = forwardRef<HTMLInputElement, SwitchProps>(
|
||||
{
|
||||
"navds-switch--loading": loading,
|
||||
"navds-switch--disabled": inputProps.disabled ?? loading,
|
||||
"navds-switch--readonly": readOnly,
|
||||
}
|
||||
)}
|
||||
>
|
||||
<input
|
||||
{...omit(rest, ["size"])}
|
||||
{...omit(rest, ["size", "readOnly"])}
|
||||
{...omit(inputProps, ["aria-invalid", "aria-describedby"])}
|
||||
disabled={inputProps.disabled ?? loading}
|
||||
checked={checkedProp}
|
||||
defaultChecked={defaultChecked}
|
||||
ref={ref}
|
||||
type="checkbox"
|
||||
onChange={(e) => handleChange(e)}
|
||||
onChange={(e) => {
|
||||
if (readOnly) {
|
||||
return;
|
||||
}
|
||||
setChecked(e.target.checked);
|
||||
props.onChange && props.onChange(e);
|
||||
}}
|
||||
onClick={(e) => {
|
||||
if (readOnly) {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
props?.onClick?.(e);
|
||||
}}
|
||||
className={cl(className, "navds-switch__input")}
|
||||
/>
|
||||
<span className="navds-switch__track">
|
||||
@@ -136,6 +146,7 @@ export const Switch = forwardRef<HTMLInputElement, SwitchProps>(
|
||||
})}
|
||||
>
|
||||
<BodyShort as="div" size={size} className="navds-switch__label">
|
||||
<ReadOnlyIcon readOnly={readOnly} nativeReadOnly={false} />
|
||||
{children}
|
||||
</BodyShort>
|
||||
{description && (
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import cl from "clsx";
|
||||
import React, { forwardRef, InputHTMLAttributes } from "react";
|
||||
import { BodyShort, ErrorMessage, Label, omit } from "..";
|
||||
import { ReadOnlyIcon } from "./ReadOnlyIcon";
|
||||
import { FormFieldProps, useFormField } from "./useFormField";
|
||||
|
||||
export interface TextFieldProps
|
||||
@@ -30,7 +31,7 @@ export interface TextFieldProps
|
||||
* Type of form control. Picking the correct type helps user fill inn their required information
|
||||
* @default "text"
|
||||
*/
|
||||
type?: "email" | "number" | "password" | "tel" | "text" | "url";
|
||||
type?: "email" | "number" | "password" | "tel" | "text" | "url" | "time";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,6 +63,7 @@ export const TextField = forwardRef<HTMLInputElement, TextFieldProps>(
|
||||
htmlSize,
|
||||
hideLabel = false,
|
||||
type = "text",
|
||||
readOnly,
|
||||
...rest
|
||||
} = props;
|
||||
|
||||
@@ -71,10 +73,13 @@ export const TextField = forwardRef<HTMLInputElement, TextFieldProps>(
|
||||
className,
|
||||
"navds-form-field",
|
||||
`navds-form-field--${size}`,
|
||||
|
||||
{
|
||||
"navds-text-field--error": hasError,
|
||||
"navds-text-field--disabled": !!inputProps.disabled,
|
||||
"navds-form-field--disabled": !!inputProps.disabled,
|
||||
"navds-form-field--readonly": readOnly,
|
||||
"navds-text-field--readonly": readOnly,
|
||||
}
|
||||
)}
|
||||
>
|
||||
@@ -85,6 +90,7 @@ export const TextField = forwardRef<HTMLInputElement, TextFieldProps>(
|
||||
"navds-sr-only": hideLabel,
|
||||
})}
|
||||
>
|
||||
<ReadOnlyIcon readOnly={readOnly} />
|
||||
{label}
|
||||
</Label>
|
||||
|
||||
@@ -105,6 +111,7 @@ export const TextField = forwardRef<HTMLInputElement, TextFieldProps>(
|
||||
{...inputProps}
|
||||
ref={ref}
|
||||
type={type}
|
||||
readOnly={readOnly}
|
||||
className={cl(
|
||||
"navds-text-field__input",
|
||||
"navds-body-short",
|
||||
|
||||
@@ -3,6 +3,7 @@ import React, { forwardRef, useState } from "react";
|
||||
import { BodyShort, ErrorMessage, Label, omit, useId } from "..";
|
||||
import TextareaAutosize from "../util/TextareaAutoSize";
|
||||
import { FormFieldProps, useFormField } from "./useFormField";
|
||||
import { ReadOnlyIcon } from "./ReadOnlyIcon";
|
||||
|
||||
/**
|
||||
* TODO: Mulighet for lokalisering av sr-only/counter text
|
||||
@@ -85,6 +86,7 @@ export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(
|
||||
hideLabel = false,
|
||||
resize,
|
||||
i18n,
|
||||
readOnly,
|
||||
...rest
|
||||
} = props;
|
||||
|
||||
@@ -115,6 +117,8 @@ export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(
|
||||
`navds-form-field--${size}`,
|
||||
{
|
||||
"navds-form-field--disabled": !!inputProps.disabled,
|
||||
"navds-form-field--readonly": readOnly,
|
||||
"navds-textarea--readonly": readOnly,
|
||||
"navds-textarea--error": hasError,
|
||||
"navds-textarea--resize": resize,
|
||||
}
|
||||
@@ -127,6 +131,7 @@ export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(
|
||||
"navds-sr-only": hideLabel,
|
||||
})}
|
||||
>
|
||||
<ReadOnlyIcon readOnly={readOnly} />
|
||||
{label}
|
||||
</Label>
|
||||
{!!description && (
|
||||
@@ -152,6 +157,7 @@ export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(
|
||||
}
|
||||
minRows={getMinRows()}
|
||||
ref={ref}
|
||||
readOnly={readOnly}
|
||||
className={cl(
|
||||
"navds-textarea__input",
|
||||
"navds-body-short",
|
||||
@@ -203,8 +209,8 @@ export const Counter = ({ maxLength, currentLength, size, i18n }) => {
|
||||
size={size}
|
||||
>
|
||||
{difference < 0
|
||||
? `${Math.abs(difference)} ${i18n?.counterLeft ?? "tegn for mye"}`
|
||||
: `${difference} ${i18n?.counterTooMuch ?? "tegn igjen"}`}
|
||||
? `${Math.abs(difference)} ${i18n?.counterTooMuch ?? "tegn for mye"}`
|
||||
: `${difference} ${i18n?.counterLeft ?? "tegn igjen"}`}
|
||||
</BodyShort>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -4,6 +4,7 @@ import { BodyShort } from "../../typography";
|
||||
import { omit } from "../../util";
|
||||
import { FormFieldProps } from "../useFormField";
|
||||
import useCheckbox from "./useCheckbox";
|
||||
import { ReadOnlyIcon } from "../ReadOnlyIcon";
|
||||
|
||||
export interface CheckboxProps
|
||||
extends FormFieldProps,
|
||||
@@ -42,7 +43,7 @@ export interface CheckboxProps
|
||||
|
||||
export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
|
||||
(props, ref) => {
|
||||
const { inputProps, hasError, size } = useCheckbox(props);
|
||||
const { inputProps, hasError, size, readOnly, nested } = useCheckbox(props);
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -53,6 +54,7 @@ export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
|
||||
{
|
||||
"navds-checkbox--error": hasError,
|
||||
"navds-checkbox--disabled": inputProps.disabled,
|
||||
"navds-checkbox--readonly": readOnly,
|
||||
}
|
||||
)}
|
||||
>
|
||||
@@ -65,6 +67,7 @@ export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
|
||||
"hideLabel",
|
||||
"indeterminate",
|
||||
"errorId",
|
||||
"readOnly",
|
||||
])}
|
||||
{...inputProps}
|
||||
type="checkbox"
|
||||
@@ -88,7 +91,14 @@ export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
|
||||
"navds-sr-only": props.hideLabel,
|
||||
})}
|
||||
>
|
||||
<BodyShort as="span" size={size}>
|
||||
<BodyShort
|
||||
as="span"
|
||||
size={size}
|
||||
className="navds-checkbox__label-text"
|
||||
>
|
||||
{!nested && (
|
||||
<ReadOnlyIcon readOnly={readOnly} nativeReadOnly={false} />
|
||||
)}
|
||||
{props.children}
|
||||
</BodyShort>
|
||||
{props.description && (
|
||||
|
||||
@@ -81,6 +81,7 @@ export const CheckboxGroup = forwardRef<
|
||||
"navds-checkbox-group",
|
||||
`navds-checkbox-group--${rest.size ?? fieldset?.size ?? "medium"}`
|
||||
)}
|
||||
nativeReadOnly={false}
|
||||
>
|
||||
<CheckboxGroupContext.Provider
|
||||
value={{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* eslint-disable react-hooks/rules-of-hooks */
|
||||
import { Meta } from "@storybook/react";
|
||||
import React, { useState } from "react";
|
||||
import { Checkbox, CheckboxGroup } from "../../index";
|
||||
import { Meta } from "@storybook/react";
|
||||
|
||||
export default {
|
||||
title: "ds-react/Checkbox",
|
||||
@@ -190,3 +190,37 @@ export const Indeterminate = () => {
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export const Readonly = () => (
|
||||
<div className="colgap">
|
||||
<CheckboxGroup
|
||||
legend="Hvilken frukt liker du?"
|
||||
defaultValue={["banan"]}
|
||||
readOnly
|
||||
>
|
||||
<Checkbox value="banan">Banan</Checkbox>
|
||||
<Checkbox value="eple">Eple</Checkbox>
|
||||
<Checkbox value="druer" indeterminate>
|
||||
Druer
|
||||
</Checkbox>
|
||||
</CheckboxGroup>
|
||||
<CheckboxGroup
|
||||
legend="Hvilken frukt liker du?"
|
||||
error="feilmelding"
|
||||
defaultValue={["Eple"]}
|
||||
readOnly
|
||||
>
|
||||
<Checkbox value="eple" description="Epler kommer i 4 varianter">
|
||||
Eple
|
||||
</Checkbox>
|
||||
<Checkbox value="banan">Banan</Checkbox>
|
||||
</CheckboxGroup>
|
||||
<hr />
|
||||
<Checkbox value="tekst1" readOnly>
|
||||
Eple single
|
||||
</Checkbox>
|
||||
<Checkbox value="tekst1" checked readOnly>
|
||||
Banan single
|
||||
</Checkbox>
|
||||
</div>
|
||||
);
|
||||
@@ -10,7 +10,7 @@ import { omit } from "../..";
|
||||
const useCheckbox = ({ children, ...props }: CheckboxProps) => {
|
||||
const checkboxGroup = useContext(CheckboxGroupContext);
|
||||
|
||||
const { inputProps, ...rest } = useFormField(
|
||||
const { inputProps, readOnly, ...rest } = useFormField(
|
||||
omit(props, ["description"]),
|
||||
"checkbox"
|
||||
);
|
||||
@@ -30,6 +30,8 @@ const useCheckbox = ({ children, ...props }: CheckboxProps) => {
|
||||
|
||||
return {
|
||||
...rest,
|
||||
readOnly,
|
||||
nested: !!checkboxGroup,
|
||||
inputProps: {
|
||||
...inputProps,
|
||||
checked: checkboxGroup?.value
|
||||
@@ -39,9 +41,19 @@ const useCheckbox = ({ children, ...props }: CheckboxProps) => {
|
||||
? checkboxGroup.defaultValue.includes(props.value)
|
||||
: props.defaultChecked,
|
||||
onChange: (e) => {
|
||||
if (readOnly) {
|
||||
return;
|
||||
}
|
||||
props.onChange && props.onChange(e);
|
||||
checkboxGroup && checkboxGroup.toggleValue(props.value);
|
||||
},
|
||||
onClick: (e) => {
|
||||
if (readOnly) {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
props?.onClick?.(e);
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import React from "react";
|
||||
import { XMarkIcon } from "@navikt/aksel-icons";
|
||||
|
||||
interface ClearButtonProps extends React.HTMLAttributes<HTMLButtonElement> {
|
||||
handleClear: (event: any) => void;
|
||||
clearButtonLabel?: string;
|
||||
}
|
||||
|
||||
export const ClearButton: React.FC<ClearButtonProps> = ({
|
||||
handleClear,
|
||||
clearButtonLabel,
|
||||
...rest
|
||||
}) => {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleClear}
|
||||
className="navds-combobox__button-clear"
|
||||
{...rest}
|
||||
>
|
||||
<span className="navds-sr-only">
|
||||
{clearButtonLabel ? clearButtonLabel : "Tøm"}
|
||||
</span>
|
||||
<XMarkIcon aria-hidden />
|
||||
</button>
|
||||
);
|
||||
};
|
||||
|
||||
export default ClearButton;
|
||||
@@ -0,0 +1,136 @@
|
||||
import cl from "clsx";
|
||||
import React, { forwardRef, useMemo, useRef } from "react";
|
||||
import { BodyShort, Label, mergeRefs } from "../..";
|
||||
import ClearButton from "./ClearButton";
|
||||
import FilteredOptions from "./FilteredOptions/FilteredOptions";
|
||||
import { useFilteredOptionsContext } from "./FilteredOptions/filteredOptionsContext";
|
||||
import SelectedOptions from "./SelectedOptions/SelectedOptions";
|
||||
import ToggleListButton from "./ToggleListButton";
|
||||
import { ComboboxProps } from "./types";
|
||||
import { useSelectedOptionsContext } from "./SelectedOptions/selectedOptionsContext";
|
||||
import ComboboxWrapper from "./ComboboxWrapper";
|
||||
import { useInputContext } from "./Input/inputContext";
|
||||
import Input from "./Input/Input";
|
||||
|
||||
export const Combobox = forwardRef<
|
||||
HTMLInputElement,
|
||||
Omit<ComboboxProps, "onChange" | "options" | "size">
|
||||
>((props, ref) => {
|
||||
const {
|
||||
value: externalValue,
|
||||
onClear,
|
||||
className,
|
||||
hideLabel = false,
|
||||
description,
|
||||
label,
|
||||
clearButton = true,
|
||||
clearButtonLabel,
|
||||
toggleListButton = true,
|
||||
toggleListButtonLabel,
|
||||
inputClassName,
|
||||
shouldShowSelectedOptions = true,
|
||||
...rest
|
||||
} = props;
|
||||
|
||||
const toggleListButtonRef = useRef<HTMLButtonElement>(null);
|
||||
|
||||
const { currentOption, toggleIsListOpen } = useFilteredOptionsContext();
|
||||
const { selectedOptions } = useSelectedOptionsContext();
|
||||
|
||||
const {
|
||||
clearInput,
|
||||
focusInput,
|
||||
hasError,
|
||||
inputDescriptionId,
|
||||
inputProps,
|
||||
inputRef,
|
||||
value,
|
||||
size = "medium",
|
||||
} = useInputContext();
|
||||
|
||||
const mergedInputRef = useMemo(
|
||||
() => mergeRefs([inputRef, ref]),
|
||||
[inputRef, ref]
|
||||
);
|
||||
|
||||
return (
|
||||
<ComboboxWrapper
|
||||
className={className}
|
||||
hasError={hasError}
|
||||
inputProps={inputProps}
|
||||
inputSize={size}
|
||||
toggleIsListOpen={toggleIsListOpen}
|
||||
toggleListButtonRef={toggleListButtonRef}
|
||||
>
|
||||
<Label
|
||||
htmlFor={inputProps.id}
|
||||
size={size}
|
||||
className={cl("navds-form-field__label", {
|
||||
"navds-sr-only": hideLabel,
|
||||
})}
|
||||
>
|
||||
{label}
|
||||
</Label>
|
||||
{!!description && (
|
||||
<BodyShort
|
||||
as="div"
|
||||
className={cl("navds-form-field__description", {
|
||||
"navds-sr-only": hideLabel,
|
||||
})}
|
||||
id={inputDescriptionId}
|
||||
size={size}
|
||||
>
|
||||
{description}
|
||||
</BodyShort>
|
||||
)}
|
||||
<div className="navds-combobox__wrapper">
|
||||
<div
|
||||
className={cl(
|
||||
"navds-combobox__wrapper-inner navds-text-field__input",
|
||||
{
|
||||
"navds-combobox__wrapper-inner--virtually-unfocused":
|
||||
currentOption !== null,
|
||||
}
|
||||
)}
|
||||
onClick={focusInput}
|
||||
>
|
||||
{!shouldShowSelectedOptions ? (
|
||||
<Input
|
||||
id={inputProps.id}
|
||||
ref={mergedInputRef}
|
||||
inputClassName={inputClassName}
|
||||
{...rest}
|
||||
/>
|
||||
) : (
|
||||
<SelectedOptions selectedOptions={selectedOptions} size={size}>
|
||||
<Input
|
||||
id={inputProps.id}
|
||||
ref={mergedInputRef}
|
||||
inputClassName={inputClassName}
|
||||
{...rest}
|
||||
/>
|
||||
</SelectedOptions>
|
||||
)}
|
||||
<div>
|
||||
{value && clearButton && (
|
||||
<ClearButton
|
||||
handleClear={clearInput}
|
||||
clearButtonLabel={clearButtonLabel}
|
||||
tabIndex={-1}
|
||||
/>
|
||||
)}
|
||||
{toggleListButton && (
|
||||
<ToggleListButton
|
||||
toggleListButtonLabel={toggleListButtonLabel}
|
||||
ref={toggleListButtonRef}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<FilteredOptions />
|
||||
</div>
|
||||
</ComboboxWrapper>
|
||||
);
|
||||
});
|
||||
|
||||
export default Combobox;
|
||||
@@ -0,0 +1,99 @@
|
||||
import React, { forwardRef } from "react";
|
||||
import Combobox from "./Combobox";
|
||||
import { FilteredOptionsProvider } from "./FilteredOptions/filteredOptionsContext";
|
||||
import { CustomOptionsProvider } from "./customOptionsContext";
|
||||
import { SelectedOptionsProvider } from "./SelectedOptions/selectedOptionsContext";
|
||||
import { InputContextProvider } from "./Input/inputContext";
|
||||
import { ComboboxProps } from "./types";
|
||||
|
||||
/**
|
||||
* A component that allows the user to search in a list of options
|
||||
*
|
||||
* Has options for allowing only one or multiple options to be selected,
|
||||
* or adding new, user-submitted values.
|
||||
*
|
||||
* @see [📝 Documentation](https://aksel.nav.no/komponenter/core/combobox)
|
||||
*
|
||||
* @example
|
||||
* ```jsx
|
||||
* const options = ["apple", "banana", "orange"];
|
||||
*
|
||||
* return (
|
||||
* <Combobox
|
||||
* label="Velg en verdi"
|
||||
* options={options}
|
||||
* id="my-combobox"
|
||||
* shouldAutoComplete
|
||||
* />
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
const ComboboxProvider = forwardRef<HTMLInputElement, ComboboxProps>(
|
||||
(props, ref) => {
|
||||
const {
|
||||
allowNewValues = false,
|
||||
children,
|
||||
defaultValue,
|
||||
error,
|
||||
errorId,
|
||||
filteredOptions,
|
||||
id,
|
||||
isListOpen,
|
||||
isLoading = false,
|
||||
isMultiSelect,
|
||||
onToggleSelected,
|
||||
selectedOptions,
|
||||
options,
|
||||
value,
|
||||
onChange,
|
||||
onClear,
|
||||
shouldAutocomplete,
|
||||
size,
|
||||
...rest
|
||||
} = props;
|
||||
return (
|
||||
<InputContextProvider
|
||||
value={{
|
||||
defaultValue,
|
||||
error,
|
||||
errorId,
|
||||
id,
|
||||
value,
|
||||
onChange,
|
||||
onClear,
|
||||
shouldAutocomplete,
|
||||
size,
|
||||
}}
|
||||
>
|
||||
<CustomOptionsProvider>
|
||||
<SelectedOptionsProvider
|
||||
value={{
|
||||
allowNewValues,
|
||||
isMultiSelect,
|
||||
selectedOptions,
|
||||
onToggleSelected,
|
||||
options,
|
||||
}}
|
||||
>
|
||||
<FilteredOptionsProvider
|
||||
value={{
|
||||
allowNewValues,
|
||||
filteredOptions,
|
||||
isListOpen,
|
||||
isLoading,
|
||||
isMultiSelect,
|
||||
options,
|
||||
}}
|
||||
>
|
||||
<Combobox ref={ref} {...rest}>
|
||||
{children}
|
||||
</Combobox>
|
||||
</FilteredOptionsProvider>
|
||||
</SelectedOptionsProvider>
|
||||
</CustomOptionsProvider>
|
||||
</InputContextProvider>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
export default ComboboxProvider;
|
||||
@@ -0,0 +1,68 @@
|
||||
import cl from "clsx";
|
||||
import React, { useRef, useState } from "react";
|
||||
|
||||
type ComboboxWrapperProps = {
|
||||
children: any;
|
||||
className?: string;
|
||||
hasError: boolean;
|
||||
inputProps: {
|
||||
disabled?: boolean;
|
||||
};
|
||||
inputSize: string;
|
||||
toggleIsListOpen: (isListOpen: boolean) => void;
|
||||
toggleListButtonRef: React.RefObject<HTMLButtonElement>;
|
||||
};
|
||||
|
||||
const ComboboxWrapper = ({
|
||||
children,
|
||||
className,
|
||||
hasError,
|
||||
inputProps,
|
||||
inputSize,
|
||||
toggleIsListOpen,
|
||||
toggleListButtonRef,
|
||||
}: ComboboxWrapperProps) => {
|
||||
const wrapperRef = useRef<HTMLDivElement | null>(null);
|
||||
const [hasFocusWithin, setHasFocusWithin] = useState(false);
|
||||
|
||||
function onFocusInsideWrapper(e) {
|
||||
if (
|
||||
!wrapperRef.current?.contains(e.relatedTarget) &&
|
||||
toggleListButtonRef?.current !== e.target
|
||||
) {
|
||||
toggleIsListOpen(true);
|
||||
setHasFocusWithin(true);
|
||||
}
|
||||
}
|
||||
|
||||
function onBlurWrapper(e) {
|
||||
if (!wrapperRef.current?.contains(e.relatedTarget)) {
|
||||
toggleIsListOpen(false);
|
||||
setHasFocusWithin(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={wrapperRef}
|
||||
className={cl(
|
||||
className,
|
||||
"navds-form-field",
|
||||
`navds-form-field--${inputSize}`,
|
||||
"navds-search",
|
||||
{
|
||||
"navds-search--error": hasError,
|
||||
"navds-search--disabled": !!inputProps.disabled,
|
||||
"navds-combobox--focused": hasFocusWithin,
|
||||
}
|
||||
)}
|
||||
onFocus={onFocusInsideWrapper}
|
||||
onBlur={onBlurWrapper}
|
||||
tabIndex={-1}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ComboboxWrapper;
|
||||
@@ -0,0 +1,23 @@
|
||||
import React from "react";
|
||||
|
||||
const CheckIcon = () => {
|
||||
return (
|
||||
<svg
|
||||
width="16"
|
||||
height="13"
|
||||
viewBox="0 0 16 13"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path
|
||||
fillRule="evenodd"
|
||||
clipRule="evenodd"
|
||||
fill="#005B82"
|
||||
d="M14.2014 0L16 1.89047L4.77943 13L0 8.39552L1.79361 6.5L4.77418 9.3019L14.2014 0Z"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
};
|
||||
|
||||
export default CheckIcon;
|
||||
@@ -0,0 +1,111 @@
|
||||
import React from "react";
|
||||
import cl from "clsx";
|
||||
import { BodyShort, Label, Loader } from "../../..";
|
||||
import { CheckmarkIcon, PlusIcon } from "@navikt/aksel-icons";
|
||||
import { useFilteredOptionsContext } from "./filteredOptionsContext";
|
||||
import { useSelectedOptionsContext } from "../SelectedOptions/selectedOptionsContext";
|
||||
import { useInputContext } from "../Input/inputContext";
|
||||
|
||||
const FilteredOptions = () => {
|
||||
const {
|
||||
clearInput,
|
||||
inputProps: { id },
|
||||
size,
|
||||
value,
|
||||
} = useInputContext();
|
||||
const {
|
||||
allowNewValues,
|
||||
isLoading,
|
||||
isListOpen,
|
||||
filteredOptions,
|
||||
filteredOptionsIndex,
|
||||
filteredOptionsRef,
|
||||
isValueNew,
|
||||
toggleIsListOpen,
|
||||
} = useFilteredOptionsContext();
|
||||
const { isMultiSelect, selectedOptions, toggleOption } =
|
||||
useSelectedOptionsContext();
|
||||
|
||||
return (
|
||||
<ul
|
||||
ref={filteredOptionsRef}
|
||||
className={cl("navds-combobox__list", {
|
||||
"navds-combobox__list--closed": !isListOpen,
|
||||
})}
|
||||
id={`${id}-filtered-options`}
|
||||
role="listbox"
|
||||
tabIndex={-1}
|
||||
>
|
||||
{isLoading && (
|
||||
<li
|
||||
className="navds-combobox__list-item--loading"
|
||||
role="option"
|
||||
aria-selected={false}
|
||||
id={`${id}-is-loading`}
|
||||
>
|
||||
<Loader aria-label="Søker..." />
|
||||
</li>
|
||||
)}
|
||||
{isValueNew && allowNewValues && (
|
||||
<li
|
||||
tabIndex={-1}
|
||||
onPointerUp={(event) => {
|
||||
toggleOption(value, event);
|
||||
clearInput(event);
|
||||
}}
|
||||
id={`${id}-combobox-new-option`}
|
||||
className={cl("navds-combobox__list-item__new-option", {
|
||||
"navds-combobox__list-item__new-option--focus":
|
||||
filteredOptionsIndex === -1,
|
||||
})}
|
||||
role="option"
|
||||
aria-selected={false}
|
||||
>
|
||||
<PlusIcon aria-hidden />
|
||||
<BodyShort size={size}>
|
||||
Legg til{" "}
|
||||
<Label as="span" size={size}>
|
||||
“{value}”
|
||||
</Label>
|
||||
</BodyShort>
|
||||
</li>
|
||||
)}
|
||||
{!isLoading && filteredOptions.length === 0 && (
|
||||
<li
|
||||
className="navds-combobox__list-item__no-options"
|
||||
role="option"
|
||||
aria-selected={false}
|
||||
id={`${id}-no-hits`}
|
||||
>
|
||||
Ingen søketreff
|
||||
</li>
|
||||
)}
|
||||
{filteredOptions.map((option, index) => (
|
||||
<li
|
||||
className={cl("navds-combobox__list-item", {
|
||||
"navds-combobox__list-item--focus": index === filteredOptionsIndex,
|
||||
"navds-combobox__list-item--selected":
|
||||
selectedOptions.includes(option),
|
||||
})}
|
||||
id={`${id}-option-${option.replace(" ", "-")}`}
|
||||
key={option}
|
||||
tabIndex={-1}
|
||||
onPointerUp={(event) => {
|
||||
toggleOption(option, event);
|
||||
clearInput(event);
|
||||
if (!isMultiSelect) {
|
||||
toggleIsListOpen(false);
|
||||
}
|
||||
}}
|
||||
role="option"
|
||||
aria-selected={selectedOptions.includes(option)}
|
||||
>
|
||||
<BodyShort size={size}>{option}</BodyShort>
|
||||
{selectedOptions.includes(option) && <CheckmarkIcon />}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
);
|
||||
};
|
||||
|
||||
export default FilteredOptions;
|
||||
@@ -0,0 +1,266 @@
|
||||
import React, {
|
||||
useState,
|
||||
useEffect,
|
||||
useMemo,
|
||||
createContext,
|
||||
useContext,
|
||||
useCallback,
|
||||
useRef,
|
||||
useLayoutEffect,
|
||||
} from "react";
|
||||
import { useCustomOptionsContext } from "../customOptionsContext";
|
||||
import { useInputContext } from "../Input/inputContext";
|
||||
import usePrevious from "../../../util/usePrevious";
|
||||
|
||||
const normalizeText = (text: string): string =>
|
||||
typeof text === "string" ? `${text}`.toLowerCase().trim() : "";
|
||||
|
||||
const isPartOfText = (value, text) =>
|
||||
normalizeText(text).startsWith(normalizeText(value ?? ""));
|
||||
|
||||
const isValueInList = (value, list) =>
|
||||
list?.find((listItem) => normalizeText(value) === normalizeText(listItem));
|
||||
|
||||
const getMatchingValuesFromList = (value, list) =>
|
||||
list?.filter((listItem) => isPartOfText(value, listItem));
|
||||
|
||||
type FilteredOptionsContextType = {
|
||||
activeDecendantId?: string;
|
||||
allowNewValues?: boolean;
|
||||
ariaDescribedBy?: string;
|
||||
filteredOptionsRef: React.RefObject<HTMLUListElement>;
|
||||
filteredOptionsIndex: number | null;
|
||||
setFilteredOptionsIndex: (index: number) => void;
|
||||
isListOpen: boolean;
|
||||
isLoading?: boolean;
|
||||
filteredOptions: string[];
|
||||
isValueNew: boolean;
|
||||
toggleIsListOpen: (newState?: boolean) => void;
|
||||
currentOption: string | null;
|
||||
resetFilteredOptionsIndex: () => void;
|
||||
moveFocusUp: () => void;
|
||||
moveFocusDown: () => void;
|
||||
moveFocusToInput: () => void;
|
||||
moveFocusToEnd: () => void;
|
||||
shouldAutocomplete?: boolean;
|
||||
};
|
||||
const FilteredOptionsContext = createContext<FilteredOptionsContextType>(
|
||||
{} as FilteredOptionsContextType
|
||||
);
|
||||
|
||||
export const FilteredOptionsProvider = ({ children, value: props }) => {
|
||||
const {
|
||||
allowNewValues,
|
||||
filteredOptions: externalFilteredOptions,
|
||||
isListOpen: isExternalListOpen,
|
||||
isLoading,
|
||||
options,
|
||||
} = props;
|
||||
const filteredOptionsRef = useRef<HTMLUListElement | null>(null);
|
||||
const {
|
||||
inputProps: { id },
|
||||
value,
|
||||
searchTerm,
|
||||
setValue,
|
||||
setSearchTerm,
|
||||
shouldAutocomplete,
|
||||
} = useInputContext();
|
||||
|
||||
const [filteredOptionsIndex, setFilteredOptionsIndex] = useState<
|
||||
number | null
|
||||
>(null);
|
||||
const [isInternalListOpen, setInternalListOpen] = useState(false);
|
||||
const { customOptions } = useCustomOptionsContext();
|
||||
|
||||
const filteredOptions = useMemo(() => {
|
||||
if (externalFilteredOptions) {
|
||||
return externalFilteredOptions;
|
||||
}
|
||||
const opts = [...customOptions, ...options];
|
||||
setFilteredOptionsIndex(null);
|
||||
return getMatchingValuesFromList(searchTerm, opts);
|
||||
}, [customOptions, externalFilteredOptions, options, searchTerm]);
|
||||
|
||||
const previousSearchTerm = usePrevious(searchTerm);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (
|
||||
shouldAutocomplete &&
|
||||
normalizeText(searchTerm) !== "" &&
|
||||
(previousSearchTerm?.length || 0) < searchTerm.length &&
|
||||
filteredOptions.length > 0 &&
|
||||
!isValueInList(searchTerm, filteredOptions)
|
||||
) {
|
||||
setValue(
|
||||
`${searchTerm}${filteredOptions[0].substring(searchTerm.length)}`
|
||||
);
|
||||
setSearchTerm(searchTerm);
|
||||
}
|
||||
}, [
|
||||
filteredOptions,
|
||||
previousSearchTerm,
|
||||
searchTerm,
|
||||
setSearchTerm,
|
||||
setValue,
|
||||
shouldAutocomplete,
|
||||
]);
|
||||
|
||||
const isListOpen = useMemo(() => {
|
||||
return isExternalListOpen ?? isInternalListOpen;
|
||||
}, [isExternalListOpen, isInternalListOpen]);
|
||||
|
||||
const toggleIsListOpen = useCallback((newState?: boolean) => {
|
||||
setFilteredOptionsIndex(null);
|
||||
setInternalListOpen((oldState) => newState ?? !oldState);
|
||||
}, []);
|
||||
|
||||
const isValueNew = useMemo(
|
||||
() => Boolean(value) && !isValueInList(value, filteredOptions),
|
||||
[value, filteredOptions]
|
||||
);
|
||||
|
||||
const getMinimumIndex = useCallback(() => {
|
||||
return isValueNew && allowNewValues ? -1 : 0;
|
||||
}, [allowNewValues, isValueNew]);
|
||||
|
||||
const ariaDescribedBy = useMemo(() => {
|
||||
if (!isLoading && filteredOptions.length === 0) {
|
||||
return `${id}-no-hits`;
|
||||
} else if ((value && value !== "") || isLoading) {
|
||||
if (shouldAutocomplete && filteredOptions[0]) {
|
||||
return `${id}-option-${filteredOptions[0].replace(" ", "-")}`;
|
||||
} else if (isLoading) {
|
||||
return `${id}-is-loading`;
|
||||
}
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}, [isLoading, value, shouldAutocomplete, filteredOptions, id]);
|
||||
|
||||
const currentOption = useMemo(() => {
|
||||
if (filteredOptionsIndex == null) {
|
||||
return null;
|
||||
}
|
||||
if (filteredOptionsIndex === -1) {
|
||||
return value;
|
||||
}
|
||||
return filteredOptions[filteredOptionsIndex];
|
||||
}, [filteredOptionsIndex, filteredOptions, value]);
|
||||
|
||||
const resetFilteredOptionsIndex = () => {
|
||||
setFilteredOptionsIndex(getMinimumIndex());
|
||||
};
|
||||
|
||||
const scrollToOption = useCallback((newIndex: number) => {
|
||||
if (
|
||||
filteredOptionsRef.current &&
|
||||
filteredOptionsRef.current.children[newIndex]
|
||||
) {
|
||||
const child = filteredOptionsRef.current.children[newIndex];
|
||||
const { top, bottom } = child.getBoundingClientRect();
|
||||
const parentRect = filteredOptionsRef.current.getBoundingClientRect();
|
||||
if (top < parentRect.top || bottom > parentRect.bottom) {
|
||||
child.scrollIntoView({ block: "nearest" });
|
||||
}
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (filteredOptionsIndex !== null && isListOpen) {
|
||||
scrollToOption(filteredOptionsIndex);
|
||||
}
|
||||
}, [filteredOptionsIndex, isListOpen, scrollToOption]);
|
||||
|
||||
const moveFocusToInput = useCallback(() => {
|
||||
setFilteredOptionsIndex(null);
|
||||
toggleIsListOpen(false);
|
||||
}, [toggleIsListOpen]);
|
||||
|
||||
const moveFocusToEnd = useCallback(() => {
|
||||
const lastIndex = filteredOptions.length - 1;
|
||||
toggleIsListOpen(true);
|
||||
setFilteredOptionsIndex(lastIndex);
|
||||
}, [filteredOptions.length, toggleIsListOpen]);
|
||||
|
||||
const moveFocusUp = useCallback(() => {
|
||||
if (filteredOptionsIndex === null) {
|
||||
return;
|
||||
}
|
||||
if (filteredOptionsIndex === getMinimumIndex()) {
|
||||
toggleIsListOpen(false);
|
||||
setFilteredOptionsIndex(null);
|
||||
} else {
|
||||
const newIndex = Math.max(getMinimumIndex(), filteredOptionsIndex - 1);
|
||||
setFilteredOptionsIndex(newIndex);
|
||||
}
|
||||
}, [filteredOptionsIndex, getMinimumIndex, toggleIsListOpen]);
|
||||
|
||||
const moveFocusDown = useCallback(() => {
|
||||
if (filteredOptionsIndex === null || !isListOpen) {
|
||||
toggleIsListOpen(true);
|
||||
if (allowNewValues || filteredOptions.length >= 1) {
|
||||
setFilteredOptionsIndex(getMinimumIndex());
|
||||
}
|
||||
return;
|
||||
}
|
||||
const newIndex = Math.min(
|
||||
filteredOptionsIndex + 1,
|
||||
Math.max(getMinimumIndex(), filteredOptions.length - 1)
|
||||
);
|
||||
setFilteredOptionsIndex(newIndex);
|
||||
}, [
|
||||
allowNewValues,
|
||||
filteredOptions.length,
|
||||
filteredOptionsIndex,
|
||||
getMinimumIndex,
|
||||
isListOpen,
|
||||
toggleIsListOpen,
|
||||
]);
|
||||
|
||||
const activeDecendantId = useMemo(() => {
|
||||
if (filteredOptionsIndex === null) {
|
||||
return undefined;
|
||||
} else if (filteredOptionsIndex === -1) {
|
||||
return `${id}-combobox-new-option`;
|
||||
} else {
|
||||
return `${id}-option-${currentOption?.replace(" ", "-")}`;
|
||||
}
|
||||
}, [filteredOptionsIndex, currentOption, id]);
|
||||
|
||||
const filteredOptionsState = {
|
||||
activeDecendantId,
|
||||
allowNewValues,
|
||||
filteredOptionsRef,
|
||||
filteredOptionsIndex,
|
||||
setFilteredOptionsIndex,
|
||||
shouldAutocomplete,
|
||||
isListOpen,
|
||||
isLoading,
|
||||
filteredOptions,
|
||||
isValueNew,
|
||||
toggleIsListOpen,
|
||||
currentOption,
|
||||
resetFilteredOptionsIndex,
|
||||
moveFocusUp,
|
||||
moveFocusDown,
|
||||
moveFocusToInput,
|
||||
moveFocusToEnd,
|
||||
ariaDescribedBy,
|
||||
};
|
||||
|
||||
return (
|
||||
<FilteredOptionsContext.Provider value={filteredOptionsState}>
|
||||
{children}
|
||||
</FilteredOptionsContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useFilteredOptionsContext = () => {
|
||||
const context = useContext(FilteredOptionsContext);
|
||||
if (!context) {
|
||||
throw new Error(
|
||||
"useFilteredOptionsContext must be used within a FilteredOptionsProvider"
|
||||
);
|
||||
}
|
||||
return context;
|
||||
};
|
||||
@@ -0,0 +1,176 @@
|
||||
import { omit } from "../../..";
|
||||
import React, {
|
||||
useCallback,
|
||||
forwardRef,
|
||||
InputHTMLAttributes,
|
||||
ChangeEvent,
|
||||
} from "react";
|
||||
import cl from "clsx";
|
||||
import { useSelectedOptionsContext } from "../SelectedOptions/selectedOptionsContext";
|
||||
import { useFilteredOptionsContext } from "../FilteredOptions/filteredOptionsContext";
|
||||
import { useInputContext } from "./inputContext";
|
||||
|
||||
interface InputProps
|
||||
extends Omit<InputHTMLAttributes<HTMLInputElement>, "value"> {
|
||||
ref: React.Ref<HTMLInputElement>;
|
||||
inputClassName?: string;
|
||||
errorId?: string;
|
||||
value?: string;
|
||||
error?: React.ReactNode;
|
||||
}
|
||||
|
||||
const Input = forwardRef<HTMLInputElement, InputProps>(
|
||||
({ inputClassName, error, errorId, ...rest }, ref) => {
|
||||
const { clearInput, inputProps, onChange, size, value } = useInputContext();
|
||||
const { selectedOptions, removeSelectedOption, toggleOption } =
|
||||
useSelectedOptionsContext();
|
||||
const {
|
||||
activeDecendantId,
|
||||
allowNewValues,
|
||||
currentOption,
|
||||
filteredOptions,
|
||||
toggleIsListOpen,
|
||||
isListOpen,
|
||||
filteredOptionsIndex,
|
||||
moveFocusUp,
|
||||
moveFocusDown,
|
||||
ariaDescribedBy,
|
||||
moveFocusToInput,
|
||||
moveFocusToEnd,
|
||||
setFilteredOptionsIndex,
|
||||
shouldAutocomplete,
|
||||
} = useFilteredOptionsContext();
|
||||
|
||||
const onEnter = useCallback(
|
||||
(event: React.KeyboardEvent) => {
|
||||
if (currentOption) {
|
||||
event.preventDefault();
|
||||
// Selecting a value from the dropdown / FilteredOptions
|
||||
toggleOption(currentOption, event);
|
||||
clearInput(event);
|
||||
} else if (shouldAutocomplete && selectedOptions.includes(value)) {
|
||||
event.preventDefault();
|
||||
// Trying to set the same value that is already set, so just clearing the input
|
||||
clearInput(event);
|
||||
} else if ((allowNewValues || shouldAutocomplete) && value !== "") {
|
||||
event.preventDefault();
|
||||
// Autocompleting or adding a new value
|
||||
toggleOption(value, event);
|
||||
clearInput(event);
|
||||
}
|
||||
},
|
||||
[
|
||||
allowNewValues,
|
||||
clearInput,
|
||||
currentOption,
|
||||
selectedOptions,
|
||||
shouldAutocomplete,
|
||||
toggleOption,
|
||||
value,
|
||||
]
|
||||
);
|
||||
|
||||
const handleKeyUp = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
||||
e.preventDefault();
|
||||
switch (e.key) {
|
||||
case "Escape":
|
||||
clearInput(e);
|
||||
toggleIsListOpen(false);
|
||||
break;
|
||||
case "Enter":
|
||||
case "Accept":
|
||||
onEnter(e);
|
||||
break;
|
||||
case "Home":
|
||||
moveFocusToInput();
|
||||
break;
|
||||
case "End":
|
||||
moveFocusToEnd();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
const handleKeyDown = useCallback(
|
||||
(e) => {
|
||||
if (e.key === "Backspace") {
|
||||
if (value === "") {
|
||||
const lastSelectedOption =
|
||||
selectedOptions[selectedOptions.length - 1];
|
||||
removeSelectedOption(lastSelectedOption);
|
||||
}
|
||||
} else if (e.key === "ArrowDown") {
|
||||
// Check that cursor position is at the end of the input field,
|
||||
// so we don't interfere with text editing
|
||||
if (e.target.selectionStart === value?.length) {
|
||||
e.preventDefault();
|
||||
moveFocusDown();
|
||||
}
|
||||
} else if (e.key === "ArrowUp") {
|
||||
// Check that the FilteredOptions list is open and has virtual focus.
|
||||
// Otherwise ignore keystrokes, so it doesn't interfere with text editing
|
||||
if (isListOpen && filteredOptionsIndex !== null) {
|
||||
e.preventDefault();
|
||||
moveFocusUp();
|
||||
}
|
||||
}
|
||||
},
|
||||
[
|
||||
value,
|
||||
selectedOptions,
|
||||
removeSelectedOption,
|
||||
moveFocusDown,
|
||||
isListOpen,
|
||||
filteredOptionsIndex,
|
||||
moveFocusUp,
|
||||
]
|
||||
);
|
||||
|
||||
const onChangeHandler = useCallback(
|
||||
(event: ChangeEvent<HTMLInputElement>) => {
|
||||
const newValue = event.target.value;
|
||||
if (newValue && newValue !== "") {
|
||||
toggleIsListOpen(true);
|
||||
} else if (filteredOptions.length === 0) {
|
||||
toggleIsListOpen(false);
|
||||
}
|
||||
onChange(event);
|
||||
},
|
||||
[filteredOptions.length, onChange, toggleIsListOpen]
|
||||
);
|
||||
|
||||
const onBlur = () => {
|
||||
setFilteredOptionsIndex(-1);
|
||||
};
|
||||
|
||||
return (
|
||||
<input
|
||||
{...rest}
|
||||
{...omit(inputProps, ["aria-invalid"])}
|
||||
ref={ref}
|
||||
value={value}
|
||||
onChange={onChangeHandler}
|
||||
type="text"
|
||||
role="combobox"
|
||||
onBlur={onBlur}
|
||||
onKeyUp={handleKeyUp}
|
||||
onKeyDown={handleKeyDown}
|
||||
aria-controls={`${inputProps.id}-filtered-options`}
|
||||
aria-expanded={!!isListOpen}
|
||||
autoComplete="off"
|
||||
aria-autocomplete={shouldAutocomplete ? "both" : "list"}
|
||||
aria-activedescendant={activeDecendantId}
|
||||
aria-describedby={ariaDescribedBy}
|
||||
className={cl(
|
||||
inputClassName,
|
||||
"navds-combobox__input",
|
||||
"navds-body-short",
|
||||
`navds-body-${size}`
|
||||
)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
export default Input;
|
||||
@@ -0,0 +1,127 @@
|
||||
import React, {
|
||||
ChangeEvent,
|
||||
ChangeEventHandler,
|
||||
createContext,
|
||||
useCallback,
|
||||
useContext,
|
||||
useLayoutEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
import { useFormField, FormFieldType } from "../../useFormField";
|
||||
|
||||
interface InputContextType extends FormFieldType {
|
||||
clearInput: (event: React.PointerEvent | React.KeyboardEvent) => void;
|
||||
focusInput: () => void;
|
||||
inputRef: React.RefObject<HTMLInputElement>;
|
||||
value: string;
|
||||
setValue: (text: string) => void;
|
||||
onChange: ChangeEventHandler<HTMLInputElement>;
|
||||
searchTerm: string;
|
||||
setSearchTerm: React.Dispatch<React.SetStateAction<string>>;
|
||||
shouldAutocomplete?: boolean;
|
||||
}
|
||||
|
||||
const InputContext = createContext<InputContextType>({} as InputContextType);
|
||||
|
||||
export const InputContextProvider = ({ children, value: props }) => {
|
||||
const {
|
||||
defaultValue = "",
|
||||
description,
|
||||
disabled,
|
||||
error,
|
||||
errorId,
|
||||
id: externalId,
|
||||
value: externalValue,
|
||||
onChange: externalOnChange,
|
||||
onClear,
|
||||
shouldAutocomplete,
|
||||
size,
|
||||
} = props;
|
||||
const formFieldProps = useFormField(
|
||||
{
|
||||
description,
|
||||
disabled,
|
||||
error,
|
||||
errorId,
|
||||
id: externalId,
|
||||
size,
|
||||
},
|
||||
"comboboxfield"
|
||||
);
|
||||
const inputRef = useRef<HTMLInputElement | null>(null);
|
||||
const [internalValue, setInternalValue] = useState<string>(defaultValue);
|
||||
|
||||
const value = useMemo(
|
||||
() => String(externalValue ?? internalValue),
|
||||
[externalValue, internalValue]
|
||||
);
|
||||
|
||||
const [searchTerm, setSearchTerm] = useState(value);
|
||||
|
||||
const onChange = useCallback(
|
||||
(event: ChangeEvent<HTMLInputElement>) => {
|
||||
const value = event.currentTarget.value;
|
||||
externalValue ?? setInternalValue(value);
|
||||
externalOnChange?.(event);
|
||||
setSearchTerm(value);
|
||||
},
|
||||
[externalValue, externalOnChange]
|
||||
);
|
||||
|
||||
const setValue = useCallback(
|
||||
(text) => {
|
||||
setInternalValue(text);
|
||||
},
|
||||
[setInternalValue]
|
||||
);
|
||||
|
||||
const clearInput = useCallback(
|
||||
(event: React.PointerEvent | React.KeyboardEvent) => {
|
||||
onClear?.(event);
|
||||
setValue("");
|
||||
setSearchTerm("");
|
||||
},
|
||||
[onClear, setSearchTerm, setValue]
|
||||
);
|
||||
|
||||
const focusInput = useCallback(() => {
|
||||
inputRef.current?.focus?.();
|
||||
}, []);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (shouldAutocomplete && inputRef && value !== searchTerm) {
|
||||
inputRef.current?.setSelectionRange?.(searchTerm.length, value.length);
|
||||
}
|
||||
}, [value, searchTerm, shouldAutocomplete]);
|
||||
|
||||
return (
|
||||
<InputContext.Provider
|
||||
value={{
|
||||
...formFieldProps,
|
||||
clearInput,
|
||||
focusInput,
|
||||
inputRef,
|
||||
value,
|
||||
setValue,
|
||||
onChange,
|
||||
searchTerm,
|
||||
setSearchTerm,
|
||||
shouldAutocomplete,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</InputContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useInputContext = () => {
|
||||
const context = useContext(InputContext);
|
||||
if (!context) {
|
||||
throw new Error(
|
||||
"useInputContext must be used within an InputContextProvider"
|
||||
);
|
||||
}
|
||||
return context;
|
||||
};
|
||||
@@ -0,0 +1,48 @@
|
||||
import React from "react";
|
||||
import { Chips } from "../../..";
|
||||
import { useSelectedOptionsContext } from "./selectedOptionsContext";
|
||||
import { useInputContext } from "../Input/inputContext";
|
||||
|
||||
interface SelectedOptionsProps {
|
||||
selectedOptions?: string[];
|
||||
size?: "medium" | "small";
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
const Option = ({ option }: { option: string }) => {
|
||||
const { isMultiSelect, removeSelectedOption } = useSelectedOptionsContext();
|
||||
const { focusInput } = useInputContext();
|
||||
|
||||
const onClick = (e) => {
|
||||
e.stopPropagation();
|
||||
removeSelectedOption(option);
|
||||
focusInput();
|
||||
};
|
||||
|
||||
if (!isMultiSelect) {
|
||||
return (
|
||||
<div className="navds-combobox__selected-options--no-bg">{option}</div>
|
||||
);
|
||||
}
|
||||
|
||||
return <Chips.Removable onClick={onClick}>{option}</Chips.Removable>;
|
||||
};
|
||||
|
||||
const SelectedOptions: React.FC<SelectedOptionsProps> = ({
|
||||
selectedOptions = [],
|
||||
size,
|
||||
children,
|
||||
}) => {
|
||||
return (
|
||||
<Chips className="navds-combobox__selected-options" size={size}>
|
||||
{selectedOptions.length
|
||||
? selectedOptions.map((option, i) => (
|
||||
<Option key={option + i} option={option} />
|
||||
))
|
||||
: []}
|
||||
{children}
|
||||
</Chips>
|
||||
);
|
||||
};
|
||||
|
||||
export default SelectedOptions;
|
||||
@@ -0,0 +1,147 @@
|
||||
import React, {
|
||||
createContext,
|
||||
useCallback,
|
||||
useContext,
|
||||
useMemo,
|
||||
useState,
|
||||
} from "react";
|
||||
import usePrevious from "../../../util/usePrevious";
|
||||
import { useInputContext } from "../Input/inputContext";
|
||||
import { ComboboxProps } from "../types";
|
||||
import { useCustomOptionsContext } from "../customOptionsContext";
|
||||
|
||||
type SelectedOptionsContextType = {
|
||||
addSelectedOption: (option: string) => void;
|
||||
isMultiSelect?: boolean;
|
||||
removeSelectedOption: (option: string) => void;
|
||||
prevSelectedOptions?: string[];
|
||||
selectedOptions: string[];
|
||||
setSelectedOptions: (any) => void;
|
||||
toggleOption: (
|
||||
option: string,
|
||||
event: React.KeyboardEvent | React.PointerEvent
|
||||
) => void;
|
||||
};
|
||||
|
||||
const SelectedOptionsContext = createContext<SelectedOptionsContextType>(
|
||||
{} as SelectedOptionsContextType
|
||||
);
|
||||
|
||||
export const SelectedOptionsProvider = ({
|
||||
children,
|
||||
value,
|
||||
}: {
|
||||
children: any;
|
||||
value: Pick<
|
||||
ComboboxProps,
|
||||
| "allowNewValues"
|
||||
| "isMultiSelect"
|
||||
| "options"
|
||||
| "selectedOptions"
|
||||
| "onToggleSelected"
|
||||
>;
|
||||
}) => {
|
||||
const { clearInput, focusInput } = useInputContext();
|
||||
const { customOptions, removeCustomOption, addCustomOption } =
|
||||
useCustomOptionsContext();
|
||||
const {
|
||||
allowNewValues,
|
||||
isMultiSelect,
|
||||
selectedOptions: externalSelectedOptions,
|
||||
onToggleSelected,
|
||||
options,
|
||||
} = value;
|
||||
const [internalSelectedOptions, setSelectedOptions] = useState<string[]>([]);
|
||||
const selectedOptions = useMemo(
|
||||
() =>
|
||||
externalSelectedOptions ?? [...customOptions, ...internalSelectedOptions],
|
||||
[customOptions, externalSelectedOptions, internalSelectedOptions]
|
||||
);
|
||||
|
||||
const addSelectedOption = useCallback(
|
||||
(option: string) => {
|
||||
const isAddedByUser = !options
|
||||
.map((opt) => opt.toLowerCase())
|
||||
.includes(option?.toLowerCase?.());
|
||||
if (isAddedByUser) {
|
||||
allowNewValues && addCustomOption(option);
|
||||
} else if (isMultiSelect) {
|
||||
setSelectedOptions((prevSelectedOptions) => [
|
||||
...prevSelectedOptions,
|
||||
option,
|
||||
]);
|
||||
} else {
|
||||
setSelectedOptions([option]);
|
||||
}
|
||||
onToggleSelected?.(option, true, isAddedByUser);
|
||||
},
|
||||
[addCustomOption, allowNewValues, isMultiSelect, onToggleSelected, options]
|
||||
);
|
||||
|
||||
const removeSelectedOption = useCallback(
|
||||
(option: string) => {
|
||||
const isAddedByUser = customOptions.includes(option);
|
||||
if (isAddedByUser) {
|
||||
removeCustomOption(option);
|
||||
} else {
|
||||
setSelectedOptions((prevSelectedOptions) =>
|
||||
prevSelectedOptions.filter(
|
||||
(selectedOption) => selectedOption !== option
|
||||
)
|
||||
);
|
||||
}
|
||||
onToggleSelected?.(option, false, isAddedByUser);
|
||||
},
|
||||
[customOptions, onToggleSelected, removeCustomOption]
|
||||
);
|
||||
|
||||
const toggleOption = useCallback(
|
||||
(option: string, event: React.KeyboardEvent | React.PointerEvent) => {
|
||||
if (selectedOptions.includes(option)) {
|
||||
removeSelectedOption(option);
|
||||
} else {
|
||||
addSelectedOption(option);
|
||||
}
|
||||
if (!isMultiSelect) {
|
||||
clearInput(event);
|
||||
}
|
||||
focusInput();
|
||||
},
|
||||
[
|
||||
addSelectedOption,
|
||||
clearInput,
|
||||
focusInput,
|
||||
isMultiSelect,
|
||||
removeSelectedOption,
|
||||
selectedOptions,
|
||||
]
|
||||
);
|
||||
|
||||
const prevSelectedOptions = usePrevious<string[]>(selectedOptions);
|
||||
|
||||
const selectedOptionsState = {
|
||||
addSelectedOption,
|
||||
isMultiSelect,
|
||||
removeSelectedOption,
|
||||
prevSelectedOptions,
|
||||
selectedOptions,
|
||||
setSelectedOptions,
|
||||
toggleOption,
|
||||
};
|
||||
|
||||
return (
|
||||
<SelectedOptionsContext.Provider value={selectedOptionsState}>
|
||||
{children}
|
||||
</SelectedOptionsContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useSelectedOptionsContext = () => {
|
||||
const context = useContext(SelectedOptionsContext);
|
||||
if (!context) {
|
||||
throw new Error(
|
||||
"useSelectedOptionsContext must be used within a SelectedOptionsProvider"
|
||||
);
|
||||
}
|
||||
return context;
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
import React, { forwardRef } from "react";
|
||||
import { ChevronUpIcon, ChevronDownIcon } from "@navikt/aksel-icons";
|
||||
|
||||
import { useFilteredOptionsContext } from "./FilteredOptions/filteredOptionsContext";
|
||||
|
||||
interface ToggleListButtonProps {
|
||||
toggleListButtonLabel?: string;
|
||||
}
|
||||
|
||||
export const ToggleListButton = forwardRef<
|
||||
HTMLButtonElement,
|
||||
ToggleListButtonProps
|
||||
>(({ toggleListButtonLabel }, ref) => {
|
||||
const { isListOpen, toggleIsListOpen } = useFilteredOptionsContext();
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onPointerUp={() => toggleIsListOpen()}
|
||||
onKeyDown={({ key }) => key === "Enter" && toggleIsListOpen()}
|
||||
className="navds-combobox__button-toggle-list"
|
||||
aria-expanded={isListOpen}
|
||||
tabIndex={-1}
|
||||
ref={ref}
|
||||
>
|
||||
<span className="navds-sr-only">
|
||||
{toggleListButtonLabel ?? "Alternativer"}
|
||||
</span>
|
||||
{isListOpen ? (
|
||||
<ChevronUpIcon aria-hidden />
|
||||
) : (
|
||||
<ChevronDownIcon aria-hidden />
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
});
|
||||
|
||||
export default ToggleListButton;
|
||||
@@ -0,0 +1,423 @@
|
||||
/* eslint-disable react-hooks/rules-of-hooks */
|
||||
import { Meta } from "@storybook/react";
|
||||
import React, { useState, useId, useMemo } from "react";
|
||||
import { userEvent, within } from "@storybook/testing-library";
|
||||
import { Chips, UNSAFE_Combobox, TextField } from "../../index";
|
||||
import { expect } from "@storybook/jest";
|
||||
|
||||
export default {
|
||||
title: "ds-react/Combobox",
|
||||
component: UNSAFE_Combobox,
|
||||
argTypes: {
|
||||
isListOpen: {
|
||||
control: {
|
||||
type: "boolean",
|
||||
},
|
||||
},
|
||||
isLoading: {
|
||||
control: {
|
||||
type: "boolean",
|
||||
},
|
||||
},
|
||||
},
|
||||
} as Meta;
|
||||
|
||||
const options = [
|
||||
"banana",
|
||||
"apple",
|
||||
"apple pie",
|
||||
"tangerine",
|
||||
"pear",
|
||||
"grape",
|
||||
"kiwi",
|
||||
"mango",
|
||||
"passion fruit",
|
||||
"pineapple",
|
||||
"strawberry",
|
||||
"watermelon",
|
||||
"grape fruit",
|
||||
];
|
||||
|
||||
const initialSelectedOptions = ["passion fruit", "grape fruit"];
|
||||
|
||||
const DemoContainer = ({
|
||||
dataTheme,
|
||||
children,
|
||||
}: {
|
||||
children: any;
|
||||
dataTheme: "dark" | "light";
|
||||
}) => (
|
||||
<div data-theme={dataTheme} style={{ width: "300px" }}>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
|
||||
export const Default = (props) => {
|
||||
const id = useId();
|
||||
return (
|
||||
<DemoContainer dataTheme={props.darkMode}>
|
||||
<UNSAFE_Combobox
|
||||
options={props.options}
|
||||
label="Hva er dine favorittfrukter?"
|
||||
/* everything under here is optional? */
|
||||
shouldAutocomplete={props.shouldAutoComplete}
|
||||
size="medium"
|
||||
id={id}
|
||||
/>
|
||||
</DemoContainer>
|
||||
);
|
||||
};
|
||||
|
||||
Default.args = {
|
||||
options,
|
||||
shouldAutoComplete: true,
|
||||
};
|
||||
|
||||
export function MultiSelect(props) {
|
||||
const id = useId();
|
||||
return (
|
||||
<DemoContainer dataTheme={props.darkMode}>
|
||||
<UNSAFE_Combobox
|
||||
id={id}
|
||||
label="Komboboks - velg flere"
|
||||
options={props.options}
|
||||
isMultiSelect={props.isMultiSelect}
|
||||
size={props.size}
|
||||
/>
|
||||
</DemoContainer>
|
||||
);
|
||||
}
|
||||
|
||||
MultiSelect.args = {
|
||||
options,
|
||||
isMultiSelect: true,
|
||||
size: "medium",
|
||||
};
|
||||
|
||||
export function MultiSelectWithAddNewOptions(props) {
|
||||
const id = useId();
|
||||
return (
|
||||
<DemoContainer dataTheme={props.darkMode}>
|
||||
<UNSAFE_Combobox
|
||||
id={id}
|
||||
isMultiSelect={props.isMultiSelect}
|
||||
label="Komboboks (med mulighet for å legge til nye verdier)"
|
||||
options={props.options}
|
||||
allowNewValues={props.allowNewValues}
|
||||
/>
|
||||
</DemoContainer>
|
||||
);
|
||||
}
|
||||
|
||||
MultiSelectWithAddNewOptions.args = {
|
||||
allowNewValues: true,
|
||||
isMultiSelect: true,
|
||||
options,
|
||||
shouldAutocomplete: false,
|
||||
};
|
||||
|
||||
export const MultiSelectWithExternalChips = (props) => {
|
||||
const [selectedOptions, setSelectedOptions] = useState<string[]>(
|
||||
props.selectedOptions
|
||||
);
|
||||
const [value, setValue] = useState("");
|
||||
const id = useId();
|
||||
|
||||
const toggleSelected = (option) =>
|
||||
selectedOptions.includes(option)
|
||||
? setSelectedOptions(selectedOptions.filter((opt) => opt !== option))
|
||||
: setSelectedOptions([...selectedOptions, option]);
|
||||
return (
|
||||
<DemoContainer dataTheme={props.darkMode}>
|
||||
{selectedOptions && (
|
||||
<Chips>
|
||||
{selectedOptions.map((option) => (
|
||||
<Chips.Removable
|
||||
key={option}
|
||||
onPointerUp={() => toggleSelected(option)}
|
||||
onKeyUp={(e) => e.key === "Enter" && toggleSelected(option)}
|
||||
>
|
||||
{option}
|
||||
</Chips.Removable>
|
||||
))}
|
||||
</Chips>
|
||||
)}
|
||||
<UNSAFE_Combobox
|
||||
options={options}
|
||||
selectedOptions={selectedOptions}
|
||||
onToggleSelected={(option: string) => toggleSelected(option)}
|
||||
isListOpen={props.isListOpen}
|
||||
isMultiSelect
|
||||
value={props.controlled ? value : undefined}
|
||||
onChange={(event) =>
|
||||
props.controlled ? setValue(event.currentTarget.value) : undefined
|
||||
}
|
||||
label="Komboboks"
|
||||
size="medium"
|
||||
error={props.error && "error here"}
|
||||
id={id}
|
||||
shouldShowSelectedOptions={false}
|
||||
/>
|
||||
</DemoContainer>
|
||||
);
|
||||
};
|
||||
|
||||
MultiSelectWithExternalChips.args = {
|
||||
controlled: false,
|
||||
options,
|
||||
selectedOptions: [],
|
||||
};
|
||||
|
||||
export function Loading(props) {
|
||||
const id = useId();
|
||||
return (
|
||||
<DemoContainer dataTheme={props.darkMode}>
|
||||
<UNSAFE_Combobox
|
||||
id={id}
|
||||
label="Komboboks (laster)"
|
||||
options={[]}
|
||||
selectedOptions={[]}
|
||||
isListOpen={props.isListOpen}
|
||||
isLoading={props.isLoading}
|
||||
/>
|
||||
</DemoContainer>
|
||||
);
|
||||
}
|
||||
|
||||
Loading.args = {
|
||||
isLoading: true,
|
||||
isListOpen: true,
|
||||
};
|
||||
|
||||
export function ComboboxWithNoHits(props) {
|
||||
const id = useId();
|
||||
const [value, setValue] = useState(props.value);
|
||||
return (
|
||||
<DemoContainer dataTheme={props.darkMode}>
|
||||
<UNSAFE_Combobox
|
||||
id={id}
|
||||
label="Komboboks (uten søketreff)"
|
||||
options={props.options}
|
||||
value={value}
|
||||
onChange={(event) => setValue(event.currentTarget.value)}
|
||||
isListOpen={true}
|
||||
/>
|
||||
</DemoContainer>
|
||||
);
|
||||
}
|
||||
|
||||
ComboboxWithNoHits.args = {
|
||||
options,
|
||||
value: "Orange",
|
||||
};
|
||||
|
||||
export const Controlled = (props) => {
|
||||
const id = useId();
|
||||
const [value, setValue] = useState(props.value);
|
||||
const [selectedOptions, setSelectedOptions] = useState(props.selectedOptions);
|
||||
const filteredOptions = useMemo(
|
||||
() => props.options.filter((option) => option.includes(value)),
|
||||
[props.options, value]
|
||||
);
|
||||
|
||||
const onToggleSelected = (option, isSelected) => {
|
||||
if (isSelected) {
|
||||
setSelectedOptions([...selectedOptions, option]);
|
||||
} else {
|
||||
setSelectedOptions(selectedOptions.filter((o) => o !== option));
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<DemoContainer dataTheme={props.darkMode}>
|
||||
<TextField
|
||||
label="Overstyr value"
|
||||
onChange={(event) => setValue(event.target.value)}
|
||||
value={value}
|
||||
/>
|
||||
<br />
|
||||
<UNSAFE_Combobox
|
||||
label="Hva er dine favorittfrukter?"
|
||||
id={id}
|
||||
filteredOptions={filteredOptions}
|
||||
isMultiSelect
|
||||
options={props.options}
|
||||
onChange={(event) => setValue(event.target.value)}
|
||||
onToggleSelected={onToggleSelected}
|
||||
selectedOptions={selectedOptions}
|
||||
value={value}
|
||||
/>
|
||||
</DemoContainer>
|
||||
);
|
||||
};
|
||||
|
||||
Controlled.args = {
|
||||
value: "apple",
|
||||
options,
|
||||
selectedOptions: initialSelectedOptions,
|
||||
};
|
||||
|
||||
export const ComboboxSizes = (props) => (
|
||||
<DemoContainer dataTheme={props.darkMode}>
|
||||
<UNSAFE_Combobox
|
||||
label="Hva er dine favorittfrukter?"
|
||||
description="Medium single-select"
|
||||
options={options}
|
||||
/>
|
||||
<br />
|
||||
<UNSAFE_Combobox
|
||||
label="Hva er dine favorittfrukter?"
|
||||
description="Small single-select"
|
||||
options={options}
|
||||
size="small"
|
||||
/>
|
||||
<br />
|
||||
<UNSAFE_Combobox
|
||||
label="Hva er dine favorittfrukter?"
|
||||
description="Medium multiselect"
|
||||
options={options}
|
||||
isMultiSelect
|
||||
allowNewValues
|
||||
/>
|
||||
<br />
|
||||
<UNSAFE_Combobox
|
||||
label="Hva er dine favorittfrukter?"
|
||||
description="Small multiselect"
|
||||
options={options}
|
||||
isMultiSelect
|
||||
size="small"
|
||||
allowNewValues
|
||||
/>
|
||||
</DemoContainer>
|
||||
);
|
||||
|
||||
ComboboxSizes.args = {
|
||||
options,
|
||||
};
|
||||
|
||||
function sleep(ms: number) {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
export const CancelInputTest = {
|
||||
render: (props) => {
|
||||
return (
|
||||
<DemoContainer dataTheme={props.darkMode}>
|
||||
<UNSAFE_Combobox
|
||||
options={options}
|
||||
label="Hva er dine favorittfrukter?"
|
||||
/>
|
||||
</DemoContainer>
|
||||
);
|
||||
},
|
||||
play: async ({ canvasElement }) => {
|
||||
const canvas = within(canvasElement);
|
||||
|
||||
const input = canvas.getByLabelText("Hva er dine favorittfrukter?");
|
||||
|
||||
userEvent.click(input);
|
||||
await userEvent.type(input, "apple", { delay: 200 });
|
||||
await sleep(1000);
|
||||
|
||||
userEvent.keyboard("{ArrowDown}");
|
||||
await sleep(1000);
|
||||
userEvent.keyboard("{Escape}");
|
||||
await sleep(1000);
|
||||
userEvent.keyboard("{ArrowDown}");
|
||||
const banana = canvas.getByText("banana");
|
||||
userEvent.click(banana);
|
||||
},
|
||||
};
|
||||
|
||||
export const RemoveSelectedMultiSelectTest = {
|
||||
render: (props) => {
|
||||
return (
|
||||
<DemoContainer dataTheme={props.darkMode}>
|
||||
<UNSAFE_Combobox
|
||||
options={options}
|
||||
label="Hva er dine favorittfrukter?"
|
||||
isMultiSelect
|
||||
/>
|
||||
</DemoContainer>
|
||||
);
|
||||
},
|
||||
play: async ({ canvasElement }) => {
|
||||
const canvas = within(canvasElement);
|
||||
|
||||
const input = canvas.getByLabelText("Hva er dine favorittfrukter?");
|
||||
|
||||
userEvent.click(input);
|
||||
await userEvent.type(input, "apple", { delay: 200 });
|
||||
await sleep(250);
|
||||
|
||||
userEvent.keyboard("{ArrowDown}");
|
||||
await sleep(250);
|
||||
userEvent.keyboard("{Enter}");
|
||||
await sleep(250);
|
||||
userEvent.keyboard("{Escape}");
|
||||
await sleep(250);
|
||||
|
||||
userEvent.click(input);
|
||||
await userEvent.type(input, "banana", { delay: 200 });
|
||||
await sleep(250);
|
||||
|
||||
userEvent.keyboard("{ArrowDown}");
|
||||
await sleep(250);
|
||||
userEvent.keyboard("{Enter}");
|
||||
await sleep(250);
|
||||
|
||||
const appleSlett = canvas.getByLabelText("apple slett");
|
||||
appleSlett.focus();
|
||||
await sleep(250);
|
||||
userEvent.click(appleSlett);
|
||||
await sleep(250);
|
||||
const appleOption = canvas.getByRole("option", {
|
||||
name: "apple",
|
||||
selected: false,
|
||||
});
|
||||
expect(appleOption).toBeVisible();
|
||||
userEvent.keyboard("{Escape}");
|
||||
await sleep(250);
|
||||
expect(appleOption).not.toBeVisible();
|
||||
|
||||
const bananaSlett = canvas.getByLabelText("banana slett");
|
||||
expect(bananaSlett).toBeInTheDocument();
|
||||
const appleSlettAgain = canvas.queryByLabelText("apple slett");
|
||||
expect(appleSlettAgain).not.toBeInTheDocument();
|
||||
},
|
||||
};
|
||||
|
||||
export const AddWhenAddNewDisabledTest = {
|
||||
render: (props) => {
|
||||
return (
|
||||
<DemoContainer dataTheme={props.darkMode}>
|
||||
<UNSAFE_Combobox
|
||||
options={options}
|
||||
label="Hva er dine favorittfrukter?"
|
||||
isMultiSelect
|
||||
/>
|
||||
</DemoContainer>
|
||||
);
|
||||
},
|
||||
play: async ({ canvasElement }) => {
|
||||
const canvas = within(canvasElement);
|
||||
|
||||
const input = canvas.getByLabelText("Hva er dine favorittfrukter?");
|
||||
|
||||
userEvent.click(input);
|
||||
await userEvent.type(input, "aaa", { delay: 200 });
|
||||
await sleep(250);
|
||||
|
||||
userEvent.keyboard("{ArrowDown}");
|
||||
await sleep(250);
|
||||
userEvent.keyboard("{ArrowDown}");
|
||||
await sleep(250);
|
||||
userEvent.keyboard("{Enter}");
|
||||
await sleep(250);
|
||||
userEvent.keyboard("{Escape}");
|
||||
await sleep(250);
|
||||
|
||||
const invalidSelect = canvas.queryByLabelText("aaa slett");
|
||||
expect(invalidSelect).not.toBeInTheDocument();
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,123 @@
|
||||
/* eslint-disable react/jsx-pascal-case */
|
||||
import { render } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import React, { useId } from "react";
|
||||
import { UNSAFE_Combobox } from "..";
|
||||
import { act } from "react-dom/test-utils";
|
||||
|
||||
const options = [
|
||||
"banana",
|
||||
"apple",
|
||||
"tangerine",
|
||||
"pear",
|
||||
"grape",
|
||||
"kiwi",
|
||||
"mango",
|
||||
"passion fruit",
|
||||
"pineapple",
|
||||
"strawberry",
|
||||
"watermelon",
|
||||
"grape fruit",
|
||||
];
|
||||
|
||||
const App = (props) => {
|
||||
const id = useId();
|
||||
return (
|
||||
<div data-theme="light">
|
||||
<UNSAFE_Combobox
|
||||
label="Hva er dine favorittfrukter?"
|
||||
size="medium"
|
||||
variant="simple"
|
||||
id={id}
|
||||
{...props}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
describe("Render combobox", () => {
|
||||
describe("with multi select", () => {
|
||||
it("Should be able to search, select and remove selections", async () => {
|
||||
const utils = render(<App isMultiSelect options={options} />);
|
||||
|
||||
await act(async () => {
|
||||
await userEvent.click(
|
||||
utils.getByRole("combobox", { name: "Hva er dine favorittfrukter?" })
|
||||
);
|
||||
});
|
||||
await act(async () => {
|
||||
await userEvent.type(
|
||||
utils.getByRole("combobox", { name: "Hva er dine favorittfrukter?" }),
|
||||
"apple"
|
||||
);
|
||||
});
|
||||
await act(async () => {
|
||||
await userEvent.click(
|
||||
await utils.findByRole("option", { name: "apple" })
|
||||
);
|
||||
});
|
||||
expect(
|
||||
await utils.findByRole("option", { name: "apple", selected: true })
|
||||
).toBeInTheDocument();
|
||||
await act(async () => {
|
||||
await userEvent.click(
|
||||
await utils.findByRole("button", { name: "apple slett" })
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("Should show loading icon when loading (used for async search)", async () => {
|
||||
const utils = render(<App options={[]} isListOpen isLoading />);
|
||||
|
||||
expect(await utils.findByRole("option", { name: "venter..." }));
|
||||
});
|
||||
});
|
||||
|
||||
describe("Combobox state-handling", () => {
|
||||
it("Should not select previous focused element when closes", async () => {
|
||||
const utils = render(<App options={options} />);
|
||||
|
||||
await act(async () => {
|
||||
await userEvent.click(
|
||||
utils.getByRole("combobox", { name: "Hva er dine favorittfrukter?" })
|
||||
);
|
||||
});
|
||||
await act(async () => {
|
||||
await userEvent.type(
|
||||
utils.getByRole("combobox", { name: "Hva er dine favorittfrukter?" }),
|
||||
"ban"
|
||||
);
|
||||
await userEvent.keyboard("{ArrowDown}");
|
||||
await userEvent.keyboard("{ArrowUp}");
|
||||
await userEvent.keyboard("{Enter}");
|
||||
});
|
||||
|
||||
expect(
|
||||
await utils.queryByRole("button", { name: "banana slett" })
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("Should reset list when resetting input (ESC)", async () => {
|
||||
const utils = render(<App options={options} />);
|
||||
|
||||
await act(async () => {
|
||||
await userEvent.click(
|
||||
utils.getByRole("combobox", { name: "Hva er dine favorittfrukter?" })
|
||||
);
|
||||
});
|
||||
await act(async () => {
|
||||
await userEvent.type(
|
||||
utils.getByRole("combobox", { name: "Hva er dine favorittfrukter?" }),
|
||||
"apple"
|
||||
);
|
||||
await userEvent.keyboard("{ArrowDown}");
|
||||
await userEvent.keyboard("{Escape}");
|
||||
await userEvent.keyboard("{ArrowDown}");
|
||||
});
|
||||
|
||||
expect(
|
||||
await utils.findByRole("option", { name: "banana" })
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,57 @@
|
||||
import React, { useState, useCallback, createContext, useContext } from "react";
|
||||
import { useInputContext } from "./Input/inputContext";
|
||||
|
||||
type CustomOptionsContextType = {
|
||||
customOptions: string[];
|
||||
removeCustomOption: (option: string) => void;
|
||||
addCustomOption: (option: string) => void;
|
||||
};
|
||||
|
||||
const CustomOptionsContext = createContext<CustomOptionsContextType>(
|
||||
{} as CustomOptionsContextType
|
||||
);
|
||||
|
||||
export const CustomOptionsProvider = ({ children }) => {
|
||||
const [customOptions, setCustomOptions] = useState<string[]>([]);
|
||||
const { focusInput } = useInputContext();
|
||||
|
||||
const removeCustomOption = useCallback(
|
||||
(option) => {
|
||||
setCustomOptions((prevCustomOptions) =>
|
||||
prevCustomOptions.filter((o) => o !== option)
|
||||
);
|
||||
focusInput();
|
||||
},
|
||||
[focusInput, setCustomOptions]
|
||||
);
|
||||
|
||||
const addCustomOption = useCallback(
|
||||
(option) => {
|
||||
setCustomOptions((prevOptions) => [...prevOptions, option]);
|
||||
focusInput();
|
||||
},
|
||||
[focusInput, setCustomOptions]
|
||||
);
|
||||
|
||||
const customOptionsState = {
|
||||
customOptions,
|
||||
removeCustomOption,
|
||||
addCustomOption,
|
||||
};
|
||||
|
||||
return (
|
||||
<CustomOptionsContext.Provider value={customOptionsState}>
|
||||
{children}
|
||||
</CustomOptionsContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useCustomOptionsContext = () => {
|
||||
const context = useContext(CustomOptionsContext);
|
||||
if (!context) {
|
||||
throw new Error(
|
||||
"useCustomOptionsContext must be used within a CustomOptionsProvider"
|
||||
);
|
||||
}
|
||||
return context;
|
||||
};
|
||||
@@ -0,0 +1,2 @@
|
||||
export { default as Combobox } from "./ComboboxProvider";
|
||||
export { type ComboboxProps } from "./types";
|
||||
@@ -0,0 +1,127 @@
|
||||
import React, { ChangeEvent, InputHTMLAttributes } from "react";
|
||||
import { FormFieldProps } from "../useFormField";
|
||||
|
||||
export interface ComboboxProps
|
||||
extends FormFieldProps,
|
||||
Omit<InputHTMLAttributes<HTMLInputElement>, "size" | "onChange" | "value"> {
|
||||
/**
|
||||
* Combobox label
|
||||
*/
|
||||
label: React.ReactNode;
|
||||
/**
|
||||
* List of options to use for autocompletion
|
||||
*/
|
||||
options: string[];
|
||||
/**
|
||||
* If enabled, adds an option to add the value of the input as an option whenever there are no options matching the value.
|
||||
*/
|
||||
allowNewValues?: boolean;
|
||||
/**
|
||||
* If "true" adds a button to clear the value in the input field
|
||||
*/
|
||||
clearButton?: boolean;
|
||||
/**
|
||||
* Custom name for the clear button. Requires "clearButton" to be "true".
|
||||
*
|
||||
* @default "Tøm"
|
||||
*/
|
||||
clearButtonLabel?: string;
|
||||
/**
|
||||
* A list of options to display in the dropdown list.
|
||||
* If provided, this overrides the internal search logic in the component.
|
||||
* Useful for e.g. searching on a server or when overriding the search algorithm to search for synonyms or similar.
|
||||
*/
|
||||
filteredOptions?: string[];
|
||||
/**
|
||||
* Optionally hide the label visually.
|
||||
* Not recommended, but can be considered for e.g. search fields in the top menu.
|
||||
*/
|
||||
hideLabel?: boolean;
|
||||
/**
|
||||
* Custom class name for the input field.
|
||||
*
|
||||
* If used for styling, please consider using tokens instead.
|
||||
*/
|
||||
inputClassName?: string | undefined;
|
||||
/**
|
||||
* Controlled open/closed state for the dropdown list
|
||||
*/
|
||||
isListOpen?: boolean;
|
||||
/**
|
||||
* Set to "true" when doing an async search and waiting for new filteredOptions.
|
||||
*
|
||||
* Will show a spinner in the dropdown and announce to screen readers that it is loading.
|
||||
*/
|
||||
isLoading?: boolean;
|
||||
/**
|
||||
* Set to "true" to allow multiple selections
|
||||
*
|
||||
* This will display selected values as a list of Chips in front of the input field, instead of a selection replacing the value of the input.
|
||||
*
|
||||
*/
|
||||
isMultiSelect?: boolean;
|
||||
/**
|
||||
* Callback function triggered whenever the value of the input field is triggered.
|
||||
*
|
||||
* @param event
|
||||
* @returns
|
||||
*/
|
||||
onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
|
||||
/**
|
||||
* Callback function triggered whenever the input field is cleared
|
||||
*
|
||||
* @param event
|
||||
* @returns
|
||||
*/
|
||||
onClear?: (event: React.PointerEvent | React.KeyboardEvent) => void;
|
||||
/**
|
||||
* Callback function triggered whenever an option is selected or de-selected
|
||||
*
|
||||
* @param option
|
||||
* @param isSelected - Whether the option has been selected or unselected
|
||||
* @param isAddedByUser - Whether the option comes from user input, instead of from the list
|
||||
* @returns
|
||||
*/
|
||||
onToggleSelected?: (
|
||||
option: string,
|
||||
isSelected: boolean,
|
||||
isAddedByUser: boolean
|
||||
) => void;
|
||||
/**
|
||||
* List of selected options.
|
||||
*
|
||||
* Use this prop when controlling the selected state outside for the component,
|
||||
* e.g. for a filter, where options can be toggled elsewhere/programmatically.
|
||||
*/
|
||||
selectedOptions?: string[];
|
||||
/**
|
||||
* Set to "true" to enable inline autocomplete.
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
shouldAutocomplete?: boolean;
|
||||
/**
|
||||
* When set to "true" displays selected options as Chips before the input field
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
shouldShowSelectedOptions?: boolean;
|
||||
/**
|
||||
* When set to "true" displays the toggle button for opening/closing the dropdown list
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
toggleListButton?: boolean;
|
||||
/**
|
||||
* Custom name for the toggle list-button. Requires "toggleListButton" to be "true".
|
||||
*
|
||||
* @default "Alternativer"
|
||||
*/
|
||||
toggleListButtonLabel?: string;
|
||||
/**
|
||||
* Set this to override the value of the input field.
|
||||
*
|
||||
* This converts the input to a controlled input, so you have to use onChange to update the value.
|
||||
*/
|
||||
value?: string;
|
||||
}
|
||||
@@ -17,6 +17,7 @@ export {
|
||||
type RadioProps,
|
||||
} from "./radio";
|
||||
export { Search, type SearchClearEvent, type SearchProps } from "./search";
|
||||
export { Combobox as UNSAFE_Combobox, type ComboboxProps } from "./combobox";
|
||||
export { default as Select, type SelectProps } from "./Select";
|
||||
export { default as Switch, type SwitchProps } from "./Switch";
|
||||
export { Counter, default as Textarea, type TextareaProps } from "./Textarea";
|
||||
|
||||
@@ -6,7 +6,7 @@ import { FormFieldProps } from "../useFormField";
|
||||
import { useRadio } from "./useRadio";
|
||||
|
||||
export interface RadioProps
|
||||
extends Omit<FormFieldProps, "error" | "errorId">,
|
||||
extends Omit<FormFieldProps, "error" | "errorId" | "readOnly">,
|
||||
Omit<InputHTMLAttributes<HTMLInputElement>, "size" | "value"> {
|
||||
/**
|
||||
* Radio label
|
||||
@@ -23,17 +23,18 @@ export interface RadioProps
|
||||
}
|
||||
|
||||
export const Radio = forwardRef<HTMLInputElement, RadioProps>((props, ref) => {
|
||||
const { inputProps, size, hasError } = useRadio(props);
|
||||
const { inputProps, size, hasError, readOnly } = useRadio(props);
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cl(props.className, "navds-radio", `navds-radio--${size}`, {
|
||||
"navds-radio--error": hasError,
|
||||
"navds-radio--disabled": inputProps.disabled,
|
||||
"navds-radio--readonly": readOnly,
|
||||
})}
|
||||
>
|
||||
<input
|
||||
{...omit(props, ["children", "size", "description"])}
|
||||
{...omit(props, ["children", "size", "description", "readOnly"])}
|
||||
{...inputProps}
|
||||
className="navds-radio__input"
|
||||
ref={ref}
|
||||
|
||||
@@ -65,6 +65,7 @@ export const RadioGroup = forwardRef<HTMLFieldSetElement, RadioGroupProps>(
|
||||
value,
|
||||
onChange = () => {},
|
||||
required,
|
||||
readOnly,
|
||||
...rest
|
||||
},
|
||||
ref
|
||||
@@ -76,12 +77,14 @@ export const RadioGroup = forwardRef<HTMLFieldSetElement, RadioGroupProps>(
|
||||
return (
|
||||
<Fieldset
|
||||
{...rest}
|
||||
readOnly={readOnly}
|
||||
ref={ref}
|
||||
className={cl(
|
||||
className,
|
||||
"navds-radio-group",
|
||||
`navds-radio-group--${rest.size ?? fieldset?.size ?? "medium"}`
|
||||
)}
|
||||
nativeReadOnly={false}
|
||||
>
|
||||
<RadioGroupContext.Provider
|
||||
value={{
|
||||
|
||||
@@ -92,3 +92,30 @@ export const GroupDescription = () => (
|
||||
<Radio value="tekst2">Radiotekst</Radio>
|
||||
</RadioGroup>
|
||||
);
|
||||
|
||||
export const UUDemo = () => (
|
||||
<div className="colgap">
|
||||
<RadioGroup
|
||||
legend="Hvilken frukt vil du ha?"
|
||||
description="Du kan bare velge en frukt"
|
||||
defaultValue="eple"
|
||||
readOnly
|
||||
>
|
||||
<Radio value="eple">Eple</Radio>
|
||||
<Radio value="banan" description="Bananer er importert fra X">
|
||||
Banan
|
||||
</Radio>
|
||||
<Radio value="druer">Druer</Radio>
|
||||
</RadioGroup>
|
||||
<RadioGroup
|
||||
legend="Når har du ferie?"
|
||||
defaultValue="1"
|
||||
readOnly
|
||||
error="du må velge en ferie"
|
||||
>
|
||||
<Radio value="1">August</Radio>
|
||||
<Radio value="2">Juli</Radio>
|
||||
<Radio value="3">Juni</Radio>
|
||||
</RadioGroup>
|
||||
</div>
|
||||
);
|
||||
@@ -10,7 +10,7 @@ import { omit } from "../..";
|
||||
export const useRadio = (props: RadioProps) => {
|
||||
const radioGroup = useContext(RadioGroupContext);
|
||||
|
||||
const { inputProps, ...rest } = useFormField(
|
||||
const { inputProps, readOnly, ...rest } = useFormField(
|
||||
omit(props, ["description"]),
|
||||
"radio"
|
||||
);
|
||||
@@ -25,6 +25,7 @@ export const useRadio = (props: RadioProps) => {
|
||||
|
||||
return {
|
||||
...rest,
|
||||
readOnly,
|
||||
inputProps: {
|
||||
...inputProps,
|
||||
name: radioGroup?.name,
|
||||
@@ -37,9 +38,19 @@ export const useRadio = (props: RadioProps) => {
|
||||
? undefined
|
||||
: radioGroup?.value === props.value,
|
||||
onChange: (e) => {
|
||||
if (readOnly) {
|
||||
return;
|
||||
}
|
||||
props.onChange && props.onChange(e);
|
||||
radioGroup?.onChange && radioGroup.onChange(props.value);
|
||||
},
|
||||
onClick: (e) => {
|
||||
if (readOnly) {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
props?.onClick?.(e);
|
||||
},
|
||||
required: radioGroup?.required,
|
||||
type: "radio",
|
||||
},
|
||||
|
||||
@@ -27,7 +27,7 @@ export type SearchClearEvent =
|
||||
| { trigger: "Escape"; event: React.KeyboardEvent<HTMLDivElement> };
|
||||
|
||||
export interface SearchProps
|
||||
extends FormFieldProps,
|
||||
extends Omit<FormFieldProps, "readOnly">,
|
||||
Omit<InputHTMLAttributes<HTMLInputElement>, "size" | "onChange"> {
|
||||
children?: React.ReactNode;
|
||||
/**
|
||||
@@ -221,7 +221,7 @@ export const Search = forwardRef<HTMLInputElement, SearchProps>(
|
||||
)}
|
||||
<input
|
||||
ref={mergedRef}
|
||||
{...omit(rest, ["error", "errorId", "size"])}
|
||||
{...omit(rest, ["error", "errorId", "size", "readOnly"])}
|
||||
{...inputProps}
|
||||
value={value ?? internalValue}
|
||||
onChange={(e) => handleChange(e.target.value)}
|
||||
|
||||
@@ -114,3 +114,20 @@ export const HideLabel = () => {
|
||||
</Select>
|
||||
);
|
||||
};
|
||||
|
||||
export const Readonly = () => {
|
||||
return (
|
||||
<div className="colgap">
|
||||
<Select
|
||||
label="Hvilkets land er du fra?"
|
||||
description="Velg landet du bor 180 dagen i året"
|
||||
readOnly
|
||||
>
|
||||
{content}
|
||||
</Select>
|
||||
<Select label="Hvilkets land er du fra?" readOnly error="feilmelding">
|
||||
{content}
|
||||
</Select>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -116,3 +116,17 @@ export const HideLabel = () => {
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const Readonly = () => {
|
||||
return (
|
||||
<div className="colgap">
|
||||
<Switch description="Slår av alle notifikasjoner" readOnly>
|
||||
Notifikasjoner
|
||||
</Switch>
|
||||
|
||||
<Switch checked readOnly>
|
||||
Notifikasjoner
|
||||
</Switch>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -83,3 +83,17 @@ export const Disabled = () => {
|
||||
export const HideLabel = () => {
|
||||
return <TextField label="Ipsum enim quis culpa" hideLabel />;
|
||||
};
|
||||
|
||||
export const Readonly = () => {
|
||||
return (
|
||||
<div className="colgap">
|
||||
<TextField
|
||||
label="Bosted"
|
||||
description="Skriv bosted i Norge"
|
||||
readOnly
|
||||
value="Oslo"
|
||||
/>
|
||||
<TextField label="Bosted" readOnly error="feilmelding" value="Oslo" />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
Loaded 100 of 290 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user