-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
377 additions
and
2 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,8 @@ | ||
--- | ||
"@navikt/ds-css": minor | ||
"@navikt/ds-react": minor | ||
--- | ||
|
||
:tada: Ny komponent Skeleton! | ||
|
||
- varianter: text, circle, rounded og rectangle |
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,55 @@ | ||
.navds-skeleton { | ||
display: block; | ||
background-color: var(--ac-skeleton-bg, var(--a-surface-neutral-moderate)); | ||
height: 1.3em; | ||
animation: akselSkeletonAnimation 0.8s linear infinite alternate; | ||
} | ||
|
||
.navds-skeleton--has-children { | ||
color: transparent; | ||
} | ||
|
||
.navds-skeleton--has-children > * { | ||
visibility: hidden; | ||
} | ||
|
||
.navds-skeleton--has-children.navds-skeleton--no-height { | ||
height: auto; | ||
} | ||
|
||
.navds-skeleton--has-children.navds-skeleton--no-width { | ||
width: fit-content; | ||
} | ||
|
||
.navds-skeleton--text { | ||
height: auto; | ||
transform-origin: 0 55%; | ||
transform: scale(1, 0.6); | ||
border-radius: var(--a-border-radius-medium); | ||
} | ||
|
||
.navds-skeleton--text:empty::before { | ||
content: "\00a0"; | ||
} | ||
|
||
.navds-skeleton--circle { | ||
border-radius: var(--a-border-radius-full); | ||
} | ||
|
||
.navds-skeleton--rectangle { | ||
border-radius: 0; | ||
} | ||
|
||
.navds-skeleton--rounded { | ||
border-radius: var(--a-border-radius-xlarge); | ||
} | ||
|
||
@keyframes akselSkeletonAnimation { | ||
0% { | ||
opacity: 1; | ||
} | ||
|
||
100% { | ||
opacity: 0.4; | ||
} | ||
} |
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,48 @@ | ||
import React, { forwardRef } from "react"; | ||
import cl from "clsx"; | ||
|
||
export interface SkeletonProps extends React.HTMLAttributes<HTMLDivElement> { | ||
children?: React.ReactNode; | ||
/** | ||
* @default text | ||
*/ | ||
variant?: "circle" | "rectangle" | "rounded" | "text"; | ||
/** | ||
* When not inferring height from children, you must specify height | ||
*/ | ||
height?: number | string; | ||
/** | ||
* When not infering width from children, you must specify width | ||
*/ | ||
width?: number | string; | ||
} | ||
|
||
export const Skeleton = forwardRef<HTMLDivElement, SkeletonProps>( | ||
( | ||
{ className, children, height, width, style, variant = "text", ...rest }, | ||
ref | ||
) => { | ||
return ( | ||
<div | ||
{...rest} | ||
ref={ref} | ||
className={cl( | ||
"navds-skeleton", | ||
className, | ||
`navds-skeleton--${variant}`, | ||
{ | ||
"navds-skeleton--has-children": Boolean(children), | ||
"navds-skeleton--no-height": !height, | ||
"navds-skeleton--no-width": !width, | ||
} | ||
)} | ||
style={{ ...style, width, height }} | ||
aria-hidden | ||
> | ||
{children} | ||
</div> | ||
); | ||
} | ||
); | ||
|
||
export default Skeleton; |
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,2 @@ | ||
export { default as Skeleton } from "./Skeleton"; | ||
export type { SkeletonProps } from "./Skeleton"; |
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,118 @@ | ||
import React from "react"; | ||
import { Skeleton } from "."; | ||
import { Alert } from "../alert"; | ||
import { Button } from "../button"; | ||
import { Checkbox } from "../form"; | ||
import { BodyLong, Heading } from "../typography"; | ||
|
||
export default { | ||
title: "ds-react/Skeleton", | ||
component: Skeleton, | ||
decorators: [ | ||
(Story) => ( | ||
<div style={{ display: "grid", gap: "0.5rem" }}> | ||
<Story /> | ||
</div> | ||
), | ||
], | ||
}; | ||
|
||
export const Default = { | ||
render: () => ( | ||
<div> | ||
<Skeleton> | ||
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consequuntur | ||
voluptas sint dolore omnis quia consequatur beatae vero cum officia | ||
debitis. Quidem debitis omnis reprehenderit nobis rerum. Nulla, magnam? | ||
Saepe, eveniet? Test | ||
</Skeleton> | ||
<Skeleton> | ||
<Alert variant="info"> | ||
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consequuntur | ||
voluptas sint dolore omnis quia consequatur beatae vero cum officia | ||
debitis. Quidem debitis omnis reprehenderit nobis rerum. Nulla, | ||
magnam? Saepe, eveniet? | ||
</Alert> | ||
</Skeleton> | ||
<Skeleton> | ||
<BodyLong> | ||
Quidem debitis omnis reprehenderit nobis rerum. Nulla, magnam? Saepe, | ||
eveniet? | ||
</BodyLong> | ||
<Checkbox value="test">Valg 1</Checkbox> | ||
<Checkbox value="tes2">Valg 2</Checkbox> | ||
<div style={{ display: "flex", gap: "2rem" }}> | ||
<Button>Send inn</Button> | ||
<Button>Tilbake</Button> | ||
</div> | ||
</Skeleton> | ||
</div> | ||
), | ||
}; | ||
|
||
export const Shapes = { | ||
render: () => ( | ||
<> | ||
<Skeleton variant="text"></Skeleton> | ||
<Skeleton variant="circle" width={60} height={60}></Skeleton> | ||
<Skeleton variant="rectangle" width={200} height={40}></Skeleton> | ||
<Skeleton variant="rounded" width={200} height={40}></Skeleton> | ||
</> | ||
), | ||
}; | ||
|
||
export const WrappingComponents = { | ||
render: () => ( | ||
<Skeleton style={{ display: "grid", gap: "0.5rem" }}> | ||
<BodyLong> | ||
Quidem debitis omnis reprehenderit nobis rerum. Nulla, magnam? Saepe, | ||
eveniet? | ||
</BodyLong> | ||
<Checkbox value="test">Valg 1</Checkbox> | ||
<Checkbox value="tes2">Valg 2</Checkbox> | ||
<div style={{ display: "flex", gap: "2rem" }}> | ||
<Button>Send inn</Button> | ||
<Button>Tilbake</Button> | ||
</div> | ||
</Skeleton> | ||
), | ||
}; | ||
|
||
export const TextSizing = { | ||
render: () => ( | ||
<div style={{ display: "grid", width: 300 }}> | ||
<Skeleton> | ||
<Heading level="1" size="xlarge"> | ||
Placeholder | ||
</Heading> | ||
</Skeleton> | ||
<Skeleton> | ||
<BodyLong>Placeholder</BodyLong> | ||
</Skeleton> | ||
<BodyLong as={Skeleton}>Placeholder</BodyLong> | ||
</div> | ||
), | ||
}; | ||
|
||
export const NativeText = { | ||
render: () => ( | ||
<div> | ||
<h1> | ||
<Skeleton> | ||
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consequuntur | ||
voluptas sint dolore omnis quia consequatur beatae vero cum officia | ||
debitis. Quidem debitis omnis reprehenderit nobis rerum. Nulla, | ||
magnam? Saepe, eveniet? Test | ||
</Skeleton> | ||
</h1> | ||
<Skeleton> | ||
<p> | ||
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consequuntur | ||
voluptas sint dolore omnis quia consequatur beatae vero cum officia | ||
debitis. Quidem debitis omnis reprehenderit nobis rerum. Nulla, | ||
magnam? Saepe, eveniet? Test | ||
</p> | ||
</Skeleton> | ||
</div> | ||
), | ||
}; |
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,25 @@ | ||
import { Skeleton } from "@navikt/ds-react"; | ||
import { withDsExample } from "components/website-modules/examples/withDsExample"; | ||
|
||
const Example = () => { | ||
return ( | ||
<div className="shadow-medium ring-border-subtle w-56 rounded-lg p-6 ring-1"> | ||
<Skeleton variant="circle" width={60} height={60} /> | ||
<Skeleton variant="text" width="100%" /> | ||
<Skeleton variant="text" width="100%" /> | ||
<Skeleton variant="text" width="100%" /> | ||
<Skeleton variant="text" width="80%" /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default withDsExample(Example); | ||
|
||
/* Storybook story */ | ||
export const Demo = { | ||
render: Example, | ||
}; | ||
|
||
export const args = { | ||
index: 4, | ||
}; |
22 changes: 22 additions & 0 deletions
22
aksel.nav.no/website/pages/eksempler/skeleton/children.tsx
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,22 @@ | ||
import { Button, Skeleton, TextField } from "@navikt/ds-react"; | ||
import { withDsExample } from "components/website-modules/examples/withDsExample"; | ||
|
||
const Example = () => { | ||
return ( | ||
<Skeleton variant="rounded"> | ||
<TextField label="E-post" /> | ||
<Button>Send inn</Button> | ||
</Skeleton> | ||
); | ||
}; | ||
|
||
export default withDsExample(Example); | ||
|
||
/* Storybook story */ | ||
export const Demo = { | ||
render: Example, | ||
}; | ||
|
||
export const args = { | ||
index: 3, | ||
}; |
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,35 @@ | ||
import { Heading, Skeleton } from "@navikt/ds-react"; | ||
import { withDsExample } from "components/website-modules/examples/withDsExample"; | ||
|
||
const Example = () => { | ||
return ( | ||
<> | ||
{loaded ? ( | ||
<span>Loaded</span> | ||
) : ( | ||
<div className="w-48"> | ||
<Skeleton variant="circle" width={80} height={80} /> | ||
<Heading as={Skeleton} size="large"> | ||
Card-title | ||
</Heading> | ||
<Skeleton variant="text" width="100%" /> | ||
<Skeleton variant="text" width="100%" /> | ||
<Skeleton variant="text" width="80%" /> | ||
</div> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default withDsExample(Example); | ||
|
||
/* Storybook story */ | ||
export const Demo = { | ||
render: Example, | ||
}; | ||
|
||
export const args = { | ||
index: 5, | ||
}; | ||
|
||
const loaded = false; |
Oops, something went wrong.