Skip to content

Conversation

@jesstelford
Copy link
Contributor

@jesstelford jesstelford commented Sep 12, 2023

Fixed #10393

@jesstelford jesstelford linked an issue Sep 15, 2023 that may be closed by this pull request
@jesstelford jesstelford force-pushed the encapsulate-style-props-10393 branch from 1630c0f to 4bf71b2 Compare September 15, 2023 08:07
jesstelford added a commit that referenced this pull request Sep 15, 2023
@jesstelford jesstelford force-pushed the encapsulate-style-props-10393 branch from 4bf71b2 to 63a9030 Compare September 15, 2023 08:37
@jesstelford jesstelford marked this pull request as ready for review September 15, 2023 08:37
Copy link
Member

@kyledurand kyledurand left a comment

Choose a reason for hiding this comment

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

This is looking good. As you can probably tell I'm not a fan of mixins. Not a blocker. If you do go the mixin route can you add a comment about why it's needed and where it should be used?

Comment on lines +18 to +22
@mixin non-responsive-prop($componentName, $componentProp, $declarationProp) {
@include scope-custom-property($componentName, $componentProp);

#{$declarationProp}: var(--pc-#{$componentName}-#{$componentProp});
}
Copy link
Member

Choose a reason for hiding this comment

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

My take here is to remove this mixin and include @include scope-custom-property where you need it. In the future we'll have atomic css from our tokens and shouldn't need all these custom properties everywhere. This added mixin complicates that clean up work.

The previous css was also much easier to read

Copy link
Contributor Author

@jesstelford jesstelford Sep 18, 2023

Choose a reason for hiding this comment

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

Agreed this is obfuscating some things which I also don't like, but it is enforcing a basic level of standardization which is kind of the reason this bug appeared in the first place (lack of standardization).

My approach here was to follow the pattern established by @mixin responsive-props(). The motivation being to avoid this issue coming back up again in the future (I can imagine future-me seeing --pc-foo-whatever: initial and thinking "That's completely useless, let's be a good engineer and remove it" without realizing it's important. Similarly for naming of breakpoint props - I actually want that encapsulated away somewhere (mixin or function, I don't mind) so it can be consistent with little effort from the dev (again, to avoid future accidental errors being introduced).

Maybe I'm being overly cautious, but the fact this bug existed for so long without anyone noticing implies to me if we accidentally reintroduce it somewhere, it'll go unnoticed again for a while.

I initial thought we could use a @function instead, and keep the CSS declaration in the callsite which would be easier to understand, but I don't think that's possible with the way we're doing the media query stuff unfortunately. Perhaps a PostCSS plugin might be a better solution for both of these cases? Keep the input CSS clean, but output fully responsive token sets transparently (kind of like autoprefixer, but more autoresponsivizer? 😛)

In the future we'll have atomic css from our tokens

Does that involve switching to a CSS-in-JS solution? Because without it, we'll still need to do this "donut scope" encapsulation of the CSS variables step regardless of what they're named.

Copy link
Member

Choose a reason for hiding this comment

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

Does that involve switching to a CSS-in-JS solution

Yes and no, I guess. I'm thinking we need css classes created from tokens, so we'd apply a class (based off of a prop) for padding for example and would automatically be scoped. This would clean up a ton of our css and remove a lot of buggy custom properties

// stylelint-disable-next-line -- Explicitly set `0` to create a local stacking context. While the initial `z-index: auto` has a stack level of `0` within the current stacking context, it does not create a new local stacking context.
z-index: 0;

@include scope-custom-property('shadow-bevel', 'z-index');
Copy link
Member

Choose a reason for hiding this comment

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

We should never have nested ShadowBevels right? What's this for? Can you /snapit and test the admin thoroughly if you think we need this added scope?

Copy link
Contributor Author

@jesstelford jesstelford Sep 18, 2023

Choose a reason for hiding this comment

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

Because <ShadowBevel> accepts children, it's possible for them to be nested (even if it may not make sense from a UX perspective).

It also comes baked into <Card>, but that hard-codes zIndex="32" so wont fall afoul of the inheritance bug (the bug only occurs when there's no explicit value set - when not set, nested <ShadowBevels> don't pass style={{ '--pc-shadow-bevel-z-index': zIndex }}, so it will incorrectly inherit their z-index from a parent <ShadowBevel>).

The final value gets applied to a ::before pseudo element located within the <ShadowBevel>, which itself sets z-index: 0 to create a new stacking context, so I think this could only introduce a regression in one case: Where there's an outer <ShadowBevel> with a high zIndex prop set (say; 1000), containing a nested <ShadowBevel> without a zIndex prop passed (so it incorrectly inherits the zIndex: 1000 prop), and there happens to be a child of the nested <ShadowBevel> (within the same stacking context) with an explicit z-index set which is lower than the zIndex prop passed to the outer <ShadowBevel>...

A quick Grokt shows no usages of <ShadowBevel> outside the Polaris repo, so the above situation doesn't occur afaict 🎉

Happy to test this more thoroughly, but can you think of a way to narrow down the scope of what to test besides attempting to load every page that uses a <Card>? 😅

Copy link
Member

Choose a reason for hiding this comment

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

We don't export the ShadowBevel component. It's internal only

@jesstelford jesstelford force-pushed the encapsulate-style-props-10393 branch from 63a9030 to da1e620 Compare September 18, 2023 01:52
@jesstelford jesstelford merged commit 5acfcec into main Sep 19, 2023
@jesstelford jesstelford deleted the encapsulate-style-props-10393 branch September 19, 2023 05:06
laurkim pushed a commit that referenced this pull request Sep 22, 2023
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @shopify/[email protected]

### Minor Changes

- [#10477](#10477)
[`790a001cd`](790a001)
Thanks [@aaronccasanova](https://github.com/aaronccasanova)! - Updated
semantic `color` tokens


- [#10478](#10478)
[`8be227e0c`](8be227e)
Thanks [@MaxCloutier](https://github.com/MaxCloutier)! - Added
`allowFiltering` prop on `ActionList`, and `filterActions` prop on Page
Header


- [#9445](#9445)
[`7be9c243a`](7be9c24)
Thanks [@m4thieulavoie](https://github.com/m4thieulavoie)! - Added
support for subheaders and selection of a range of `IndexTable.Rows` --
See the [With
subheaders](https://polaris.shopify.com/components/tables/index-table)
example on polaris.shopify.com for how to properly configure
    -   `IndexTable.Row`
- Added support for setting the `indeterminate` value on the `selected`
prop
- Added the `selectionRange` prop to specify a range of other
consecutive, related rows selected when the row is selected
- Added the `rowType` prop to indicate the relationship or role of the
row's contents (defaults to `data`, `subheader` renders the row to look
and behave like the table header row)
Added support for setting accessibility attributes on `IndexTable.Cell`
    -   `IndexTable.Cell`
- Added the `as` prop to support rendering the cell as a `th` element if
it is serving as a subheading cell
- Added support for the `headers` attribute to manually associate all
headers when the cell is described by more than its column heading
- Added support for the `colSpan` attribute to specify the number of the
columns that the cell element should extend to
- Added support for the `scope` attribute to indicate whether the `th`
is a header for a column, row, or group of columns or rows


- [#10490](#10490)
[`863f15ff2`](863f15f)
Thanks [@mrcthms](https://github.com/mrcthms)! - Add new
`IndexFiltersManager` for allowing disabling of Page Header actions when
in Filtering or EditingColumns mode


- [#10566](#10566)
[`9fed74317`](9fed743)
Thanks [@mrcthms](https://github.com/mrcthms)! - Fixed a bug in
`Filters` where changes to the `appliedFilters` prop were not being
handled

### Patch Changes

- [#10404](#10404)
[`5acfcec04`](5acfcec)
Thanks [@jesstelford](https://github.com/jesstelford)! - Scoped CSS
variables for non-responsive props on `Tooltip`, `RangeSlider`,
`ProgressBar`, and `HorizontalStack`.


- [#10582](#10582)
[`3efbc1b4e`](3efbc1b)
Thanks [@mrcthms](https://github.com/mrcthms)! - Fixed the focus states
of actions within the Page Header component


- [#10492](#10492)
[`d5ff72dec`](d5ff72d)
Thanks [@mrcthms](https://github.com/mrcthms)! - Updated Storybook
stories to be wrapped with an empty FrameContext.Provider

- Updated dependencies
\[[`fe1aac1b5`](fe1aac1),
[`790a001cd`](790a001),
[`63cf3ad24`](63cf3ad),
[`120e96eae`](120e96e)]:
    -   @shopify/[email protected]

## @shopify/[email protected]

### Minor Changes

- [#10465](#10465)
[`fe1aac1b5`](fe1aac1)
Thanks [@aaronccasanova](https://github.com/aaronccasanova)! - Updated
private primitive `colors`


- [#10477](#10477)
[`790a001cd`](790a001)
Thanks [@aaronccasanova](https://github.com/aaronccasanova)! - Updated
semantic `color` tokens


- [#10600](#10600)
[`63cf3ad24`](63cf3ad)
Thanks [@lgriffee](https://github.com/lgriffee)! - Added public
primitive and semantic `shadow` token scales

### Patch Changes

- [#10485](#10485)
[`120e96eae`](120e96e)
Thanks [@lgriffee](https://github.com/lgriffee)! - Updated public
primitive `base` and `light-uplift` theme scales

## @shopify/[email protected]

### Patch Changes

- [#10575](#10575)
[`ea6b54284`](ea6b542)
Thanks [@aveline](https://github.com/aveline)! - Handled `buttonFrom`
and `buttonsFrom` functions in `Button` migration

- Updated dependencies
\[[`fe1aac1b5`](fe1aac1),
[`790a001cd`](790a001),
[`63cf3ad24`](63cf3ad),
[`120e96eae`](120e96e)]:
    -   @shopify/[email protected]
    -   @shopify/[email protected]

## @shopify/[email protected]

### Patch Changes

- Updated dependencies
\[[`fe1aac1b5`](fe1aac1),
[`790a001cd`](790a001),
[`63cf3ad24`](63cf3ad),
[`120e96eae`](120e96e)]:
    -   @shopify/[email protected]

## [email protected]

### Patch Changes

- [#10605](#10605)
[`9748b0838`](9748b08)
Thanks [@laurkim](https://github.com/laurkim)! - Updated logic for
rendering `color` custom property previews in `TokenList`


- [#10573](#10573)
[`da09e0b8c`](da09e0b)
Thanks [@kyledurand](https://github.com/kyledurand)! - Updated copy url
to change browser url

- Updated dependencies
\[[`fe1aac1b5`](fe1aac1),
[`5acfcec04`](5acfcec),
[`790a001cd`](790a001),
[`8be227e0c`](8be227e),
[`63cf3ad24`](63cf3ad),
[`7be9c243a`](7be9c24),
[`863f15ff2`](863f15f),
[`3efbc1b4e`](3efbc1b),
[`d5ff72dec`](d5ff72d),
[`120e96eae`](120e96e),
[`9fed74317`](9fed743)]:
    -   @shopify/[email protected]
    -   @shopify/[email protected]

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
ascherkus pushed a commit to ascherkus/polaris that referenced this pull request Feb 19, 2025
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @shopify/[email protected]

### Minor Changes

- [Shopify#10477](Shopify#10477)
[`790a001cd`](Shopify@be6914d)
Thanks [@aaronccasanova](https://github.com/aaronccasanova)! - Updated
semantic `color` tokens


- [Shopify#10478](Shopify#10478)
[`8be227e0c`](Shopify@b588f20)
Thanks [@MaxCloutier](https://github.com/MaxCloutier)! - Added
`allowFiltering` prop on `ActionList`, and `filterActions` prop on Page
Header


- [Shopify#9445](Shopify#9445)
[`7be9c243a`](Shopify@4069237)
Thanks [@m4thieulavoie](https://github.com/m4thieulavoie)! - Added
support for subheaders and selection of a range of `IndexTable.Rows` --
See the [With
subheaders](https://polaris.shopify.com/components/tables/index-table)
example on polaris.shopify.com for how to properly configure
    -   `IndexTable.Row`
- Added support for setting the `indeterminate` value on the `selected`
prop
- Added the `selectionRange` prop to specify a range of other
consecutive, related rows selected when the row is selected
- Added the `rowType` prop to indicate the relationship or role of the
row's contents (defaults to `data`, `subheader` renders the row to look
and behave like the table header row)
Added support for setting accessibility attributes on `IndexTable.Cell`
    -   `IndexTable.Cell`
- Added the `as` prop to support rendering the cell as a `th` element if
it is serving as a subheading cell
- Added support for the `headers` attribute to manually associate all
headers when the cell is described by more than its column heading
- Added support for the `colSpan` attribute to specify the number of the
columns that the cell element should extend to
- Added support for the `scope` attribute to indicate whether the `th`
is a header for a column, row, or group of columns or rows


- [Shopify#10490](Shopify#10490)
[`863f15ff2`](Shopify@07246bc)
Thanks [@mrcthms](https://github.com/mrcthms)! - Add new
`IndexFiltersManager` for allowing disabling of Page Header actions when
in Filtering or EditingColumns mode


- [Shopify#10566](Shopify#10566)
[`9fed74317`](Shopify@3fb446f)
Thanks [@mrcthms](https://github.com/mrcthms)! - Fixed a bug in
`Filters` where changes to the `appliedFilters` prop were not being
handled

### Patch Changes

- [Shopify#10404](Shopify#10404)
[`5acfcec04`](Shopify@5cdd787)
Thanks [@jesstelford](https://github.com/jesstelford)! - Scoped CSS
variables for non-responsive props on `Tooltip`, `RangeSlider`,
`ProgressBar`, and `HorizontalStack`.


- [Shopify#10582](Shopify#10582)
[`3efbc1b4e`](Shopify@d47089b)
Thanks [@mrcthms](https://github.com/mrcthms)! - Fixed the focus states
of actions within the Page Header component


- [Shopify#10492](Shopify#10492)
[`d5ff72dec`](Shopify@8057862)
Thanks [@mrcthms](https://github.com/mrcthms)! - Updated Storybook
stories to be wrapped with an empty FrameContext.Provider

- Updated dependencies
\[[`fe1aac1b5`](Shopify@a4f7ed7),
[`790a001cd`](Shopify@be6914d),
[`63cf3ad24`](Shopify@d4e6bd4),
[`120e96eae`](Shopify@fe98b0b)]:
    -   @shopify/[email protected]

## @shopify/[email protected]

### Minor Changes

- [Shopify#10465](Shopify#10465)
[`fe1aac1b5`](Shopify@a4f7ed7)
Thanks [@aaronccasanova](https://github.com/aaronccasanova)! - Updated
private primitive `colors`


- [Shopify#10477](Shopify#10477)
[`790a001cd`](Shopify@be6914d)
Thanks [@aaronccasanova](https://github.com/aaronccasanova)! - Updated
semantic `color` tokens


- [Shopify#10600](Shopify#10600)
[`63cf3ad24`](Shopify@d4e6bd4)
Thanks [@lgriffee](https://github.com/lgriffee)! - Added public
primitive and semantic `shadow` token scales

### Patch Changes

- [Shopify#10485](Shopify#10485)
[`120e96eae`](Shopify@fe98b0b)
Thanks [@lgriffee](https://github.com/lgriffee)! - Updated public
primitive `base` and `light-uplift` theme scales

## @shopify/[email protected]

### Patch Changes

- [Shopify#10575](Shopify#10575)
[`ea6b54284`](Shopify@9761c8a)
Thanks [@aveline](https://github.com/aveline)! - Handled `buttonFrom`
and `buttonsFrom` functions in `Button` migration

- Updated dependencies
\[[`fe1aac1b5`](Shopify@a4f7ed7),
[`790a001cd`](Shopify@be6914d),
[`63cf3ad24`](Shopify@d4e6bd4),
[`120e96eae`](Shopify@fe98b0b)]:
    -   @shopify/[email protected]
    -   @shopify/[email protected]

## @shopify/[email protected]

### Patch Changes

- Updated dependencies
\[[`fe1aac1b5`](Shopify@a4f7ed7),
[`790a001cd`](Shopify@be6914d),
[`63cf3ad24`](Shopify@d4e6bd4),
[`120e96eae`](Shopify@fe98b0b)]:
    -   @shopify/[email protected]

## [email protected]

### Patch Changes

- [Shopify#10605](Shopify#10605)
[`9748b0838`](Shopify@a21aca4)
Thanks [@laurkim](https://github.com/laurkim)! - Updated logic for
rendering `color` custom property previews in `TokenList`


- [Shopify#10573](Shopify#10573)
[`da09e0b8c`](Shopify@439fedc)
Thanks [@kyledurand](https://github.com/kyledurand)! - Updated copy url
to change browser url

- Updated dependencies
\[[`fe1aac1b5`](Shopify@a4f7ed7),
[`5acfcec04`](Shopify@5cdd787),
[`790a001cd`](Shopify@be6914d),
[`8be227e0c`](Shopify@b588f20),
[`63cf3ad24`](Shopify@d4e6bd4),
[`7be9c243a`](Shopify@4069237),
[`863f15ff2`](Shopify@07246bc),
[`3efbc1b4e`](Shopify@d47089b),
[`d5ff72dec`](Shopify@8057862),
[`120e96eae`](Shopify@fe98b0b),
[`9fed74317`](Shopify@3fb446f)]:
    -   @shopify/[email protected]
    -   @shopify/[email protected]

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Non-responsive props break encapsulation for nested components

2 participants