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

add development checks for displayName #2141

Merged
merged 2 commits into from
Jul 16, 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
5 changes: 5 additions & 0 deletions .changeset/proud-hornets-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@itwin/itwinui-react': patch
---

Component `displayName`s have been eliminiated from the prod build.
24 changes: 18 additions & 6 deletions packages/itwinui-react/src/core/Alert/Alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ const AlertComponent = React.forwardRef((props, forwardedRef) => {
</Alert.Wrapper>
);
}) as PolymorphicForwardRefComponent<'div', AlertOwnProps & AlertLegacyProps>;
AlertComponent.displayName = 'Alert';
if (process.env.NODE_ENV === 'development') {
AlertComponent.displayName = 'Alert';
}

// ----------------------------------------------------------------------------
// Alert.Wrapper component
Expand All @@ -101,7 +103,9 @@ const AlertWrapper = React.forwardRef((props, ref) => {
</Box>
);
}) as PolymorphicForwardRefComponent<'div', AlertOwnProps>;
AlertWrapper.displayName = 'Alert.Wrapper';
if (process.env.NODE_ENV === 'development') {
AlertWrapper.displayName = 'Alert.Wrapper';
}

// ----------------------------------------------------------------------------
// Alert.Icon component
Expand All @@ -119,13 +123,17 @@ const AlertIcon = React.forwardRef((props, ref) => {
</Icon>
);
}) as PolymorphicForwardRefComponent<'span', React.ComponentProps<typeof Icon>>;
AlertIcon.displayName = 'Alert.Icon';
if (process.env.NODE_ENV === 'development') {
AlertIcon.displayName = 'Alert.Icon';
}

// ----------------------------------------------------------------------------
// Alert.Message component

const AlertMessage = polymorphic.span('iui-alert-message');
AlertMessage.displayName = 'Alert.Message';
if (process.env.NODE_ENV === 'development') {
AlertMessage.displayName = 'Alert.Message';
}

// ----------------------------------------------------------------------------
// Alert.Action component
Expand All @@ -147,7 +155,9 @@ const AlertAction = React.forwardRef((props, ref) => {
</Anchor>
);
}) as PolymorphicForwardRefComponent<'a'>;
AlertAction.displayName = 'Alert.Action';
if (process.env.NODE_ENV === 'development') {
AlertAction.displayName = 'Alert.Action';
}

// ----------------------------------------------------------------------------
// Alert.CloseButton component
Expand All @@ -167,7 +177,9 @@ const AlertCloseButton = React.forwardRef((props, ref) => {
</IconButton>
);
}) as PolymorphicForwardRefComponent<'button'>;
AlertCloseButton.displayName = 'Alert.CloseButton';
if (process.env.NODE_ENV === 'development') {
AlertCloseButton.displayName = 'Alert.CloseButton';
}

/**
* A small box to quickly grab user attention and communicate a brief message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,9 @@ const BreadcrumbsItem = React.forwardRef((props, forwardedRef) => {
/>
);
}) as PolymorphicForwardRefComponent<'a'>;
BreadcrumbsItem.displayName = 'Breadcrumbs.Item';
if (process.env.NODE_ENV === 'development') {
BreadcrumbsItem.displayName = 'Breadcrumbs.Item';
}

// ----------------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import {
export const ButtonGroupContext = React.createContext<string | undefined>(
undefined,
);
ButtonGroupContext.displayName = 'ButtonGroupContext';
if (process.env.NODE_ENV === 'development') {
ButtonGroupContext.displayName = 'ButtonGroupContext';
}

// ----------------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ export const ComboBoxEndIcon = React.forwardRef((props, forwardedRef) => {
</Icon>
);
}) as PolymorphicForwardRefComponent<'span', ComboBoxEndIconProps>;
ComboBoxEndIcon.displayName = 'ComboBoxEndIcon';
if (process.env.NODE_ENV === 'development') {
ComboBoxEndIcon.displayName = 'ComboBoxEndIcon';
}
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,6 @@ export const ComboBoxInput = React.forwardRef((props, forwardedRef) => {
</>
);
}) as PolymorphicForwardRefComponent<'input', ComboBoxInputProps>;
ComboBoxInput.displayName = 'ComboBoxInput';
if (process.env.NODE_ENV === 'development') {
ComboBoxInput.displayName = 'ComboBoxInput';
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ export const ComboBoxInputContainer = React.forwardRef(
);
},
) as PolymorphicForwardRefComponent<'div', ComboBoxInputContainerProps>;
ComboBoxInputContainer.displayName = 'ComboBoxInputContainer';
if (process.env.NODE_ENV === 'development') {
ComboBoxInputContainer.displayName = 'ComboBoxInputContainer';
}
4 changes: 3 additions & 1 deletion packages/itwinui-react/src/core/ComboBox/ComboBoxMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,6 @@ export const ComboBoxMenu = React.forwardRef((props, forwardedRef) => {
)
);
}) as PolymorphicForwardRefComponent<'div', ComboBoxMenuProps>;
ComboBoxMenu.displayName = 'ComboBoxMenu';
if (process.env.NODE_ENV === 'development') {
ComboBoxMenu.displayName = 'ComboBoxMenu';
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,6 @@ export const ComboBoxMenuItem = React.memo(
);
}) as PolymorphicForwardRefComponent<'div', ComboBoxMenuItemProps>,
);
ComboBoxMenuItem.displayName = 'ComboBoxMenuItem';
if (process.env.NODE_ENV === 'development') {
ComboBoxMenuItem.displayName = 'ComboBoxMenuItem';
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ export const ComboBoxMultipleContainer = React.forwardRef((props, ref) => {
return <SelectTagContainer ref={ref} tags={selectedItems} {...rest} />;
}) as PolymorphicForwardRefComponent<'div', ComboBoxMultipleContainerProps>;

ComboBoxMultipleContainer.displayName = 'ComboBoxMultipleContainer';
if (process.env.NODE_ENV === 'development') {
ComboBoxMultipleContainer.displayName = 'ComboBoxMultipleContainer';
}
8 changes: 6 additions & 2 deletions packages/itwinui-react/src/core/ComboBox/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export const ComboBoxRefsContext = React.createContext<
}
| undefined
>(undefined);
ComboBoxRefsContext.displayName = 'ComboBoxRefsContext';
if (process.env.NODE_ENV === 'development') {
ComboBoxRefsContext.displayName = 'ComboBoxRefsContext';
}

type ComboBoxStateContextProps<T = unknown> = {
isOpen: boolean;
Expand All @@ -34,4 +36,6 @@ type ComboBoxStateContextProps<T = unknown> = {
export const ComboBoxStateContext = React.createContext<
ComboBoxStateContextProps | undefined
>(undefined);
ComboBoxStateContext.displayName = 'ComboBoxStateContext';
if (process.env.NODE_ENV === 'development') {
ComboBoxStateContext.displayName = 'ComboBoxStateContext';
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ const ExpandableBlockContext = React.createContext<
} & ExpandableBlockOwnProps)
| undefined
>(undefined);
ExpandableBlockContext.displayName = 'ExpandableBlockContext';
if (process.env.NODE_ENV === 'development') {
ExpandableBlockContext.displayName = 'ExpandableBlockContext';
}

// ----------------------------------------------------------------------------
// Main ExpandableBlock component
Expand Down Expand Up @@ -90,7 +92,9 @@ const ExpandableBlockComponent = React.forwardRef((props, forwardedRef) => {
'div',
ExpandableBlockOwnProps & ExpandableBlockLegacyProps
>;
ExpandableBlockComponent.displayName = 'ExpandableBlock';
if (process.env.NODE_ENV === 'development') {
ExpandableBlockComponent.displayName = 'ExpandableBlock';
}

// ----------------------------------------------------------------------------

Expand Down Expand Up @@ -144,7 +148,9 @@ const ExpandableBlockWrapper = React.forwardRef((props, forwardedRef) => {
</ExpandableBlockContext.Provider>
);
}) as PolymorphicForwardRefComponent<'div', ExpandableBlockOwnProps>;
ExpandableBlockWrapper.displayName = 'ExpandableBlock.Wrapper';
if (process.env.NODE_ENV === 'development') {
ExpandableBlockWrapper.displayName = 'ExpandableBlock.Wrapper';
}

// ----------------------------------------------------------------------------
// ExpandableBlock.Trigger component
Expand Down Expand Up @@ -184,7 +190,9 @@ const ExpandableBlockTrigger = React.forwardRef((props, forwardedRef) => {
</LinkBox>
);
}) as PolymorphicForwardRefComponent<'div', ExpandableBlockTriggerOwnProps>;
ExpandableBlockTrigger.displayName = 'ExpandableBlock.Trigger';
if (process.env.NODE_ENV === 'development') {
ExpandableBlockTrigger.displayName = 'ExpandableBlock.Trigger';
}

// ----------------------------------------------------------------------------
// ExpandableBlock.ExpandIcon component
Expand All @@ -201,13 +209,17 @@ const ExpandableBlockExpandIcon = React.forwardRef((props, forwardedRef) => {
</Icon>
);
}) as PolymorphicForwardRefComponent<'span'>;
ExpandableBlockExpandIcon.displayName = 'ExpandableBlock.ExpandIcon';
if (process.env.NODE_ENV === 'development') {
ExpandableBlockExpandIcon.displayName = 'ExpandableBlock.ExpandIcon';
}

// ----------------------------------------------------------------------------
// ExpandableBlock.LabelArea component

const ExpandableBlockLabelArea = polymorphic.span('iui-expandable-block-label');
ExpandableBlockLabelArea.displayName = 'ExpandableBlock.LabelArea';
if (process.env.NODE_ENV === 'development') {
ExpandableBlockLabelArea.displayName = 'ExpandableBlock.LabelArea';
}

// ----------------------------------------------------------------------------
// ExpandableBlock.Title component
Expand Down Expand Up @@ -238,7 +250,9 @@ const ExpandableBlockTitle = React.forwardRef((props, forwardedRef) => {
</ButtonBase>
);
}) as PolymorphicForwardRefComponent<'button'>;
ExpandableBlockTitle.displayName = 'ExpandableBlock.Title';
if (process.env.NODE_ENV === 'development') {
ExpandableBlockTitle.displayName = 'ExpandableBlock.Title';
}

// ----------------------------------------------------------------------------
// ExpandableBlock.Caption component
Expand All @@ -262,7 +276,9 @@ const ExpandableBlockCaption = React.forwardRef((props, forwardedRef) => {
/>
);
}) as PolymorphicForwardRefComponent<'div'>;
ExpandableBlockCaption.displayName = 'ExpandableBlock.Caption';
if (process.env.NODE_ENV === 'development') {
ExpandableBlockCaption.displayName = 'ExpandableBlock.Caption';
}

// ----------------------------------------------------------------------------
// ExpandableBlock.EndIcon component
Expand All @@ -281,7 +297,9 @@ const ExpandableBlockEndIcon = React.forwardRef((props, forwardedRef) => {
'span',
React.ComponentPropsWithoutRef<typeof Icon>
>;
ExpandableBlockEndIcon.displayName = 'ExpandableBlock.EndIcon';
if (process.env.NODE_ENV === 'development') {
ExpandableBlockEndIcon.displayName = 'ExpandableBlock.EndIcon';
}

// ----------------------------------------------------------------------------
// ExpandableBlock.Content component
Expand All @@ -302,7 +320,9 @@ const ExpandableBlockContent = React.forwardRef((props, forwardedRef) => {
</Box>
);
}) as PolymorphicForwardRefComponent<'div', ExpandableBlockContentOwnProps>;
ExpandableBlockContent.displayName = 'ExpandableBlock.Content';
if (process.env.NODE_ENV === 'development') {
ExpandableBlockContent.displayName = 'ExpandableBlock.Content';
}

/**
* Expandable block with customizable Title, Caption, Content and EndIcon subcomponents.
Expand Down
32 changes: 24 additions & 8 deletions packages/itwinui-react/src/core/FileUpload/FileUploadCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ const toDate = (dateNumber: number) => {
const FileUploadCardIcon = polymorphic.span('iui-file-card-icon', {
children: <SvgDocument />,
});
FileUploadCardIcon.displayName = 'FileUploadCard.Icon';
if (process.env.NODE_ENV === 'development') {
FileUploadCardIcon.displayName = 'FileUploadCard.Icon';
}

// ----------------------------------------------------------------------------
// FileUploadCard.Info component

const FileUploadCardInfo = polymorphic.span('iui-file-card-text');
FileUploadCardInfo.displayName = 'FileUploadCard.Info';
if (process.env.NODE_ENV === 'development') {
FileUploadCardInfo.displayName = 'FileUploadCard.Info';
}

// ----------------------------------------------------------------------------
// FileUploadCard.Title component
Expand All @@ -68,7 +72,9 @@ const FileUploadCardTitle = React.forwardRef((props, ref) => {
</Box>
);
}) as PolymorphicForwardRefComponent<'span'>;
FileUploadCardTitle.displayName = 'FileUploadCard.Title';
if (process.env.NODE_ENV === 'development') {
FileUploadCardTitle.displayName = 'FileUploadCard.Title';
}

// ----------------------------------------------------------------------------
// FileUploadCard.Description component
Expand Down Expand Up @@ -97,13 +103,17 @@ const FileUploadCardDescription = React.forwardRef((props, ref) => {
</Box>
);
}) as PolymorphicForwardRefComponent<'span'>;
FileUploadCardDescription.displayName = 'FileUploadCard.Description';
if (process.env.NODE_ENV === 'development') {
FileUploadCardDescription.displayName = 'FileUploadCard.Description';
}

// ----------------------------------------------------------------------------
// FileUploadCard.Action component

const FileUploadCardAction = polymorphic.div('iui-file-card-action');
FileUploadCardAction.displayName = 'FileUploadCard.Action';
if (process.env.NODE_ENV === 'development') {
FileUploadCardAction.displayName = 'FileUploadCard.Action';
}

// ----------------------------------------------------------------------------
// FileUploadCard.InputLabel component
Expand All @@ -117,7 +127,9 @@ const FileUploadCardInputLabel = React.forwardRef((props, ref) => {
</Anchor>
);
}) as PolymorphicForwardRefComponent<'label'>;
FileUploadCardInputLabel.displayName = 'FileUploadCard.InputLabel';
if (process.env.NODE_ENV === 'development') {
FileUploadCardInputLabel.displayName = 'FileUploadCard.InputLabel';
}

// ----------------------------------------------------------------------------
// FileUploadCard.Input component
Expand Down Expand Up @@ -168,7 +180,9 @@ const FileUploadCardInput = React.forwardRef((props, ref) => {
</>
);
}) as PolymorphicForwardRefComponent<'input'>;
FileUploadCardInput.displayName = 'FileUploadCard.Input';
if (process.env.NODE_ENV === 'development') {
FileUploadCardInput.displayName = 'FileUploadCard.Input';
}

// ----------------------------------------------------------------------------
// FileUploadCard component
Expand Down Expand Up @@ -277,7 +291,9 @@ export const FileUploadCard = Object.assign(FileUploadCardComponent, {
InputLabel: FileUploadCardInputLabel,
Input: FileUploadCardInput,
});
FileUploadCard.displayName = 'FileUploadCard';
if (process.env.NODE_ENV === 'development') {
FileUploadCard.displayName = 'FileUploadCard';
}

export const FileUploadCardContext = React.createContext<
| {
Expand Down
12 changes: 9 additions & 3 deletions packages/itwinui-react/src/core/Flex/Flex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ const FlexComponent = React.forwardRef((props, ref) => {
/>
);
}) as PolymorphicForwardRefComponent<'div', FlexOwnProps>;
FlexComponent.displayName = 'Flex';
if (process.env.NODE_ENV === 'development') {
FlexComponent.displayName = 'Flex';
}

type FlexOwnProps = {
/**
Expand Down Expand Up @@ -125,7 +127,9 @@ const FlexSpacer = React.forwardRef((props, ref) => {
/>
);
}) as PolymorphicForwardRefComponent<'div', FlexSpacerOwnProps>;
FlexSpacer.displayName = 'Flex.Spacer';
if (process.env.NODE_ENV === 'development') {
FlexSpacer.displayName = 'Flex.Spacer';
}

type FlexSpacerOwnProps = {
/**
Expand Down Expand Up @@ -169,7 +173,9 @@ const FlexItem = React.forwardRef((props, ref) => {
/>
);
}) as PolymorphicForwardRefComponent<'div', FlexItemOwnProps>;
FlexItem.displayName = 'Flex.Item';
if (process.env.NODE_ENV === 'development') {
FlexItem.displayName = 'Flex.Item';
}

type FlexItemOwnProps = {
/**
Expand Down
Loading
Loading