-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow customizing sizes. DO NOT MERGE - test-custom-sizes.d.ts …
…just exists to prove it works
- Loading branch information
Showing
12 changed files
with
69 additions
and
12 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,11 @@ | ||
import type {} from '@digdir/designsystemet-react/sizes'; | ||
|
||
declare module '@digdir/designsystemet-react/sizes' { | ||
export interface SizeMap { | ||
'2xs': never; | ||
xs: never; | ||
sm: 'small'; | ||
md: 'medium'; | ||
lg: 'laaaarge'; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,7 +1,10 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"types": ["../../packages/theme/brand/colors.d.ts"] | ||
"types": [ | ||
"./test-custom-sizes.d.ts", | ||
"../../packages/theme/brand/colors.d.ts" | ||
] | ||
}, | ||
"include": [".", "./.storybook/**/*", "../../packages/css/postcss.config.js"] | ||
} |
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
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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './components'; | ||
export * from './utilities'; | ||
export type { Size } from './types'; | ||
export type { Size } from './sizes'; | ||
export type { Color } from './colors'; |
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,38 @@ | ||
/** | ||
* Base interface for user-defined mappings from Designsystemet's internal size names | ||
* to user-defined sizes. This allows a downstream library consumer to augment this | ||
* interface to change or disable a given size. | ||
* | ||
* Why would you do this? | ||
* - It lets you change the sizing scale (e.g. map all sizes one size down) | ||
* - It allows you to rename the sizes as you please (e.g. "small", "medium", ...) | ||
* NB: This means you would have to bring your own `data-size` styling, as renaming | ||
* a size to one that doesn't already exist in Designsystemet opts out of the | ||
* built-in `data-size` styling. | ||
* @example | ||
* import type {} from '@digdir/designsystemet-react/sizes'; | ||
* | ||
* // This will disable '2xs' and rename 'sm' to 'small' | ||
* declare module '@digdir/designsystemet-react/sizes' { | ||
* export interface SizeMap { | ||
* '2xs': never; | ||
* sm: 'small'; | ||
* } | ||
* } | ||
* | ||
*/ | ||
// biome-ignore lint/suspicious/noEmptyInterface: used for interface augmentation | ||
export interface SizeMap {} | ||
|
||
export type AllPossibleSizes = '2xs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl'; | ||
|
||
type DefaultSizeMap = { | ||
[K in AllPossibleSizes]: K; | ||
}; | ||
|
||
type CombinedSizeMap = Omit<DefaultSizeMap, keyof SizeMap> & SizeMap; | ||
|
||
/** Look up the actual size names for the given internal size names */ | ||
export type GetSizes<T extends AllPossibleSizes> = CombinedSizeMap[T]; | ||
|
||
export type Size = GetSizes<'sm' | 'md' | 'lg'>; |
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