Compare commits

...
Author SHA1 Message Date
github-actions[bot]andgithub-actions[bot] d1ceb40439 Version Packages (#2141)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-08-07 13:58:17 +02:00
e033b34c3b Table component: adding click event on expandable table rows (#2127)
Co-authored-by: Vegard Haugstvedt <it.vegard@gmail.com>
Co-authored-by: Ken <26967723+KenAJoh@users.noreply.github.com>
2023-08-07 13:42:07 +02:00
Halvor Haugan de3991d0f0 📝 Fiks skrivefeil i Select-eksempler (#2140) 2023-08-04 18:30:41 +02:00
github-actions[bot]andgithub-actions[bot] 9641215506 Version Packages (#2139)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-08-04 13:43:34 +02:00
Ken 8a82e1c1f6 [Ny komponent] Stack, Spacer (#2040) 2023-08-04 13:13:46 +02:00
54 changed files with 1162 additions and 54 deletions

No files matched your search

+4
View File
@@ -1,5 +1,9 @@
# @navikt/aksel-icons
## 4.9.0
## 4.8.0
## 4.7.4
## 4.7.3
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@navikt/aksel-icons",
"version": "4.7.4",
"version": "4.9.0",
"author": "Aksel | NAV",
"homepage": "https://aksel.nav.no/ikoner",
"repository": {
+4
View File
@@ -1,5 +1,9 @@
# @navikt/aksel-stylelint
## 4.9.0
## 4.8.0
## 4.7.4
## 4.7.3
+3 -3
View File
@@ -1,6 +1,6 @@
{
"name": "@navikt/aksel-stylelint",
"version": "4.7.4",
"version": "4.9.0",
"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.7.4",
"@navikt/ds-tokens": "^4.7.4",
"@navikt/ds-css": "^4.9.0",
"@navikt/ds-tokens": "^4.9.0",
"@types/jest": "^29.0.0",
"concurrently": "7.2.1",
"copyfiles": "2.4.1",
+14
View File
@@ -1,5 +1,19 @@
# @navikt/aksel
## 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
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@navikt/aksel",
"version": "4.7.4",
"version": "4.9.0",
"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.7.4",
"@navikt/ds-css": "4.9.0",
"axios": "1.3.6",
"chalk": "4.1.0",
"clipboardy": "^2.3.0",
+12
View File
@@ -1,5 +1,17 @@
# @navikt/ds-css
## 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
+13 -1
View File
@@ -57,7 +57,7 @@ const StyleMappings = {
{
component: "UNSAFE_Combobox",
main: "combobox.css",
dependencies: [typoCss],
dependencies: [typoCss, "chips.css"],
},
{
component: "ConfirmationPanel",
@@ -134,6 +134,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] },
+1
View File
@@ -29,6 +29,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 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@navikt/ds-css",
"version": "4.7.4",
"version": "4.9.0",
"description": "CSS for NAV Designsystem",
"author": "Aksel | NAV designsystem team",
"keywords": [
@@ -27,7 +27,7 @@
"css:get-version": "node config/get-version.js"
},
"devDependencies": {
"@navikt/ds-tokens": "^4.7.4",
"@navikt/ds-tokens": "^4.9.0",
"cssnano": "6.0.0",
"fast-glob": "3.2.11",
"lodash": "4.17.21",
+61
View File
@@ -0,0 +1,61 @@
/* stylelint-disable csstools/value-no-unknown-custom-properties */
/* stylelint-disable aksel/design-token-exists */
.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))))
);
}
}
+5 -1
View File
@@ -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));
}
@@ -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;
}
+22
View File
@@ -1,5 +1,27 @@
# @navikt/ds-react
## 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
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@navikt/ds-react",
"version": "4.7.4",
"version": "4.9.0",
"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.7.4",
"@navikt/aksel-icons": "^4.9.0",
"@radix-ui/react-tabs": "1.0.0",
"@radix-ui/react-toggle-group": "1.0.0",
"clsx": "^1.2.1",
+1
View File
@@ -32,3 +32,4 @@ export * from "./toggle-group";
export * from "./tooltip";
export * from "./typography";
export * from "./util";
export * from "./layout/stack";
@@ -0,0 +1,30 @@
import React, { forwardRef } from "react";
import { OverridableComponent } from "../../util/OverridableComponent";
import { StackProps, Stack } from "./Stack";
export type HStackProps = Omit<StackProps, "direction">;
/**
* Layout-primitive for horizontal flexbox
*
* @see [📝 Documentation](https://aksel.nav.no/komponenter/core/Stack)
* @see 🏷️ {@link HStackProps}
* @see [🤖 OverridableComponent](https://aksel.nav.no/grunnleggende/kode/overridablecomponent) support
*
* @example
* <HStack gap="8">
* <MyComponent />
* <MyComponent />
* </HStack>
*
* @example
* // Responsive gap
* <HStack gap={{xs: "2", md: "6"}}>
* <MyComponent />
* <MyComponent />
* </HStack>
*/
export const HStack: OverridableComponent<HStackProps, HTMLDivElement> =
forwardRef((props, ref) => {
return <Stack {...props} ref={ref} direction="row" />;
});
@@ -0,0 +1,15 @@
import React from "react";
/**
* Layout-primitive for auto-spacing between elements
*
* @see [📝 Documentation](https://aksel.nav.no/komponenter/core/Stack)
*
* @example
* <HStack gap="8">
* <MyComponent />
* <Spacer />
* <MyComponent />
* </HStack>
*/
export const Spacer = () => <div className="navds-stack__spacer" />;
@@ -0,0 +1,76 @@
import cl from "clsx";
import React, { forwardRef, HTMLAttributes } from "react";
import { OverridableComponent } from "../../util/OverridableComponent";
import {
getResponsiveProps,
ResponsiveProp,
SpacingScale,
} from "../utilities/css";
export interface StackProps extends HTMLAttributes<HTMLDivElement> {
children: React.ReactNode;
/**
* Justify-content
*/
justify?:
| "start"
| "center"
| "end"
| "space-around"
| "space-between"
| "space-evenly";
/**
* Align-items
*/
align?: "start" | "center" | "end" | "baseline" | "stretch";
/**
* flex-wrap
*/
wrap?: boolean;
/**
* @example
* gap='4'
* gap={{xs: '2', sm: '3', md: '4', lg: '5', xl: '6'}}
*/
gap?: ResponsiveProp<SpacingScale>;
direction: "row" | "column";
}
export const Stack: OverridableComponent<StackProps, HTMLDivElement> =
forwardRef(
(
{
as: Component = "div",
className,
align,
justify,
wrap = true,
gap,
style: _style,
direction,
...rest
},
ref
) => {
const style = {
"--ac-stack-direction": direction,
"--ac-stack-align": align,
"--ac-stack-justify": justify,
"--ac-stack-wrap": wrap ? "wrap" : "nowrap",
...getResponsiveProps(`stack`, "gap", "spacing", gap),
..._style,
} as React.CSSProperties;
return (
<Component
{...rest}
ref={ref}
style={style}
className={cl("navds-stack", className, {
"navds-vstack": direction === "column",
"navds-hstack": direction === "row",
})}
/>
);
}
);
@@ -0,0 +1,30 @@
import React, { forwardRef } from "react";
import { OverridableComponent } from "../../util/OverridableComponent";
import { StackProps, Stack } from "./Stack";
export type VStackProps = Omit<StackProps, "direction" | "wrap">;
/**
* Layout-primitive for vetical flexbox
*
* @see [📝 Documentation](https://aksel.nav.no/komponenter/core/Stack)
* @see 🏷️ {@link VStackProps}
* @see [🤖 OverridableComponent](https://aksel.nav.no/grunnleggende/kode/overridablecomponent) support
*
* @example
* <VStack gap="8">
* <MyComponent />
* <MyComponent />
* </VStack>
*
* @example
* // Responsive gap
* <VStack gap={{xs: "2", md: "6"}}>
* <MyComponent />
* <MyComponent />
* </VStack>
*/
export const VStack: OverridableComponent<VStackProps, HTMLDivElement> =
forwardRef((props, ref) => {
return <Stack {...props} ref={ref} direction="column" wrap={false} />;
});
@@ -0,0 +1,3 @@
export { HStack, type HStackProps } from "./HStack";
export { VStack, type VStackProps } from "./VStack";
export { Spacer } from "./Spacer";
@@ -0,0 +1,161 @@
import React from "react";
import type { Meta } from "@storybook/react";
import { HStack, VStack, Spacer } from ".";
export default {
title: "ds-react/Stack",
component: HStack,
} satisfies Meta<typeof HStack>;
export const Horizontal = {
render: () => (
<HStack gap="4">
<Placeholders count={4} />
</HStack>
),
};
export const Spacing = {
render: () => (
<div style={{ height: "80vh", display: "flex" }}>
<VStack gap="8">
<Spacer />
<HStack gap="4">
<Placeholders count={1} />
<Spacer />
<Placeholders count={1} />
</HStack>
<HStack gap="4">
<Placeholders count={1} />
<Placeholders count={1} />
</HStack>
<HStack gap="4">
<Placeholders count={2} />
</HStack>
</VStack>
</div>
),
parameters: {
layout: "fullscreen",
},
};
export const Vertical = {
render: () => (
<VStack gap="4">
<Placeholders count={4} />
</VStack>
),
};
export const VerticalDemo = {
render: () => (
<VStack gap="2">
<VStack>
<Placeholders count={4} />
</VStack>
<Placeholders count={4} />
<VStack>
<Placeholders count={4} />
</VStack>
</VStack>
),
};
export const VerticalAlign = {
render: () => (
<VStack gap="4">
<VStack align="start">
<Placeholders count={2} />
</VStack>
<VStack align="center">
<Placeholders count={2} />
</VStack>
<VStack align="end">
<Placeholders count={2} />
</VStack>
</VStack>
),
parameters: {
layout: "fullscreen",
},
};
export const OverrideComponent = {
render: () => (
<VStack gap="4" as="form" onSubmit={(e) => e.preventDefault()}>
<Placeholders count={4} />
</VStack>
),
};
export const Responsive = {
render: () => (
<VStack gap={{ xs: "1", sm: "3", md: "6", lg: "10", xl: "16" }}>
<Placeholders count={4} />
</VStack>
),
};
export const Nested = {
render: () => (
<VStack gap="16">
<Placeholders count={2}>
<VStack gap="4">
<Placeholders count={2} color="gray" />
</VStack>
</Placeholders>
</VStack>
),
};
export const DividerDemo = {
render: () => (
<div style={{ height: "80vh", width: "40rem" }}>
<VStack gap={{ xs: "2", md: "6", lg: "12" }}>
<HStack gap={{ xs: "2", md: "6", lg: "12" }}>
<Placeholders count={1} />
<Spacer />
<Placeholders count={1} />
</HStack>
<hr
style={{
border: "none",
borderBottom: "1px solid var(--a-border-divider)",
margin: 0,
}}
/>
<HStack gap={{ xs: "2", md: "6", lg: "12" }}>
<Placeholders count={2} />
</HStack>
</VStack>
</div>
),
};
function Placeholders({
count,
children,
color,
}: {
count: number;
children?: React.ReactNode;
color?: string;
}) {
return (
<>
{Array.from({ length: count }, (_, i) => (
<div
key={i}
style={{
backgroundColor: color ?? "var(--a-purple-200)",
height: children ? "" : "3rem",
width: children ? "" : "3rem",
}}
>
{children}
</div>
))}
</>
);
}
@@ -0,0 +1,56 @@
export type BreakpointsAlias = "xs" | "sm" | "md" | "lg" | "xl";
export type SpacingScale =
| "0"
| "05"
| "1"
| "2"
| "3"
| "4"
| "5"
| "6"
| "7"
| "8"
| "9"
| "10"
| "11"
| "12"
| "14"
| "16"
| "18"
| "20"
| "24"
| "32";
export type ResponsiveProp<T> =
| T
| {
// eslint-disable-next-line no-unused-vars
[Breakpoint in BreakpointsAlias]?: T;
};
export function getResponsiveProps(
componentName: string,
componentProp: string,
tokenSubgroup: string,
responsiveProp?:
| string
| {
// eslint-disable-next-line no-unused-vars
[Breakpoint in BreakpointsAlias]?: string;
}
) {
if (!responsiveProp) return {};
if (typeof responsiveProp === "string") {
return {
[`--ac-${componentName}-${componentProp}-xs`]: `var(--a-${tokenSubgroup}-${responsiveProp})`,
};
}
return Object.fromEntries(
Object.entries(responsiveProp).map(([breakpointAlias, aliasOrScale]) => [
`--ac-${componentName}-${componentProp}-${breakpointAlias}`,
`var(--a-${tokenSubgroup}-${aliasOrScale})`,
])
);
}
+28 -8
View File
@@ -31,10 +31,15 @@ export interface ExpandableRowProps extends Omit<RowProps, "content"> {
*/
onOpenChange?: (open: boolean) => void;
/**
* Disable expansio
* Disable expansion. shadeOnHover will not be visible.
* @default false
*/
expansionDisabled?: boolean;
/**
* Makes the whole row clickable
* @default false
*/
expandOnRowClick?: boolean;
/**
* The width of the expanded row's internal cell
* @default 999
@@ -58,6 +63,7 @@ export const ExpandableRow: ExpandableRowType = forwardRef(
open,
onOpenChange,
expansionDisabled = false,
expandOnRowClick = false,
colSpan = 999,
...rest
},
@@ -65,9 +71,22 @@ export const ExpandableRow: ExpandableRowType = forwardRef(
) => {
const [internalOpen, setInternalOpen] = useState<boolean>(defaultOpen);
const id = useId();
const isOpen = open ?? internalOpen;
const expansionHandler = (e) => {
onOpenChange?.(!isOpen);
if (open === undefined) {
setInternalOpen((open) => !open);
}
e.stopPropagation();
};
const onRowClick = (e) => {
if (e.target.nodeName === "TD" || e.target.nodeName === "TH") {
expansionHandler(e);
}
};
return (
<>
<Row
@@ -75,7 +94,13 @@ export const ExpandableRow: ExpandableRowType = forwardRef(
ref={ref}
className={cl("navds-table__expandable-row", className, {
"navds-table__expandable-row--open": isOpen,
"navds-table__expandable-row--expansion-disabled":
expansionDisabled,
})}
onClick={(e) => {
!expansionDisabled && expandOnRowClick && onRowClick(e);
rest?.onClick?.(e);
}}
>
{togglePlacement === "right" && children}
<DataCell
@@ -89,12 +114,7 @@ export const ExpandableRow: ExpandableRowType = forwardRef(
className="navds-table__toggle-expand-button"
aria-controls={id}
aria-expanded={isOpen}
onClick={() => {
onOpenChange?.(!isOpen);
if (open === undefined) {
setInternalOpen((open) => !open);
}
}}
onClick={expansionHandler}
>
<ChevronDownIcon
className="navds-table__expandable-icon"
@@ -1,6 +1,6 @@
import React, { useState } from "react";
import { Table } from "..";
import { Link } from "../..";
import { Button, Checkbox, Link } from "../..";
export default {
title: "ds-react/Table",
@@ -37,6 +37,7 @@ export const Expandable = () => {
};
export const ExpandableSmall = () => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const [open, setOpen] = useState(false);
return (
<Table size="small">
@@ -227,3 +228,63 @@ export const ExpandableOpen = () => {
</Table>
);
};
export const ClickableRow = {
render: () => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const [isRowOpen1, setIsRowOpen1] = useState(false);
// eslint-disable-next-line react-hooks/rules-of-hooks
const [isRowOpen2, setIsRowOpen2] = useState(false);
return (
<>
<Table zebraStripes>
<Table.Header>
<Table.Row>
<Table.HeaderCell>Navn</Table.HeaderCell>
<Table.HeaderCell>Info</Table.HeaderCell>
<Table.HeaderCell aria-hidden />
</Table.Row>
</Table.Header>
<Table.Body>
<Table.ExpandableRow
content={<div>placeholder row 1</div>}
togglePlacement="right"
onOpenChange={setIsRowOpen1}
data-testid="row1"
open={isRowOpen1}
expandOnRowClick
>
<Table.DataCell>Ola</Table.DataCell>
<Table.DataCell>
<Button
size="xsmall"
onClick={(e) => {
alert("Mer info");
}}
>
Mer info
</Button>
</Table.DataCell>
</Table.ExpandableRow>
<Table.ExpandableRow
content={<div>placeholder row 2</div>}
togglePlacement="right"
onOpenChange={setIsRowOpen2}
data-testid="row2"
open={isRowOpen2}
expandOnRowClick
>
<Table.DataCell>Hans</Table.DataCell>
<Table.DataCell>
<Checkbox hideLabel size="small">
Sett
</Checkbox>
</Table.DataCell>
</Table.ExpandableRow>
</Table.Body>
</Table>
</>
);
},
};
+4
View File
@@ -1,5 +1,9 @@
# @navikt/ds-tailwind
## 4.9.0
## 4.8.0
## 4.7.4
## 4.7.3
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@navikt/ds-tailwind",
"version": "4.7.4",
"version": "4.9.0",
"description": "Tailwind config based on @navikt/ds-tokens",
"author": "Aksel | NAV designsystem team",
"keywords": [
@@ -22,7 +22,7 @@
"directory": "@navikt/core/tailwind"
},
"devDependencies": {
"@navikt/ds-tokens": "^4.7.4",
"@navikt/ds-tokens": "^4.9.0",
"@types/jest": "^29.0.0",
"color": "4.2.3",
"jest": "^29.0.0",
+4
View File
@@ -1,5 +1,9 @@
# @navikt/ds-tokens
## 4.9.0
## 4.8.0
## 4.7.4
## 4.7.3
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@navikt/ds-tokens",
"version": "4.7.4",
"version": "4.9.0",
"description": "Design-tokens for NAV designsystem",
"author": "Aksel | NAV designsystem team",
"keywords": [
+20
View File
@@ -1,5 +1,25 @@
# Changelog
## 4.9.0
### @navikt/ds-css
- Table: ExpandableRow kan nå åpnes med 'expandOnRowClick'-prop ([#2127](https://github.com/navikt/aksel/pull/2127))
### @navikt/ds-react
- Table: ExpandableRow kan nå åpnes med 'expandOnRowClick'-prop ([#2127](https://github.com/navikt/aksel/pull/2127))
## 4.8.0
### @navikt/ds-css
- Nye komponenter `VStack`, `HStack` og `Spacer` for å enklere kunne lage layout med flexbox og spacing-variabler. ([#2040](https://github.com/navikt/aksel/pull/2040))
### @navikt/ds-react
- 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
### @navikt/ds-css
+5 -5
View File
@@ -15,11 +15,11 @@
"website"
],
"dependencies": {
"@navikt/aksel-icons": "^4.7.4",
"@navikt/ds-css": "^4.7.4",
"@navikt/ds-react": "^4.7.4",
"@navikt/ds-tailwind": "^4.7.4",
"@navikt/ds-tokens": "^4.7.4"
"@navikt/aksel-icons": "^4.9.0",
"@navikt/ds-css": "^4.9.0",
"@navikt/ds-react": "^4.9.0",
"@navikt/ds-tailwind": "^4.9.0",
"@navikt/ds-tokens": "^4.9.0"
},
"devDependencies": {
"prettier-plugin-tailwindcss": "^0.2.3"
@@ -0,0 +1,73 @@
import { HStack, VStack } from "@navikt/ds-react";
import { withDsExample } from "components/website-modules/examples/withDsExample";
const Example = () => {
return (
<VStack gap="12">
<HStack gap="3" align="center">
<Placeholder text="center" />
<Placeholder />
<Placeholder />
<Placeholder />
<Placeholder />
</HStack>
<HStack gap="3" align="end">
<Placeholder text="end" />
<Placeholder />
<Placeholder />
<Placeholder />
<Placeholder />
</HStack>
<HStack gap="3" align="start">
<Placeholder text="start" />
<Placeholder />
<Placeholder />
<Placeholder />
<Placeholder />
</HStack>
<HStack gap="3" align="stretch">
<Placeholder text="stretch" />
<Placeholder />
<Placeholder />
<Placeholder />
<Placeholder />
</HStack>
<HStack gap="3" align="baseline">
<Placeholder text="baseline" />
<Placeholder text="text" noPadding />
<Placeholder text="text" noPadding />
<Placeholder text="text" noPadding />
<Placeholder text="text" noPadding />
</HStack>
</VStack>
);
};
export default withDsExample(Example);
/* Storybook story */
export const Demo = {
render: Example,
};
export const args = {
index: 2,
desc: "Endrer 'align-items'.",
};
const Placeholder = ({
text,
noPadding,
}: {
text?: string;
noPadding?: boolean;
}) => {
return (
<div
className="min-h-4 text-text-on-action h-auto w-auto rounded bg-teal-600 p-2"
style={{ padding: noPadding && 0 }}
>
{text}
</div>
);
};
@@ -0,0 +1,29 @@
import { HStack } from "@navikt/ds-react";
import { withDsExample } from "components/website-modules/examples/withDsExample";
const Example = () => {
return (
<HStack gap="4">
<Placeholder />
<Placeholder />
<Placeholder />
<Placeholder />
</HStack>
);
};
export default withDsExample(Example);
/* Storybook story */
export const Demo = {
render: Example,
};
export const args = {
index: 0,
desc: "HStack er en enkel layout-komponent for flexbox.",
};
const Placeholder = () => {
return <div className="aspect-square h-12 rounded bg-teal-500" />;
};
@@ -0,0 +1,76 @@
import { HStack, VStack } from "@navikt/ds-react";
import { withDsExample } from "components/website-modules/examples/withDsExample";
const Example = () => {
return (
<div className="min-w-72 bg-deepblue-50">
<VStack gap="12">
<HStack gap="3" justify="center">
<Placeholder text="center" />
<Placeholder />
<Placeholder />
<Placeholder />
</HStack>
<HStack gap="3" justify="end">
<Placeholder text="end" />
<Placeholder />
<Placeholder />
<Placeholder />
</HStack>
<HStack gap="3" justify="start">
<Placeholder text="start" />
<Placeholder />
<Placeholder />
<Placeholder />
</HStack>
<HStack gap="3" justify="space-around">
<Placeholder text="around" />
<Placeholder />
<Placeholder />
<Placeholder />
</HStack>
<HStack gap="3" justify="space-between">
<Placeholder text="between" />
<Placeholder />
<Placeholder />
<Placeholder />
</HStack>
<HStack gap="3" justify="space-evenly">
<Placeholder text="evenly" />
<Placeholder />
<Placeholder />
<Placeholder />
</HStack>
</VStack>
</div>
);
};
export default withDsExample(Example);
/* Storybook story */
export const Demo = {
render: Example,
};
export const args = {
index: 3,
desc: "Endrer 'justify-content'.",
};
const Placeholder = ({
text,
noPadding,
}: {
text?: string;
noPadding?: boolean;
}) => {
return (
<div
className="min-h-4 text-text-on-action h-auto w-auto rounded bg-teal-600 p-2"
style={{ padding: noPadding && 0 }}
>
{text}
</div>
);
};
@@ -0,0 +1,32 @@
import { HStack } from "@navikt/ds-react";
import { withDsExample } from "components/website-modules/examples/withDsExample";
const Example = () => {
return (
<HStack gap="4" wrap={false}>
<Placeholder />
<Placeholder />
<Placeholder />
<Placeholder />
<Placeholder />
<Placeholder />
<Placeholder />
</HStack>
);
};
export default withDsExample(Example);
/* Storybook story */
export const Demo = {
render: Example,
};
export const args = {
index: 1,
desc: "Som standard er 'wrap' satt til 'true'.",
};
const Placeholder = () => {
return <div className="aspect-square h-12 rounded bg-teal-500" />;
};
@@ -0,0 +1,29 @@
import { HStack } from "@navikt/ds-react";
import { withDsExample } from "components/website-modules/examples/withDsExample";
const Example = () => {
return (
<HStack gap={{ xs: "4", sm: "6", md: "8", lg: "10", xl: "12" }}>
<Placeholder />
<Placeholder />
<Placeholder />
<Placeholder />
</HStack>
);
};
export default withDsExample(Example);
/* Storybook story */
export const Demo = {
render: Example,
};
export const args = {
index: 4,
desc: "Med responsive gap kan man redusere/øke mellomrom basert på brekkpunktene våre. Implementasjonen er mobile-first, slik at man 'sm: 8' vil sette gap for 'md', 'lg' og 'xl' også.",
};
const Placeholder = () => {
return <div className="aspect-square h-12 rounded bg-teal-500" />;
};
@@ -0,0 +1,43 @@
import { HStack, Spacer } from "@navikt/ds-react";
import { withDsExample } from "components/website-modules/examples/withDsExample";
const Example = () => {
return (
<div className="bg-deepblue-50">
<HStack gap="3" wrap={false}>
<Placeholder />
<Spacer />
<Placeholder />
</HStack>
</div>
);
};
export default withDsExample(Example, "static");
/* Storybook story */
export const Demo = {
render: Example,
};
export const args = {
index: 7,
desc: "Spacer lar deg lett legge inn automatisk stretch mellom elementer. Dette kan komme inn nyttig når man f.eks skal plassere knapper i 'InternalHeader'.",
};
const Placeholder = ({
text,
noPadding,
}: {
text?: string;
noPadding?: boolean;
}) => {
return (
<div
className="min-h-8 text-text-on-action aspect-square h-auto w-auto rounded bg-teal-600 p-2"
style={{ padding: noPadding && 0 }}
>
{text}
</div>
);
};
@@ -1,11 +1,12 @@
import { InternalHeader } from "@navikt/ds-react";
import { InternalHeader, Spacer } from "@navikt/ds-react";
import { withDsExample } from "components/website-modules/examples/withDsExample";
const Example = () => {
return (
<InternalHeader>
<InternalHeader.Title as="h1">Sykepenger</InternalHeader.Title>
<InternalHeader.User name="Ola Normann" className="ml-auto" />
<Spacer />
<InternalHeader.User name="Ola Normann" />
</InternalHeader>
);
};
@@ -1,15 +1,12 @@
import { InternalHeader } from "@navikt/ds-react";
import { InternalHeader, Spacer } from "@navikt/ds-react";
import { withDsExample } from "components/website-modules/examples/withDsExample";
const Example = () => {
return (
<InternalHeader>
<InternalHeader.Title as="h1">Sykepenger</InternalHeader.Title>
<InternalHeader.User
name="Ola Normann"
description="D123456"
className="ml-auto"
/>
<Spacer />
<InternalHeader.User name="Ola Normann" description="D123456" />
</InternalHeader>
);
};
@@ -1,11 +1,12 @@
import { InternalHeader } from "@navikt/ds-react";
import { InternalHeader, Spacer } from "@navikt/ds-react";
import { withDsExample } from "components/website-modules/examples/withDsExample";
const Example = () => {
return (
<InternalHeader>
<InternalHeader.Title href="#home">Sykepenger</InternalHeader.Title>
<InternalHeader.User name="Ola Normann" className="ml-auto" />
<Spacer />
<InternalHeader.User name="Ola Normann" />
</InternalHeader>
);
};
@@ -1,16 +1,16 @@
import { Dropdown, InternalHeader } from "@navikt/ds-react";
import { Dropdown, InternalHeader, Spacer } from "@navikt/ds-react";
import { withDsExample } from "components/website-modules/examples/withDsExample";
const Example = () => {
return (
<InternalHeader>
<InternalHeader.Title as="h1">Sykepenger</InternalHeader.Title>
<Spacer />
<Dropdown>
<InternalHeader.UserButton
as={Dropdown.Toggle}
name="Ola Normann"
description="Enhet: Skien"
className="ml-auto"
/>
<Dropdown.Menu>
<Dropdown.Menu.List>
@@ -1,4 +1,4 @@
import { Search } from "@navikt/ds-react";
import { Search, Spacer } from "@navikt/ds-react";
import { InternalHeader } from "@navikt/ds-react";
import { withDsExample } from "components/website-modules/examples/withDsExample";
@@ -20,7 +20,8 @@ const Example = () => {
placeholder="Søk"
/>
</form>
<InternalHeader.User name="Ola Normann" className="ml-auto" />
<Spacer />
<InternalHeader.User name="Ola Normann" />
</InternalHeader>
);
};
@@ -1,13 +1,14 @@
import { MenuGridIcon } from "@navikt/aksel-icons";
import { Dropdown, InternalHeader } from "@navikt/ds-react";
import { Dropdown, InternalHeader, Spacer } from "@navikt/ds-react";
import { withDsExample } from "components/website-modules/examples/withDsExample";
const Example = () => {
return (
<InternalHeader>
<InternalHeader.Title as="h1">Sykepenger</InternalHeader.Title>
<Spacer />
<Dropdown>
<InternalHeader.Button as={Dropdown.Toggle} className="ml-auto">
<InternalHeader.Button as={Dropdown.Toggle}>
<MenuGridIcon
style={{ fontSize: "1.5rem" }}
title="Systemer og oppslagsverk"
@@ -3,7 +3,7 @@ import { withDsExample } from "components/website-modules/examples/withDsExample
const Example = () => {
return (
<Select label="Hvilket land har du bosted i.">
<Select label="Hvilket land har du bosted i?">
<option value="">Velg land</option>
<option value="norge">Norge</option>
<option value="sverige">Sverige</option>
@@ -4,7 +4,7 @@ import { withDsExample } from "components/website-modules/examples/withDsExample
const Example = () => {
return (
<Select
label="Hvilket land har du bosted i."
label="Hvilket land har du bosted i?"
description="Velg det landet du tilbringer mest tid."
>
<option value="">Velg land</option>
@@ -3,7 +3,7 @@ import { withDsExample } from "components/website-modules/examples/withDsExample
const Example = () => {
return (
<Select label="Hvilket land har du bosted i." disabled>
<Select label="Hvilket land har du bosted i?" disabled>
<option value="">Velg land</option>
<option value="norge">Norge</option>
<option value="sverige">Sverige</option>
@@ -4,7 +4,7 @@ import { withDsExample } from "components/website-modules/examples/withDsExample
const Example = () => {
return (
<Select
label="Hvilket land har du bosted i."
label="Hvilket land har du bosted i?"
error="Adressen matcher ikke landet du har satt som bosted."
>
<option value="">Velg land</option>
@@ -3,7 +3,7 @@ import { withDsExample } from "components/website-modules/examples/withDsExample
const Example = () => {
return (
<Select label="Hvilket land har du bosted i." hideLabel>
<Select label="Hvilket land har du bosted i?" hideLabel>
<option value="">Velg land</option>
<option value="norge">Norge</option>
<option value="sverige">Sverige</option>
@@ -3,7 +3,7 @@ import { withDsExample } from "components/website-modules/examples/withDsExample
const Example = () => {
return (
<Select label="Hvilket land har du bosted i." readOnly value="sverige">
<Select label="Hvilket land har du bosted i?" readOnly value="sverige">
<option value="">Velg land</option>
<option value="norge">Norge</option>
<option value="sverige">Sverige</option>
@@ -3,7 +3,7 @@ import { withDsExample } from "components/website-modules/examples/withDsExample
const Example = () => {
return (
<Select label="Hvilket land har du bosted i." size="small">
<Select label="Hvilket land har du bosted i?" size="small">
<option value="">Velg land</option>
<option value="norge">Norge</option>
<option value="sverige">Sverige</option>
@@ -0,0 +1,80 @@
import { HStack, VStack } from "@navikt/ds-react";
import { withDsExample } from "components/website-modules/examples/withDsExample";
const Example = () => {
return (
<div className="bg-deepblue-50">
<HStack gap="12">
<div>
<VStack gap="3" align="center">
<Placeholder text="center" />
<Placeholder />
<Placeholder />
<Placeholder />
</VStack>
</div>
<div>
<VStack gap="3" align="end">
<Placeholder text="end" />
<Placeholder />
<Placeholder />
<Placeholder />
</VStack>
</div>
<div>
<VStack gap="3" align="start">
<Placeholder text="start" />
<Placeholder />
<Placeholder />
<Placeholder />
</VStack>
</div>
<div>
<VStack gap="3" align="stretch">
<Placeholder text="stretch" />
<Placeholder />
<Placeholder />
<Placeholder />
</VStack>
</div>
<div>
<VStack gap="3" align="baseline">
<Placeholder text="baseline" />
<Placeholder text="text" noPadding />
<Placeholder text="text" noPadding />
<Placeholder text="text" noPadding />
</VStack>
</div>
</HStack>
</div>
);
};
export default withDsExample(Example);
/* Storybook story */
export const Demo = {
render: Example,
};
export const args = {
index: 1,
desc: "Endrer 'align-items'.",
};
const Placeholder = ({
text,
noPadding,
}: {
text?: string;
noPadding?: boolean;
}) => {
return (
<div
className="min-h-4 text-text-on-action h-auto w-auto rounded bg-teal-600 p-2"
style={{ padding: noPadding && 0 }}
>
{text}
</div>
);
};
@@ -0,0 +1,29 @@
import { VStack } from "@navikt/ds-react";
import { withDsExample } from "components/website-modules/examples/withDsExample";
const Example = () => {
return (
<VStack gap="4">
<Placeholder />
<Placeholder />
<Placeholder />
<Placeholder />
</VStack>
);
};
export default withDsExample(Example);
/* Storybook story */
export const Demo = {
render: Example,
};
export const args = {
index: 0,
desc: "VStack er en enkel layout-komponent for flexbox med flex-direction: column.",
};
const Placeholder = () => {
return <div className="aspect-square h-12 rounded bg-teal-500" />;
};
@@ -0,0 +1,72 @@
import { HStack, VStack } from "@navikt/ds-react";
import { withDsExample } from "components/website-modules/examples/withDsExample";
const Example = () => {
return (
<div className="bg-deepblue-50 flex h-72">
<HStack gap="2" wrap={false}>
<VStack justify="center">
<Placeholder text="center" />
<Placeholder />
</VStack>
<Divider />
<VStack justify="end">
<Placeholder text="end" />
<Placeholder />
</VStack>
<Divider />
<VStack justify="start">
<Placeholder text="start" />
</VStack>
<Divider />
<VStack justify="space-around">
<Placeholder text="around" />
<Placeholder />
</VStack>
<Divider />
<VStack justify="space-between">
<Placeholder text="between" />
<Placeholder />
</VStack>
<Divider />
<VStack justify="space-evenly">
<Placeholder text="evenly" />
<Placeholder />
</VStack>
</HStack>
</div>
);
};
export default withDsExample(Example);
/* Storybook story */
export const Demo = {
render: Example,
};
export const args = {
index: 2,
desc: "Endrer 'justify-content'.",
};
const Divider = () => {
return <hr className="border-r-border-divider m-0 h-full border-r" />;
};
const Placeholder = ({
text,
noPadding,
}: {
text?: string;
noPadding?: boolean;
}) => {
return (
<div
className="min-h-4 text-text-on-action h-auto w-auto rounded bg-teal-600 p-2"
style={{ padding: noPadding && 0 }}
>
{text}
</div>
);
};
@@ -0,0 +1,29 @@
import { VStack } from "@navikt/ds-react";
import { withDsExample } from "components/website-modules/examples/withDsExample";
const Example = () => {
return (
<VStack gap={{ xs: "4", sm: "6", md: "8", lg: "10", xl: "12" }}>
<Placeholder />
<Placeholder />
<Placeholder />
<Placeholder />
</VStack>
);
};
export default withDsExample(Example);
/* Storybook story */
export const Demo = {
render: Example,
};
export const args = {
index: 3,
desc: "Med responsive gap kan man redusere/øke mellomrom basert på brekkpunktene våre",
};
const Placeholder = () => {
return <div className="aspect-square h-12 rounded bg-teal-500" />;
};
+2 -2
View File
@@ -10,8 +10,8 @@
"preview": "vite preview"
},
"dependencies": {
"@navikt/ds-css": "4.7.4",
"@navikt/ds-react": "4.7.4",
"@navikt/ds-css": "4.9.0",
"@navikt/ds-react": "4.9.0",
"react": "^18.0.0",
"react-dom": "^18.0.0"
},