-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Ny komponent] Stack, Spacer (#2040)
- Loading branch information
Showing
28 changed files
with
962 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@navikt/ds-css": minor | ||
"@navikt/ds-react": minor | ||
--- | ||
|
||
Nye komponenter `VStack`, `HStack` og `Spacer` for å enklere kunne lage layout med flexbox og spacing-variabler. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)))) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" />; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" />; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
})} | ||
/> | ||
); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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} />; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { HStack, type HStackProps } from "./HStack"; | ||
export { VStack, type VStackProps } from "./VStack"; | ||
export { Spacer } from "./Spacer"; |
Oops, something went wrong.