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

Give typesafety for data-* #2655

Closed
Tracked by #2370
Barsnes opened this issue Oct 22, 2024 · 2 comments · Fixed by #2795
Closed
Tracked by #2370

Give typesafety for data-* #2655

Barsnes opened this issue Oct 22, 2024 · 2 comments · Fixed by #2795
Assignees
Labels
👨‍💻developer experience react @digdir/designsystemet-react

Comments

@Barsnes
Copy link
Member

Barsnes commented Oct 22, 2024

We don't need to add this to our package, but we can tell our users how to ensure they have typesafety and autocomplete for our data attributes.

declare global {
  namespace React.JSX {
    interface IntrinsicAttributes {
      'data-color-scheme'?: 'dark' | 'light'
    }
  }
  namespace React {
    interface HTMLAttributes<T> {
      'data-color-scheme'?: 'dark' | 'light';
    }
  }
}

We already do this for popover (popovertarget), and this is just something we need to add to our docs

Same goes for size:

Since all components (and HTML elements) will support data-size and data-color, we should expose this as props also in React and thus avoiding confusion on when size is available and when it is not.
We can however provide type safety by creating a shared props definition, which all components can extend:

/** Recommended sizes */
'data-size'?: 'sm' | 'md' | 'xl';

and those components with more sizes (Avatar, Spinner, Heading) can extend with more sizes in data-size

Note: data-color-scheme has been separated out to #2812

@Barsnes Barsnes moved this from 🔵 Inbox to 📋 Backlog in Team Design System Oct 22, 2024
@mimarz mimarz changed the title Give typesafety for data-ds-* Give typesafety for data-* Oct 24, 2024
@mimarz mimarz added the react @digdir/designsystemet-react label Oct 24, 2024
@unekinn
Copy link
Contributor

unekinn commented Oct 24, 2024

My suggestion:

  • Add a file types.d.ts with any types that are not dependent on tokens/themes to @digdir/designsystemet-react which can be imported in the consuming library
  • Output a types.d.ts from the CLI build command with any types that depend on token values / modes etc, which then becomes a part of @digdir/designsystemet-theme or an organization's own theme package
  • Add documentation on how/where to import these, and why, to README.md
    • Can be imported in an entry point file, or added to "types" array in tsconfig.json

@unekinn unekinn self-assigned this Nov 11, 2024
@unekinn
Copy link
Contributor

unekinn commented Nov 11, 2024

I'm handling this as part of #2703.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👨‍💻developer experience react @digdir/designsystemet-react
Projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

3 participants