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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tree-shaking in blade components #1045

Merged
merged 13 commits into from
Mar 23, 2023
19 changes: 9 additions & 10 deletions packages/blade/src/components/ActionList/ActionListItem.tsx
Expand Up @@ -16,7 +16,6 @@ import { useDropdown } from '~components/Dropdown/useDropdown';
import type { Feedback } from '~tokens/theme/theme';
import { Text } from '~components/Typography';
import { isReactNative, makeAccessible, makeSize, metaAttribute, MetaConstants } from '~utils';
import type { WithComponentId } from '~utils';
import { Checkbox } from '~components/Checkbox';
import size from '~tokens/global/size';
import type { StringChildrenType } from '~src/_helpers/types';
Expand Down Expand Up @@ -97,11 +96,11 @@ type ActionListSectionProps = {
*/
_hideDivider?: boolean;
};
const ActionListSection: WithComponentId<ActionListSectionProps> = ({
const ActionListSection = ({
title,
children,
_hideDivider,
}): JSX.Element => {
}: ActionListSectionProps): JSX.Element => {
return (
<BaseBox
{...makeAccessible({
Expand Down Expand Up @@ -130,9 +129,9 @@ const ActionListSection: WithComponentId<ActionListSectionProps> = ({
);
};

ActionListSection.componentId = componentIds.ActionListSection;
/*#__PURE__*/ Object.assign(ActionListSection, { componentId: componentIds.ActionListSection });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

馃槄 this looks scary

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol check it out now. It got scarier 馃槅


const ActionListItemIcon: WithComponentId<{ icon: IconComponent }> = ({ icon }): JSX.Element => {
const ActionListItemIcon = ({ icon }: { icon: IconComponent }): JSX.Element => {
const Icon = icon;
const { intent, isDisabled } = React.useContext(ActionListItemContext);
return (
Expand All @@ -147,9 +146,9 @@ const ActionListItemIcon: WithComponentId<{ icon: IconComponent }> = ({ icon }):
);
};

ActionListItemIcon.componentId = componentIds.ActionListItemIcon;
/*#__PURE__*/ Object.assign(ActionListItemIcon, { componentId: componentIds.ActionListItemIcon });

const ActionListItemText: WithComponentId<{ children: StringChildrenType }> = ({ children }) => {
const ActionListItemText = ({ children }: { children: StringChildrenType }): JSX.Element => {
const { isDisabled } = React.useContext(ActionListItemContext);

return (
Expand All @@ -159,7 +158,7 @@ const ActionListItemText: WithComponentId<{ children: StringChildrenType }> = ({
);
};

ActionListItemText.componentId = componentIds.ActionListItemText;
/*#__PURE__*/ Object.assign(ActionListItemText, { componentId: componentIds.ActionListItemText });

const ActionListCheckboxWrapper = styled(BaseBox)<{ hasDescription: boolean }>((_props) => ({
pointerEvents: 'none',
Expand Down Expand Up @@ -199,7 +198,7 @@ const makeActionListItemClickable = (
* </ActionList>
* ```
*/
const ActionListItem: WithComponentId<ActionListItemProps> = (props): JSX.Element => {
const ActionListItem = (props: ActionListItemProps): JSX.Element => {
const {
activeIndex,
dropdownBaseId,
Expand Down Expand Up @@ -332,7 +331,7 @@ const ActionListItem: WithComponentId<ActionListItemProps> = (props): JSX.Elemen
);
};

ActionListItem.componentId = componentIds.ActionListItem;
/*#__PURE__*/ Object.assign(ActionListItem, { componentId: componentIds.ActionListItem });

export {
ActionListItem,
Expand Down
Expand Up @@ -444,6 +444,6 @@ const _BaseButton: React.ForwardRefRenderFunction<BladeElementRef, BaseButtonPro
};

const BaseButton = React.forwardRef(_BaseButton);
BaseButton.displayName = 'BaseButton';
/*#__PURE__*/ Object.assign(BaseButton, { displayName: 'BaseButton' });

export default BaseButton;
Expand Up @@ -102,6 +102,6 @@ const _StyledBaseButton: React.ForwardRefRenderFunction<BladeElementRef, StyledB
};

const StyledBaseButton = React.forwardRef(_StyledBaseButton);
StyledBaseButton.displayName = 'StyledBaseButton';
/*#__PURE__*/ Object.assign(StyledBaseButton, { displayName: 'StyledBaseButton' });

export default StyledBaseButton;
2 changes: 1 addition & 1 deletion packages/blade/src/components/Button/Button/Button.tsx
Expand Up @@ -73,6 +73,6 @@ const _Button: React.ForwardRefRenderFunction<BladeElementRef, ButtonProps> = (
};

const Button = React.forwardRef(_Button);
Button.displayName = 'Button';
/*#__PURE__*/ Object.assign(Button, { displayName: 'Button' });

export default Button;
3 changes: 2 additions & 1 deletion packages/blade/src/components/Checkbox/Checkbox.tsx
Expand Up @@ -237,6 +237,7 @@ const _Checkbox: React.ForwardRefRenderFunction<BladeElementRef, CheckboxProps>
};

const Checkbox = React.forwardRef(_Checkbox);
Checkbox.displayName = 'Checkbox';

/*#__PURE__*/ Object.assign(Checkbox, { displayName: 'Checkbox' });

export { Checkbox, CheckboxProps };
Expand Up @@ -85,6 +85,6 @@ const _SelectorInput: React.ForwardRefRenderFunction<
};

const SelectorInput = React.forwardRef(_SelectorInput);
SelectorInput.displayName = 'SelectorInput';
/*#__PURE__*/ Object.assign(SelectorInput, { displayName: 'SelectorInput' });

export { SelectorInput };
Expand Up @@ -158,6 +158,6 @@ const _PasswordInput: React.ForwardRefRenderFunction<BladeElementRef, PasswordIn

const PasswordInput = React.forwardRef(_PasswordInput);
// nosemgrep
PasswordInput.displayName = 'PasswordInput';
/*#__PURE__*/ Object.assign(PasswordInput, { displayName: 'PasswordInput' });

export { PasswordInputProps, PasswordInput };
Expand Up @@ -155,7 +155,7 @@ const _SelectInput = (
* Checkout {@link https://blade.razorpay.com/?path=/docs/components-dropdown-with-select--with-single-select SelectInput Documentation}.
*/
const SelectInput = React.forwardRef(_SelectInput);
// @ts-expect-error: componentId is our custom attribute
SelectInput.componentId = 'SelectInput';

/*#__PURE__*/ Object.assign(SelectInput, { componentId: 'SelectInput' });

export { SelectInput, SelectInputProps };
Expand Up @@ -163,6 +163,6 @@ const _TextArea: React.ForwardRefRenderFunction<BladeElementRef, TextAreaProps>
};

const TextArea = React.forwardRef(_TextArea);
TextArea.displayName = 'TextArea';
/*#__PURE__*/ Object.assign(TextArea, { displayName: 'TextArea' });

export { TextArea, TextAreaProps };
Expand Up @@ -284,6 +284,7 @@ const _TextInput: React.ForwardRefRenderFunction<BladeElementRef, TextInputProps
};

const TextInput = React.forwardRef(_TextInput);
TextInput.displayName = 'TextInput';

/*#__PURE__*/ Object.assign(TextInput, { displayName: 'TextInput' });

export { TextInput, TextInputProps };
2 changes: 1 addition & 1 deletion packages/blade/src/components/Radio/Radio.tsx
Expand Up @@ -116,6 +116,6 @@ const _Radio: React.ForwardRefRenderFunction<BladeElementRef, RadioProps> = (
};

const Radio = React.forwardRef(_Radio);
Radio.displayName = 'Radio';
/*#__PURE__*/ Object.assign(Radio, { displayName: 'Radio' });

export { Radio, RadioProps };