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

feat: adds styled icon base component #1791

Merged
merged 3 commits into from
Apr 18, 2024
Merged

feat: adds styled icon base component #1791

merged 3 commits into from
Apr 18, 2024

Conversation

geotrev
Copy link
Contributor

@geotrev geotrev commented Apr 17, 2024

Description

Adds the base styled icon component to react-theming, along with updates to two components to demonstrate usage.

A follow up PR will update the remaining component instances (13 in total).

Detail

The primary goals of this base component:

  • Make the cloneElement call centralized
  • Omit theme from the resulting prop spread

Separately, using this PR as an opportunity for transient props to prevent further prop-to-DOM leaking in the affected components.

Checklist

  • 👌 design updates will be Garden Designer approved (add the designer as a reviewer)
  • 🌐 demo is up-to-date (npm start)
  • ⬅️ renders as expected with reversed (RTL) direction
  • 🤘 renders as expected with Bedrock CSS (?bedrock)
  • 💂‍♂️ includes new unit tests. Maintain existing coverage (always >= 96%)
  • ♿ tested for WCAG 2.1 AA accessibility compliance
  • 📝 tested in Chrome, Firefox, Safari, and Edge

@geotrev geotrev self-assigned this Apr 17, 2024
@geotrev geotrev requested a review from a team as a code owner April 17, 2024 15:51

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export const StyledBaseIcon = styled(({ children, theme, ...props }) =>
React.cloneElement(Children.only(children), props)
Copy link
Contributor

Choose a reason for hiding this comment

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

props.theme appears to be excluded already. Was it still landing in the DOM?

Copy link
Contributor Author

@geotrev geotrev Apr 17, 2024

Choose a reason for hiding this comment

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

Strange, it still shows up for me unless i omit the prop here 🤷🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I see what's happening. theme is omitted in a normal styled.div (or any tag) call. But because of the cloneElement, we need to manually omit it.


// eslint-disable-next-line @typescript-eslint/no-unused-vars
export const StyledBaseIcon = styled(({ children, theme, ...props }) =>
React.cloneElement(Children.only(children), props)
Copy link
Member

Choose a reason for hiding this comment

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

[nit] prefer a { cloneElement } import over React.cloneElement.

@@ -24,6 +24,7 @@ export { useWindow } from './utils/useWindow';
export { useText } from './utils/useText';
export { default as menuStyles } from './utils/menuStyles';
export { focusStyles, SELECTOR_FOCUS_VISIBLE } from './utils/focusStyles';
export { StyledBaseIcon } from './styled/StyledBaseIcon';
Copy link
Member

Choose a reason for hiding this comment

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

Should this just live in utils? We have other ...Styles utilities in there based heavily on styled-components. I'm thinking we can avoid this one-off.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that feels better.

Comment on lines 19 to 27
'data-garden-id': COMPONENT_ID,
'data-garden-version': PACKAGE_VERSION
})`
${props => retrieveComponentStyles(COMPONENT_ID, props)};
`;

StyledBaseIcon.defaultProps = {
theme: DEFAULT_THEME
};
Copy link
Member

Choose a reason for hiding this comment

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

Recommend removing from the base.

Co-authored-by: Jonathan Zempel <jzempel@gmail.com>
@geotrev geotrev merged commit ff81ed3 into next Apr 18, 2024
5 checks passed
@geotrev geotrev deleted the george/styled-icon-base branch April 18, 2024 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants