-
Notifications
You must be signed in to change notification settings - Fork 39
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
Only have types for data-color
and data-size
when designsystemet type is added to users tsconfig
#2943
Comments
data-color
when type is added to users tsconfigdata-color
and data-size
when designsystemet type is added to users tsconfig
I think the default type should contain what it does today, but also |
#2951) #2943 - Made it so `data-size` and `data-color` also accept any string as default so its the same as behaviour for other data attributes. - Except for explicits components - Removed references and default values for `data-size` and `data-color` in stories as thats contextual. - Removed unnecessary override to `data-size` and `data-color` to make sure the jsdocs and behaviour is uniform. - Added `data-color` and `data-size` as global `argTypes` for storybook so that they show up in controls for all components
One solution is to fallback to In import type { IsEmptyObject } from 'type-fest'
export type Color = IsEmptyObject<MainAndSupportColors> extends true
? string & {}
: CustomColors | SeverityColors; If we don't want to depend type-fest, we can inline the definition:
Example: When empty When extended: |
Actually, maybe this is better, since some of our components import just type ColorWithFallback<T> = IsEmptyObject<MainAndSupportColors> extends true ? string & {} : T
export type SeverityColors = ColorWithFallback<'info' | 'success' | 'warning' | 'danger'>
export type CustomColors = ColorWithFallback<'neutral' | keyof MainAndSupportColors>
export type Color = CustomColors | SeverityColors; |
Suggestion for improvement.
Currently if you have not added
color.d.ts
orreact-types.d.ts
, usage ofdata-color
anddata-size
is quite inconsistent and confusing.Depending on where you are using the data-attributes you get different types.
Confusing aspects
- Used on plain elements (div
,span
), you can not use any string, which you can on other data attributes.Suggestions
Tasks
The text was updated successfully, but these errors were encountered: