Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Allow setting the four-sides order for the split input control #6221

Merged
merged 1 commit into from
Aug 12, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export interface SplitChainedNumberInputProps<T> {
values: SplitChainedNumberInputValues
numberType: CSSNumberType
eventHandler: SplitChainedNumberInputEventHandler
fourSidesOrder?: Array<SplitFourValueSide>
}

export type SplitChainedNumberInputEventHandler = (
Expand Down Expand Up @@ -160,6 +161,8 @@ export function getInitialMode(

type CSSNumberOrNull = CSSNumber | null

export type SplitFourValueSide = 'T' | 'R' | 'B' | 'L'

export type FourValue =
| { type: 'T'; value: CSSNumberOrNull }
| { type: 'R'; value: CSSNumberOrNull }
Expand All @@ -174,7 +177,7 @@ export type SplitChainedEvent =
| { type: 'four-value'; value: FourValue }

export function splitChainedEventValueForProp(
prop: 'T' | 'R' | 'B' | 'L',
prop: SplitFourValueSide,
e: SplitChainedEvent,
): CSSNumber | null {
switch (e.type) {
Expand Down Expand Up @@ -456,7 +459,15 @@ const whenCSSNumber = (fn: (v: CSSNumber | null) => any) => (v: UnknownOrEmptyIn
}

export const SplitChainedNumberInput = React.memo((props: SplitChainedNumberInputProps<any>) => {
const { name, canvasControls, numberType, eventHandler, labels, values } = props
const {
name,
canvasControls,
numberType,
eventHandler,
labels,
values,
fourSidesOrder = ['T', 'R', 'L', 'B'],
} = props

const setHoveredCanvasControls = useSetAtom(InspectorHoveredCanvasControls)
const setFocusedCanvasControls = useSetAtom(InspectorFocusedCanvasControls)
Expand Down Expand Up @@ -600,8 +611,8 @@ export const SplitChainedNumberInput = React.memo((props: SplitChainedNumberInpu
},
]
case 'per-side':
return [
{
const sides: Record<SplitFourValueSide, Omit<NumberInputProps, 'chained' | 'id'>> = {
T: {
style: { width: '48%' },
value: values.fourValue.top?.value,
DEPRECATED_labelBelow: labels?.top ?? 'T',
Expand All @@ -619,7 +630,7 @@ export const SplitChainedNumberInput = React.memo((props: SplitChainedNumberInpu
},
testId: `${name}-T`,
},
{
R: {
style: { width: '48%' },
value: values.fourValue.right?.value,
DEPRECATED_labelBelow: labels?.right ?? 'R',
Expand All @@ -637,7 +648,7 @@ export const SplitChainedNumberInput = React.memo((props: SplitChainedNumberInpu
},
testId: `${name}-R`,
},
{
L: {
style: { width: '48%' },
value: values.fourValue.left?.value,
DEPRECATED_labelBelow: labels?.left ?? 'L',
Expand All @@ -655,7 +666,7 @@ export const SplitChainedNumberInput = React.memo((props: SplitChainedNumberInpu
},
testId: `${name}-L`,
},
{
B: {
style: { width: '48%' },
value: values.fourValue.bottom?.value,
DEPRECATED_labelBelow: labels?.bottom ?? 'B',
Expand All @@ -673,7 +684,8 @@ export const SplitChainedNumberInput = React.memo((props: SplitChainedNumberInpu
},
testId: `${name}-B`,
},
]
}
return fourSidesOrder.map((side) => sides[side])
case null:
return []
default:
Expand All @@ -689,6 +701,7 @@ export const SplitChainedNumberInput = React.memo((props: SplitChainedNumberInpu
eventHandler,
props.mode,
values,
fourSidesOrder,
])

const tooltipTitle = React.useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ const PaddingControl = React.memo(() => {
mode={modeToUse}
onCycleMode={onCycleMode}
values={values}
fourSidesOrder={['T', 'R', 'B', 'L']}
/>
)
})
Loading