Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Suggestion): ✨ new component #2881

Open
wants to merge 27 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e29f4bf
feat(Suggestion): :sparkles: new component
Barsnes Dec 11, 2024
10f82ad
Merge branch 'next' into feat/suggestion
Barsnes Dec 11, 2024
7557be6
add option to list and popove
Barsnes Dec 11, 2024
bf5bbe0
remove popover, add clear
Barsnes Dec 11, 2024
a156618
some more adjustments
Barsnes Dec 11, 2024
1a88f86
Merge branch 'next' into feat/suggestion
Barsnes Dec 11, 2024
76aa9d4
start controlled
Barsnes Dec 12, 2024
d21af0b
style checkmark, check desc
Barsnes Dec 12, 2024
17f1f66
add controleld state
Barsnes Dec 12, 2024
568aa21
make usable in non-controlled
Barsnes Dec 12, 2024
735775c
start removing things
Barsnes Dec 13, 2024
92aeb13
misc
Barsnes Dec 13, 2024
bc5ba0a
default value work, and stories
Barsnes Dec 13, 2024
9c56945
Merge branch 'next' into feat/suggestion
Barsnes Dec 13, 2024
c70933d
disable aria-allowed-attr
Barsnes Dec 13, 2024
7b6f901
example
Barsnes Dec 13, 2024
4dfdb34
fix(Suggestion): add stories and simplify
eirikbacker Dec 16, 2024
bf934e5
Merge branch 'next' into feat/suggestion
Barsnes Jan 8, 2025
93400f4
Merge branch 'next' into feat/suggestion
Barsnes Jan 9, 2025
bf7e449
Merge branch 'next' into feat/suggestion
Barsnes Jan 10, 2025
b4a2617
export as EXPERIMENTAL_Suggestion
Barsnes Jan 10, 2025
cc8dd54
use `ds-size-*`
Barsnes Jan 10, 2025
a57b126
open suggestion when in visual tests
Barsnes Jan 10, 2025
8ff632c
Merge branch 'next' into feat/suggestion
Barsnes Jan 10, 2025
c52bc03
disable failing role test
Barsnes Jan 10, 2025
8c40d3c
Create real-cats-suffer.md
Barsnes Jan 10, 2025
bab420f
fix typo for helptext :)
Barsnes Jan 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/real-cats-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@digdir/designsystemet-css": patch
"@digdir/designsystemet-react": patch
---

Experimental Suggestion: :sparkles: New component
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export const HelpText = forwardRef<HTMLButtonElement, HelpTextProps>(

### Satt saman

I CodeSanboxen under kan du sjå korleis du sett kodesnuttane over saman.
I CodeSandboxen under kan du sjå korleis du sett kodesnuttane over saman.

<ResponsiveIframe
title="own-helptext-example"
Expand Down
2 changes: 1 addition & 1 deletion packages/css/src/field.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* States
*/
&:has([aria-disabled='true'], :disabled) > * {
&:has(:disabled) > * {
cursor: not-allowed;
opacity: var(--ds-disabled-opacity);
}
Expand Down
1 change: 1 addition & 0 deletions packages/css/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
@import url('./input.css') layer(ds.components);
@import url('./alert.css') layer(ds.components);
@import url('./popover.css') layer(ds.components);
@import url('./suggestion.css') layer(ds.components);
@import url('./skiplink.css') layer(ds.components);
@import url('./details.css') layer(ds.components);
@import url('./search.css') layer(ds.components);
Expand Down
113 changes: 113 additions & 0 deletions packages/css/src/suggestion.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
.ds-suggestion {
--dsc-suggestion-option-background--selected: var(--ds-color-background-subtle);
--dsc-suggestion-option-border-color: var(--ds-color-base-default);
--dsc-suggestion-clear-gap: var(--ds-size-2);
--dsc-suggestion-clear-padding: var(--ds-size-1);
--dsc-suggestion-clear-size: var(--ds-size-9);
--dsc-suggestion-clear-icon-url: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24'%3E%3Cpath fill='currentColor' d='M6.53 5.47a.75.75 0 0 0-1.06 1.06L10.94 12l-5.47 5.47a.75.75 0 1 0 1.06 1.06L12 13.06l5.47 5.47a.75.75 0 1 0 1.06-1.06L13.06 12l5.47-5.47a.75.75 0 0 0-1.06-1.06L12 10.94z'/%3E%3C/svg%3E");
--dsc-suggestion-option-checkmark-url: url('data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%221em%22%20height%3D%221em%22%20fill%3D%22none%22%20viewBox%3D%220%200%2024%2024%22%20focusable%3D%22false%22%20role%3D%22img%22%3E%3Cpath%20fill%3D%22currentColor%22%20fill-rule%3D%22evenodd%22%20d%3D%22M18.998%206.94a.75.75%200%200%201%20.063%201.058l-8%209a.75.75%200%200%201-1.091.032l-5-5a.75.75%200%201%201%201.06-1.06l4.438%204.437%207.471-8.405A.75.75%200%200%201%2019%206.939%22%20clip-rule%3D%22evenodd%22%3E%3C%2Fpath%3E%3C%2Fsvg%3E');
--dsc-suggestion-option-checkmark-size: var(--ds-size-7);
--dsc-suggestion-list-gap: var(--ds-size-2);

box-sizing: border-box;
display: flex;
flex-wrap: wrap;
gap: var(--ds-size-1);
position: relative;

& u-datalist {
background: var(--ds-color-neutral-background-default);
border-radius: var(--ds-border-radius-md);
border: 1px solid var(--ds-color-neutral-border-default);
box-shadow: var(--ds-shadow-md);
box-sizing: border-box;
color: var(--ds-color-neutral-text-default);
inset: 100% 0 auto 0;
overflow-y: auto;
position: absolute;
z-index: 1600;
margin-top: var(--dsc-suggestion-list-gap);
max-height: 200px;

&:not(:has(u-option:hover)) > u-option:focus-visible {
border-left-color: var(--dsc-suggestion-option-border-color);
background: var(--dsc-suggestion-option-background--selected);
color: var(--ds-color-text-default);
}

/* Hide <suggestion.Empty> if any <suggestion.Option> is visible */
&:has(u-option:not([hidden])) > :not(u-option) {
display: none;
}

/* Hide datalist if no children */
&:empty {
display: none;
}

& > * {
padding: var(--ds-size-2) var(--ds-size-3);
font-family: inherit;
}

& > :is(u-option) {
padding-inline-start: var(--dsc-suggestion-option-checkmark-size);
border: none;
border-left: 5px solid transparent;
outline: none;
border-radius: var(--ds-border-radius-sm);
cursor: pointer;
position: relative;

&[selected] {
&::before {
content: '';
position: absolute;
left: 0;
mask: var(--dsc-suggestion-option-checkmark-url) center / contain no-repeat;
background: currentcolor;
width: var(--dsc-suggestion-option-checkmark-size);
height: var(--dsc-suggestion-option-checkmark-size);
}
}

@media (hover: hover) and (pointer: fine) {
&:is(u-option):hover {
border-left-color: var(--dsc-suggestion-option-border-color);
background: var(--dsc-suggestion-option-background--selected);
}
}
}
}

/**
* Clear button
*/
&:has(input:placeholder-shown) button[type='reset'],
&:has(input:is(:read-only, :disabled, [aria-disabled='true'])) button[type='reset'] {
visibility: hidden; /* We hide the clear button when input is empty */
}
&:has(button[type='reset']) input {
padding-inline-end: calc(var(--dsc-suggestion-clear-size) + var(--dsc-suggestion-clear-gap));
}

& button[type='reset'] {
--dsc-button-size: var(--dsc-suggestion-clear-size);

align-self: center;
margin-inline-start: calc((var(--dsc-suggestion-clear-size) + var(--dsc-suggestion-clear-gap)) * -1);
order: 999; /* Place last */
padding: var(--dsc-suggestion-clear-padding);
position: relative;
scale: 0.75;
z-index: 2;

&::before {
content: '';
height: var(--dsc-suggestion-clear-size);
width: var(--dsc-suggestion-clear-size);
mask: var(--dsc-suggestion-clear-icon-url) center / contain no-repeat;
background: currentcolor;
}
}
}
1 change: 1 addition & 0 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"@navikt/aksel-icons": "^6.14.0",
"@radix-ui/react-slot": "^1.1.0",
"@tanstack/react-virtual": "^3.10.7",
"@u-elements/u-datalist": "^0.0.9",
"@u-elements/u-details": "^0.1.0",
"clsx": "^2.1.1"
},
Expand Down
19 changes: 19 additions & 0 deletions packages/react/src/components/Suggestion/Suggestion.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Meta, Canvas, Controls, Primary } from '@storybook/blocks';
import * as SuggestionStories from './Suggestion.stories';

<Meta of={SuggestionStories} />

# Suggestion

Søkbar "select".

<Primary />
<Controls />

## Kontrollert

<Canvas of={SuggestionStories.Controlled} />

## Standard verdi

<Canvas of={SuggestionStories.DefaultValue} />
Loading
Loading