-
Notifications
You must be signed in to change notification settings - Fork 149
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
feat(blade): Changes in components for X migration #2448
Changes from all commits
f193d16
5caa308
92bd8a9
fbb78e8
cf5797f
3d3c75f
47f20db
f54f105
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,22 @@ | ||
--- | ||
"@razorpay/blade": minor | ||
--- | ||
|
||
feat(blade): Changes in components for X migration | ||
|
||
**Drawer:** | ||
- Changed the drawer's showOverlay behaviour to not mandate the overlay on level2 stacking | ||
- Exposed ref | ||
|
||
**RadioGroup:** | ||
- Exposed event in onChange | ||
|
||
**ButtonGroup:** | ||
- Added styled props | ||
- Added support for Tooltip inside ButtonGroup | ||
|
||
**IconButton:** | ||
- Added styledProps | ||
|
||
**SideNavLink:** | ||
- Added onClick |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -13,6 +13,7 @@ import { getFocusRingStyles } from '~utils/getFocusRingStyles'; | |||
import { throwBladeError } from '~utils/logger'; | ||||
import getIn from '~utils/lodashButBetter/get'; | ||||
import { makeAnalyticsAttribute } from '~utils/makeAnalyticsAttribute'; | ||||
import { useStyledProps } from '~components/Box/styledProps'; | ||||
|
||||
type StyledButtonProps = { | ||||
emphasis: SubtleOrIntense; | ||||
|
@@ -23,7 +24,7 @@ type StyledButtonProps = { | |||
const StyledButton = styled.button<StyledButtonProps>((props) => { | ||||
const { theme, emphasis } = props; | ||||
const motionToken = theme.motion; | ||||
|
||||
const styledPropsCSSObject = useStyledProps(props); | ||||
const emphasisColor = emphasis === 'intense' ? 'gray' : 'staticWhite'; | ||||
|
||||
if (__DEV__) { | ||||
|
@@ -74,6 +75,7 @@ const StyledButton = styled.button<StyledButtonProps>((props) => { | |||
'&:active': { | ||||
color: theme.colors.interactive.icon[emphasisColor].subtle, | ||||
}, | ||||
...styledPropsCSSObject, | ||||
}; | ||||
}); | ||||
|
||||
|
@@ -121,6 +123,7 @@ const StyledIconButton = React.forwardRef<HTMLButtonElement, StyledIconButtonPro | |||
{...makeAccessible({ label: accessibilityLabel })} | ||||
{...metaAttribute({ name: MetaConstants.IconButton, testID })} | ||||
{...makeAnalyticsAttribute(rest)} | ||||
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
|
||||
{...rest} | ||||
> | ||||
<Icon size={size} color={isDisabled ? 'interactive.icon.gray.disabled' : 'currentColor'} /> | ||||
</StyledButton> | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import type { ReactElement } from 'react'; | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import type { ButtonGroupProps } from './types'; | ||
|
@@ -13,10 +12,9 @@ import type { DotNotationToken } from '~utils/lodashButBetter/get'; | |
import getIn from '~utils/lodashButBetter/get'; | ||
import { getBackgroundColorToken } from '~components/Button/BaseButton/BaseButton'; | ||
import type { Theme } from '~components/BladeProvider'; | ||
import { throwBladeError } from '~utils/logger'; | ||
import { isValidAllowedChildren } from '~utils/isValidAllowedChildren'; | ||
import type { BladeElementRef } from '~utils/types'; | ||
import { makeAnalyticsAttribute } from '~utils/makeAnalyticsAttribute'; | ||
import { useVerifyAllowedChildren } from '~utils/useVerifyAllowedChildren'; | ||
|
||
const getDividerColorToken = ({ | ||
color, | ||
|
@@ -74,6 +72,12 @@ const _ButtonGroup = ( | |
isFullWidth, | ||
}; | ||
|
||
useVerifyAllowedChildren({ | ||
allowedComponents: ['Button', 'Dropdown', 'Tooltip', 'Popover'], | ||
componentName: 'ButtonGroup', | ||
children, | ||
}); | ||
|
||
return ( | ||
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 🤝 |
||
<ButtonGroupProvider value={contextValue}> | ||
<StyledButtonGroup | ||
|
@@ -88,26 +92,6 @@ const _ButtonGroup = ( | |
role="group" | ||
> | ||
{React.Children.map(children, (child, index) => { | ||
if (__DEV__) { | ||
// throw error if child is not a button or dropdown with button trigger | ||
/* eslint-disable no-restricted-properties */ | ||
if ( | ||
!isValidAllowedChildren(child, 'Button') && | ||
!( | ||
isValidAllowedChildren(child, 'Dropdown') && | ||
(child as ReactElement).props.children.some((c: ReactElement) => | ||
isValidAllowedChildren(c, 'DropdownButton'), | ||
) | ||
) | ||
) { | ||
throwBladeError({ | ||
moduleName: 'ButtonGroup', | ||
message: `Only "Button" or "Dropdown" component with Button trigger are allowed as children.`, | ||
}); | ||
} | ||
/* eslint-enable no-restricted-properties */ | ||
} | ||
|
||
return ( | ||
<> | ||
{child} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ import { Button } from '~components/Button/Button'; | |
import { ChevronDownIcon, PlusIcon } from '~components/Icons'; | ||
import { Dropdown, DropdownButton, DropdownOverlay } from '~components/Dropdown'; | ||
import { ActionList, ActionListItem } from '~components/ActionList'; | ||
import { AutoComplete } from '~components/Input/DropdownInputTriggers'; | ||
|
||
beforeAll(() => jest.spyOn(console, 'error').mockImplementation()); | ||
afterAll(() => jest.restoreAllMocks()); | ||
|
@@ -168,40 +167,7 @@ describe('<ButtonGroup />', () => { | |
</ButtonGroup>, | ||
), | ||
).toThrowError( | ||
'[Blade: ButtonGroup]: Only "Button" or "Dropdown" component with Button trigger are allowed as children.', | ||
); | ||
}); | ||
|
||
it('should throw error with invalid dropdown children', () => { | ||
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 remove this test? 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. Removed this test since Additionally, the previous check felt overly defensive. It validated nested components like |
||
expect(() => | ||
renderWithTheme( | ||
<ButtonGroup> | ||
<Button icon={PlusIcon}>Payout</Button> | ||
<Dropdown selectionType="single"> | ||
<AutoComplete | ||
label="City" | ||
placeholder="Select your City" | ||
name="action" | ||
onChange={({ name, values }) => { | ||
console.log({ name, values }); | ||
}} | ||
onInputValueChange={({ name, value }) => { | ||
console.log({ name, value }); | ||
}} | ||
/> | ||
<DropdownOverlay> | ||
<ActionList> | ||
<ActionListItem title="Mumbai" value="mumbai" /> | ||
<ActionListItem title="Pune" value="pune" /> | ||
<ActionListItem title="Bangalore" value="bangalore" /> | ||
<ActionListItem title="Mysore" value="mysore" /> | ||
</ActionList> | ||
</DropdownOverlay> | ||
</Dropdown> | ||
</ButtonGroup>, | ||
), | ||
).toThrowError( | ||
'[Blade: ButtonGroup]: Only "Button" or "Dropdown" component with Button trigger are allowed as children.', | ||
'[Blade: ButtonGroup]: Only `Button, Dropdown, Tooltip, Popover` components are accepted in `ButtonGroup` children', | ||
); | ||
}); | ||
}); |
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.
I think we can remove this {...makeAnalyticsAttribute(rest)}, since we are now using ...rest, which handles the analytics attributes.