-
Notifications
You must be signed in to change notification settings - Fork 151
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
fix(blade): chipgroup grid alignment #2536
Changes from 21 commits
39da608
67b9d5f
fb84e53
2481620
1e89e97
72efaeb
18838c7
464acc8
f280c95
98296fb
7c9803a
f3633f3
a818274
dc6fa5a
23ee578
f4652cb
bb40a3f
62f74c1
2a32ed1
a1f66f9
c02f1e9
1836fdc
8adc366
3443de8
1774421
833b335
4be16b6
bf73016
eee166f
29bfc15
aad91c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@razorpay/blade': patch | ||
--- | ||
|
||
fix(blade): allow consumers to align chips in chipgroup |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,19 @@ type OnChange = ({ | |
}) => void; | ||
|
||
const _Chip: React.ForwardRefRenderFunction<BladeElementRef, ChipProps> = ( | ||
{ isDisabled, value, children, icon: Icon, color, testID, _motionMeta, ...rest }, | ||
{ | ||
isDisabled, | ||
value, | ||
children, | ||
icon: Icon, | ||
color, | ||
testID, | ||
_motionMeta, | ||
width, | ||
maxWidth, | ||
minWidth, | ||
...rest | ||
}, | ||
ref, | ||
) => { | ||
const { theme } = useTheme(); | ||
|
@@ -158,9 +170,20 @@ const _Chip: React.ForwardRefRenderFunction<BladeElementRef, ChipProps> = ( | |
onKeyDown={handleKeyboardPressedIn} | ||
onKeyUp={handleKeyboardPressedOut} | ||
inputProps={isReactNative() ? inputProps : {}} | ||
style={{ cursor: _isDisabled ? 'not-allowed' : 'pointer' }} | ||
style={{ | ||
cursor: _isDisabled ? 'not-allowed' : 'pointer', | ||
width: width as string | number, | ||
maxWidth: maxWidth as string | number, | ||
minWidth: minWidth as string | number, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will break if I do |
||
}} | ||
> | ||
<BaseBox display="flex" flexDirection="column"> | ||
<BaseBox | ||
display="flex" | ||
flexDirection="column" | ||
width={width} | ||
maxWidth={maxWidth} | ||
minWidth={minWidth} | ||
tewarig marked this conversation as resolved.
Show resolved
Hide resolved
|
||
> | ||
<BaseBox display="flex" alignItems="center" flexDirection="row"> | ||
<SelectorInput | ||
hoverTokens={getChipInputHoverTokens(chipColor)} | ||
|
@@ -175,6 +198,9 @@ const _Chip: React.ForwardRefRenderFunction<BladeElementRef, ChipProps> = ( | |
isDisabled={_isDisabled} | ||
isPressed={isPressed} | ||
isDesktop={matchedDeviceType === 'desktop'} | ||
width={width} | ||
maxWidth={maxWidth} | ||
minWidth={minWidth} | ||
> | ||
<StyledChipWrapper | ||
borderColor={chipBorderColor} | ||
|
@@ -201,6 +227,9 @@ const _Chip: React.ForwardRefRenderFunction<BladeElementRef, ChipProps> = ( | |
} | ||
height={makeSize(chipHeightTokens[_size])} | ||
gap="spacing.3" | ||
width={width} | ||
maxWidth={maxWidth} | ||
minWidth={minWidth} | ||
> | ||
{Icon ? ( | ||
<BaseBox display="flex"> | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -727,3 +727,82 @@ chipRef.parameters = { | |||||
exclude: ['icon'], | ||||||
}, | ||||||
}; | ||||||
|
||||||
export const CutomLayoutInChipGroup: StoryFn<typeof ChipGroupComponent> = () => { | ||||||
const chipArray = [ | ||||||
{ | ||||||
value: '100', | ||||||
label: '₹100', | ||||||
}, | ||||||
{ | ||||||
value: '500', | ||||||
label: '₹500', | ||||||
}, | ||||||
{ | ||||||
value: '1000', | ||||||
label: '₹1000', | ||||||
}, | ||||||
{ | ||||||
value: '2000', | ||||||
label: '₹2000', | ||||||
}, | ||||||
{ | ||||||
value: '5000', | ||||||
label: '₹5000', | ||||||
}, | ||||||
{ | ||||||
value: '10000', | ||||||
label: '₹10000', | ||||||
}, | ||||||
{ | ||||||
value: '20000', | ||||||
label: '₹20000', | ||||||
}, | ||||||
{ | ||||||
value: '50000', | ||||||
label: '₹50000', | ||||||
}, | ||||||
{ | ||||||
value: '100000', | ||||||
label: '₹100000', | ||||||
}, | ||||||
{ | ||||||
value: '200000', | ||||||
label: '₹200000', | ||||||
}, | ||||||
]; | ||||||
|
||||||
return ( | ||||||
<Box gap="spacing.3" display="flex" flexDirection="column"> | ||||||
<ChipGroupComponent | ||||||
selectionType="single" | ||||||
label="Select a gift card with value (without custom chipGroupContainerLayout)" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
what is chipGroupContainerLayout? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
> | ||||||
{chipArray.map((chip, index) => ( | ||||||
<ChipComponent key={index} value={chip.value}> | ||||||
{chip.label} | ||||||
</ChipComponent> | ||||||
))} | ||||||
</ChipGroupComponent> | ||||||
<ChipGroupComponent | ||||||
selectionType="single" | ||||||
label="Select a gift card with value (custom chipGroupContainerLayout)" | ||||||
> | ||||||
<Box | ||||||
display="grid" | ||||||
gridTemplateColumns="repeat(3, 1fr)" | ||||||
gridTemplateRows="repeat(3, minmax(0, 30px))" | ||||||
gap="spacing.3" | ||||||
> | ||||||
{chipArray.map((chip, index) => ( | ||||||
<ChipComponent key={index} value={chip.value} width="100%"> | ||||||
{chip.label} | ||||||
</ChipComponent> | ||||||
))} | ||||||
</Box> | ||||||
</ChipGroupComponent> | ||||||
</Box> | ||||||
); | ||||||
}; | ||||||
|
||||||
CutomLayoutInChipGroup.storyName = 'ChipGroup with Custom layout'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import React from 'react'; | ||
import { chipGroupGapTokens, chipGroupLabelSizeTokens } from './chipTokens'; | ||
import { chipGroupLabelSizeTokens, chipGroupGapTokens } from './chipTokens'; | ||
import { ChipGroupProvider } from './ChipGroupContext'; | ||
import { useChipGroup } from './useChipGroup'; | ||
import type { ChipGroupProps } from './types'; | ||
|
@@ -96,18 +96,15 @@ const _ChipGroup = ( | |
<VisuallyHidden> | ||
<Text>{accessibilityLabel}</Text> | ||
</VisuallyHidden> | ||
<BaseBox display="flex" flexDirection="row" flexWrap="wrap"> | ||
{React.Children.map(children, (child, index) => { | ||
return ( | ||
<BaseBox | ||
key={index} | ||
marginBottom={chipGroupGapTokens[size].bottom} | ||
marginRight={chipGroupGapTokens[size].right} | ||
> | ||
{child} | ||
</BaseBox> | ||
); | ||
})} | ||
<BaseBox | ||
display="flex" | ||
flexDirection="row" | ||
flexWrap="wrap" | ||
rowGap={chipGroupGapTokens[size].bottom} | ||
columnGap={chipGroupGapTokens[size].right} | ||
marginBottom={chipGroupGapTokens[size].bottom} | ||
> | ||
{children} | ||
Comment on lines
-99
to
+107
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice 🏅 |
||
</BaseBox> | ||
<FormHint | ||
size={chipGroupLabelSizeTokens[size]} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is
as string | number
required here? isn't styled-components by default accepting string and number?