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: css modules #2318

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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/gentle-geckos-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@digdir/designsystemet-css": patch
"@digdir/designsystemet-react": patch
---

Add CSS-modules for users to compose Designsystemet CSS
5 changes: 4 additions & 1 deletion apps/storefront/layouts/PageLayout/PageLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import paragraph from '@digdir/designsystemet-css/baseline/typography/paragraph.module.css';
import { Heading, Link } from '@digdir/designsystemet-react';
import { ArrowLeftIcon } from '@navikt/aksel-icons';
import { Container } from '@repo/components';
Expand Down Expand Up @@ -34,7 +35,9 @@ const PageLayout = ({ content, data }: PageLayoutProps) => {
{data.backText}
</NextLink>
</Link>
<div className={cl(classes.meta, 'ds-paragraph-short--lg')}>
<div
className={cl(classes.meta, paragraph['ds-paragraph-short--lg'])}
>
<span>{data.author && <div>{data.author}</div>}</span>
<span className={classes.separator}> - </span>
<span>{data.date && <div>{data.date}</div>}</span>
Expand Down
17 changes: 10 additions & 7 deletions packages/css/baseline/ds-reset.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@

/* https://wiki.csswg.org/ideas/mistakes */

[class^='ds-'],
[class^='ds-']::before,
[class^='ds-']::after {
/* TODO: Can this be moved to the related components? */
[class~='ds-'],
[class~='ds-']::before,
[class~='ds-']::after {
box-sizing: border-box;
}

/* Inherit fonts for inputs and buttons */
input[class^='ds-'],
button[class^='ds-'],
textarea[class^='ds-'],
select[class^='ds-'] {

/* TODO: Can this be moved to the related form element CSS files? */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think this is a better candididate for moving to to their relevant components.
However, it gives us another point of failure

Copy link
Contributor Author

@eirikbacker eirikbacker Aug 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above regarding targeting start of classnames :)
And I suggest forgetting to add styling should be done in reviews, not by an "invisible" dependency relation :)

input[class~='ds-'],
button[class~='ds-'],
textarea[class~='ds-'],
select[class~='ds-'] {
font-family: inherit;
font-size: inherit;
line-height: inherit;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* TODO: Could these styles be placed in css root like the other files? */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

.ds-paragraph {
--dsc-bottom-spacing: var(--ds-spacing-5);

Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions packages/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
@import url('./baseline/ds-reset.css') layer(ds.reset);
@import url('./baseline/typography/label.css') layer(ds.base.typography);
@import url('./baseline/typography/heading.css') layer(ds.base.typography);
@import url('./baseline/typography/paragraph.css') layer(ds.base.typography);
@import url('./baseline/typography/paragraph.module.css') layer(ds.base.typography);
@import url('./baseline/typography/ingress.css') layer(ds.base.typography);
@import url('./baseline/typography/error-message.css') layer(ds.base.typography);
@import url('./utilities.css') layer(ds.utilities);
@import url('./box.css') layer(ds.components);
@import url('./box.module.css') layer(ds.components);
@import url('./button.css') layer(ds.components);
@import url('./alert.css') layer(ds.components);
@import url('./skiplink.css') layer(ds.components);
Expand Down Expand Up @@ -42,6 +42,6 @@
@import url('./spinner.css') layer(ds.components);
@import url('./table.css') layer(ds.components);
@import url('./combobox.css') layer(ds.components);
@import url('./breadcrumbs.css') layer(ds.components);
@import url('./breadcrumbs.module.css') layer(ds.components);
@import url('./badge.css') layer(ds.components);
@import url('./avatar.css') layer(ds.components);
1 change: 1 addition & 0 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"access": "public"
},
"dependencies": {
"@digdir/designsystemet-css": "workspace:^",
"@floating-ui/react": "0.26.21",
"@navikt/aksel-icons": "^6.14.0",
"@radix-ui/react-slot": "^1.1.0",
Expand Down
9 changes: 5 additions & 4 deletions packages/react/src/components/Box/Box.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import styles from '@digdir/designsystemet-css/box.module.css';
import { Slot } from '@radix-ui/react-slot';
import cl from 'clsx/lite';
import type { HTMLAttributes } from 'react';
Expand Down Expand Up @@ -51,10 +52,10 @@ export const Box = forwardRef<HTMLDivElement, BoxProps>(
<Component
ref={ref}
className={cl(
shadow && `ds-box--${shadow}-shadow`,
borderColor && `ds-box--${borderColor}-border-color`,
borderRadius && `ds-box--${borderRadius}-border-radius`,
`ds-box--${background}-background`,
shadow && styles[`ds-box--${shadow}-shadow`],
borderColor && styles[`ds-box--${borderColor}-border-color`],
borderRadius && styles[`ds-box--${borderRadius}-border-radius`],
styles[`ds-box--${background}-background`],
className,
)}
{...rest}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import styles from '@digdir/designsystemet-css/breadcrumbs.module.css';
import cl from 'clsx/lite';
import { type HTMLAttributes, forwardRef } from 'react';

export type BreadcrumbsItemProps = HTMLAttributes<HTMLLIElement>;

export const BreadcrumbsItem = forwardRef<HTMLLIElement, BreadcrumbsItemProps>(
({ className, ...rest }, ref) => (
<li ref={ref} className={cl('ds-breadcrumbs__item', className)} {...rest} />
<li
ref={ref}
className={cl(styles['ds-breadcrumbs__item'], className)}
{...rest}
/>
),
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMergeRefs } from '@floating-ui/react';
import styles from '@digdir/designsystemet-css/breadcrumbs.module.css';
import cl from 'clsx/lite';
import { forwardRef, useRef } from 'react';

Expand All @@ -11,7 +11,11 @@ export const BreadcrumbsLink = forwardRef<
HTMLAnchorElement,
BreadcrumbsLinkProps
>(({ className, ...rest }, ref) => (
<Link className={cl(`ds-breadcrumbs__link`, className)} ref={ref} {...rest} />
<Link
className={cl(styles[`ds-breadcrumbs__link`], className)}
ref={ref}
{...rest}
/>
));

BreadcrumbsLink.displayName = 'BreadcrumbsLink';
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import styles from '@digdir/designsystemet-css/breadcrumbs.module.css';
import { useMergeRefs } from '@floating-ui/react';
import cl from 'clsx/lite';
import { type HTMLAttributes, forwardRef, useEffect, useRef } from 'react';
Expand All @@ -22,7 +23,7 @@ export const BreadcrumbsList = forwardRef<

return (
<ol
className={cl('ds-breadcrumbs__list', className)}
className={cl(styles['ds-breadcrumbs__list'], className)}
ref={mergedRefs}
{...rest}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import styles from '@digdir/designsystemet-css/breadcrumbs.module.css';
import cl from 'clsx/lite';
import { type HTMLAttributes, forwardRef } from 'react';

Expand All @@ -13,7 +14,7 @@ export const BreadcrumbsNav = forwardRef<HTMLElement, BreadcrumbsNavProps>(
<nav
aria-label={ariaLabel}
ref={ref}
className={cl('ds-breadcrumbs__nav', className)}
className={cl(styles['ds-breadcrumbs__nav'], className)}
{...rest}
/>
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import styles from '@digdir/designsystemet-css/breadcrumbs.module.css';
import cl from 'clsx/lite';
import { type HTMLAttributes, forwardRef } from 'react';

Expand All @@ -13,7 +14,11 @@ export const BreadcrumbsRoot = forwardRef<HTMLDivElement, BreadcrumbsRootProps>(
({ className, size = 'md', ...rest }, ref) => (
<div
ref={ref}
className={cl('ds-breadcrumbs', `ds-breadcrumbs--${size}`, className)}
className={cl(
styles['ds-breadcrumbs'],
styles[`ds-breadcrumbs--${size}`],
className,
)}
{...rest}
/>
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import styles from '@digdir/designsystemet-css/baseline/typography/paragraph.module.css';
import { Slot } from '@radix-ui/react-slot';
import cl from 'clsx/lite';
import type { HTMLAttributes } from 'react';
Expand Down Expand Up @@ -45,10 +46,10 @@ export const Paragraph = forwardRef<HTMLParagraphElement, ParagraphProps>(
<Component
ref={ref}
className={cl(
'ds-paragraph',
spacing && 'ds-paragraph--spacing',
`ds-paragraph--${size}`,
lineHeightMap[variant ?? 'default'],
styles['ds-paragraph'],
spacing && styles['ds-paragraph--spacing'],
styles[`ds-paragraph--${size}`],
styles[lineHeightMap[variant ?? 'default'] as keyof typeof styles],
className,
)}
{...rest}
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2963,6 +2963,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@digdir/designsystemet-react@workspace:packages/react"
dependencies:
"@digdir/designsystemet-css": "workspace:^"
"@floating-ui/react": "npm:0.26.21"
"@navikt/aksel-icons": "npm:^6.14.0"
"@radix-ui/react-slot": "npm:^1.1.0"
Expand Down
Loading