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'
Slide 27
Slide 27 text
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
Slide 28
Slide 28 text
VSCode拡張をつくる
Style Dictionaryで生成した型を活用してVS Code拡張などのツールを
開発すると一石二鳥
参考W
V
V
デザイントークンを自動補完するVS Code拡張機能を開発しまし
CSS Variables 形式のデザイントークンを補完する VS Code Extension を作
成し生産性を上げる
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
Slide 36
Slide 36 text
JSDocのDocumentation機能を活用
エディタの機能を活用して
アップデートを知らせる
Slide 37
Slide 37 text
StyleをPropsで管理する
Chakra UI V2のStyle Propsの考え方を採用。
すべてのCSSに対応する必要はなく、必要があるものだけ対応すれば良い。
// mx = margin x
< = >
Box mx Test Box
"xxs"
Slide 38
Slide 38 text
Figmaとの連携
Slide 39
Slide 39 text
Figmaをデザイントークンの
Single Source of Truthとして扱う
デザイントークンは
ビジュアルとセットで管理する
コード(JSONなど)をSSoTとして扱う風潮もあるが私は懐疑的。
カラーコードを見て色がわかる人がいないと扱えないのでは?
Figma(デザインツール)からJSONを生成するほうが認知不可低いと考える。
Slide 40
Slide 40 text
No content
Slide 41
Slide 41 text
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