Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Bulletproof Design System with TypeScript

Bulletproof Design System with TypeScript

Avatar for takanorip

takanorip

May 23, 2025

More Decks by takanorip

Other Decks in Design

Transcript

  1. Style Dictionaryを活用 typescript/es6-declarations で型定義を出力する export const : export const :

    ; ; ColorBackgroundGray string ColorBackgroundBlue string これを利用してコンポーネントのPropsなどを自動生成できる
  2. Branded Typesの活用 SpacingとRadiusなど構造が同一だが混同したくないものを区別できる type extends = & in : type

    = type extends = extends ? | : export type = export const : < , > { [ ] }; ; < > < , > ; < >; ; Branded T U T key U TokenType DesignToken T T TokenType Branded T DesignTokenSpacing DesignToken DesignTokenSpacing string never string string never SizeSpacingXs 'spacing' 'designToken' 'spacing'
  3. Branded Typesの生成 Style Dictionaryの を利用する registerTransform import from => =>

    StyleDictionary ; StyleDictionary. ({ type: , transitive: , name: , : ( , ) {}, : ( ) { }, }); 'style-dictionary' `value` `myTransitiveTransform` registerTransform filter transform true token options token // token.value will be resolved and transformed at this point
  4. export const : | = ... => return < =

    ? : ? : ... > </ > < > ({ mx, props }) { ( style {{ : rightKey (rightKey) , : leftKey (leftKey) , }} { } { } BoxComponent ); }; Box FC PropsWithoutText PropsWithTextBody createSpacingVariableFromKey createSpacingVariableFromKey BoxComponent props children '--padding-right' '0' '--padding-left' '0'
  5. CSS VariablesをTemplate Literalで管理する const = : => return export const

    = ?: => return ? : as ( ) { DesignTokens radius key path ; }; ( ) { { : radius (radius) , } ; }; createRadiusVariableFromKey Radius join radiusVariables Radius createRadiusVariableFromKey CSSProperties key radius `var(--${ . [ ]. . ('-')})` '--radius' '0'
  6. as Propの活用 type extends = ?: : & export default

    function extends = ... : const = as || return ... </ > < . > { ; . ; } . ; < . >({ , , } < >) { ; < { }> : {children} Component ; } BoxProps C React ElementType C React ReactNode React ComponentPropsWithoutRef Box C React ElementType BoxProps C Component rest as children as children rest 'div' 'div' Component BOX
  7. GitHub Actions経由でデザイントークンを書き出す できる限り自動化しておくことでデザイナーでも更新できるようにする Figma REST API の Open API Spec

    が公開されているので、 TypeScriptを活用して処理を実装できる https://github.com/figma/rest-api-spec import type from const = await { GetFileResponse } axios. < >(url); result.data '@figma/rest-api-spec' result get GetFileResponse // This has type GetFileResponse