Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix flexGrow={0}, flexShrink={0} #2634

Merged
merged 2 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion playbook/app/pb_kits/playbook/types/base.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Simple base types
import { SyntheticEvent } from "react"

export type Binary = 0 | 1
export const BitValues = [0, 1] as const
export type Binary = typeof BitValues[number]
export type Callback<T, K> = (arg: T) => K
export type EmptyObject = Record<string, unknown>
export type InputCallback<T> = Callback<SyntheticEvent<T>, void>
Expand Down
13 changes: 9 additions & 4 deletions playbook/app/pb_kits/playbook/utilities/globalProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { omit } from 'lodash'
import { camelToSnakeCase } from './text'

import {
BitValues,
Binary,
Display,
DisplaySizes,
Expand Down Expand Up @@ -48,7 +49,7 @@ type FlexDirection = {
}

type FlexGrow = {
flexGrow?: 0 | 1
flexGrow?: Binary
}

type FlexShrink = {
Expand Down Expand Up @@ -316,15 +317,19 @@ const PROP_CATEGORIES: {[key:string]: (props: {[key: string]: any}) => string} =
flexGrowProps: ({ flexGrow }: FlexGrow) => {
if (typeof flexGrow == 'object') {
return getResponsivePropClasses(flexGrow, 'flex_grow')
} else if (BitValues.includes(flexGrow)) {
return `flex_grow_${flexGrow}`
} else {
return flexGrow ? `flex_grow_${flexGrow}` : ''
return ''
}
},
flexShrinkProps: ({ flexShrink }: FlexShrink) => {
if (typeof flexShrink == 'object') {
return getResponsivePropClasses(flexShrink, 'flex_shrink')
} else if (BitValues.includes(flexShrink)) {
return `flex_shrink_${flexShrink}`
} else {
return flexShrink ? `flex_shrink_${flexShrink}` : ''
return ''
}
},
justifyContentProps: ({ justifyContent }: JustifyContent) => {
Expand Down Expand Up @@ -392,4 +397,4 @@ export const domSafeProps = (props: {[key: string]: string}): {[key: string]: st
'dark',
]
return omit(props, notSafeProps)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test('Global Props: Returns ordinal suffixed class name', () => {
render(
<Body
data={{ testid: testId }}
flexGrow={`${x}`}
flexGrow={x}
text="Hi"
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test('Global Props: Returns ordinal suffixed class name', () => {
render(
<Body
data={{ testid: testId }}
flexShrink={`${x}`}
flexShrink={x}
text="Hi"
/>
)
Expand Down