@@ -4,19 +4,22 @@ import { Fragment } from 'react'
44import { Field } from '@theme-ui/components'
55import Combobox from '../Combobox'
66
7- type OnChangeArg =
8- | { fontFamily : string }
9- | { fontSize : number }
10- | { fontWeight : string }
11- | { lineHeight : string }
7+ type TypographyPropsValue = {
8+ fontFamily ?: string
9+ fontSize ?: string | number
10+ fontWeight ?: string | number
11+ lineHeight ?: string | number
12+ }
13+
14+ type OnChangeArg = {
15+ [ P in keyof TypographyPropsValue ] : {
16+ [ K in P ] : Exclude < TypographyPropsValue [ P ] , undefined >
17+ }
18+ } [ keyof TypographyPropsValue ]
19+
1220export interface TypographyProps {
1321 tag ?: string
14- value ?: {
15- fontFamily ?: string
16- fontSize ?: string | number
17- fontWeight ?: string
18- lineHeight ?: string
19- }
22+ value ?: TypographyPropsValue
2023 theme ?: Theme
2124 onChange : ( arg : OnChangeArg ) => void
2225}
@@ -40,7 +43,7 @@ export const SxTypography = ({
4043 name = { prefixName ( 'fontFamily' ) }
4144 label = "Font Family"
4245 value = { fontFamily || '' }
43- onChange = { ( fontFamily ) => {
46+ onChange = { fontFamily => {
4447 onChange ( { fontFamily } )
4548 } }
4649 options = { [ 'inherit' , ...Object . keys ( fonts ) ] }
@@ -56,7 +59,7 @@ export const SxTypography = ({
5659 label = "Font Size"
5760 value = { fontSize || '' }
5861 type = "number"
59- onChange = { ( e ) => {
62+ onChange = { e => {
6063 const fontSize = Number ( e . target . value )
6164 onChange ( { fontSize } )
6265 } }
@@ -65,7 +68,7 @@ export const SxTypography = ({
6568 name = { prefixName ( 'fontWeight' ) }
6669 label = "Font Weight"
6770 value = { fontWeight || '' }
68- onChange = { ( fontWeight ) => {
71+ onChange = { fontWeight => {
6972 onChange ( { fontWeight } )
7073 } }
7174 options = { [ 'inherit' , ...Object . keys ( fontWeights ) ] }
@@ -74,7 +77,7 @@ export const SxTypography = ({
7477 name = { prefixName ( 'lineHeight' ) }
7578 label = "Line Height"
7679 value = { lineHeight || '' }
77- onChange = { ( lineHeight ) => {
80+ onChange = { lineHeight => {
7881 onChange ( { lineHeight } )
7982 } }
8083 options = { [ 'inherit' , ...Object . keys ( lineHeights ) ] }
0 commit comments