Skip to content

Conversation

@atesgoral
Copy link
Contributor

@atesgoral atesgoral commented Sep 28, 2022

WHY are these changes introduced?

Because the default style selection is based on only the first letter of the name, there's little variance for cases where names in a given set may all start with the same letter (common to the language, variations within a set of names where only the suffix changes, etc.)

In Shopify Admin (both web and mobile), we are currently using the last letter of a shop's name to add colour variance to shops (e.g. when an organization may have multiple shops whose names start with the same letter).

WHAT is this pull request doing?

By using the entire name, there's more guarantee of variance. A very performant way to get a rudimentary hash out of a string is just xoring the character codes.

['Aba', 'Abb', 'Bba'].map(xorHash)
// [66, 65, 65]

🎩 checklist

@atesgoral atesgoral force-pushed the atesgoral/xor-hash-for-avatar-class branch from 5f4354b to 6c13c48 Compare September 28, 2022 17:35
return hash;
}

function styleClass(name?: string) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was no reason to define this function inside the component, so moved it out

@github-actions
Copy link
Contributor

github-actions bot commented Sep 28, 2022

size-limit report 📦

Path Size
polaris-react-cjs 202.88 KB (+0.01% 🔺)
polaris-react-esm 129.6 KB (+0.03% 🔺)
polaris-react-esnext 183.75 KB (+0.02% 🔺)
polaris-react-css 40.68 KB (0%)

@atesgoral atesgoral marked this pull request as ready for review September 28, 2022 18:51
@atesgoral atesgoral changed the title [WIP][Avatar] Improve default style class selection by using the entire name instead of just the first letter [Avatar] Improve default style class selection by using the entire name instead of just the first letter Sep 28, 2022
@atesgoral atesgoral requested a review from a team September 28, 2022 18:53
@atesgoral atesgoral force-pushed the atesgoral/xor-hash-for-avatar-class branch 2 times, most recently from b8f67ef to e11efbc Compare September 28, 2022 18:56
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 looks good to me just be sure that the mobile team is aware of the change as they'll have to make this change on their end as well

@mikegarfinkle

@atesgoral atesgoral force-pushed the atesgoral/xor-hash-for-avatar-class branch from e11efbc to 0caeb04 Compare September 29, 2022 14:35
@mikegarfinkle
Copy link
Contributor

@clarkjennings this will affect the styling approach you implemented here: https://github.com/Shopify/web/blame/main/app/foundation/Frame/components/AppSearch/components/Rows/Rows.tsx

The last letter will no longer be needed to passed to get different colors for cases of, for example, Shop USA and Shop CA. And now can just pass in the name. Does this change make sense to you? If so, once this merges, Rows.tsx can be modified?

@clarkjennings
Copy link
Contributor

@clarkjennings this will affect the styling approach you implemented here: https://github.com/Shopify/web/blame/main/app/foundation/Frame/components/AppSearch/components/Rows/Rows.tsx

The last letter will no longer be needed to passed to get different colors for cases of, for example, Shop USA and Shop CA. And now can just pass in the name. Does this change make sense to you? If so, once this merges, Rows.tsx can be modified?

This is great! 👍 🚀 I'll be happy to update my usage once this is released. Thanks!!!

@atesgoral atesgoral merged commit 3941f52 into main Oct 4, 2022
@atesgoral atesgoral deleted the atesgoral/xor-hash-for-avatar-class branch October 4, 2022 17:25
@github-actions github-actions bot mentioned this pull request Oct 4, 2022
mattkubej pushed a commit that referenced this pull request Oct 5, 2022
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

- [#7264](#7264)
[`5a1f45f7a`](5a1f45f)
Thanks [@lgriffee](https://github.com/lgriffee)! - Add sass padding and
margin migration

### Patch Changes

- [#7315](#7315)
[`c958899c7`](c958899)
Thanks [@lgriffee](https://github.com/lgriffee)! - Remove `0` and `0px`
length values from `replace-sass-lengths` migration

- Updated dependencies
\[[`0be40aa94`](0be40aa)]:
    -   @shopify/[email protected]

## @shopify/[email protected]

### Minor Changes

- [#7056](#7056)
[`0be40aa94`](0be40aa)
Thanks [@laurkim](https://github.com/laurkim)! - Added alpha `Inline`
component


- [#7056](#7056)
[`0be40aa94`](0be40aa)
Thanks [@laurkim](https://github.com/laurkim)! - Added `AlphaStack`
component


- [#7056](#7056)
[`0be40aa94`](0be40aa)
Thanks [@laurkim](https://github.com/laurkim)! - Added `Columns`
component


- [#7056](#7056)
[`0be40aa94`](0be40aa)
Thanks [@laurkim](https://github.com/laurkim)! - Added `Box` component


- [#7056](#7056)
[`0be40aa94`](0be40aa)
Thanks [@laurkim](https://github.com/laurkim)! - Added `AlphaCard`
component


- [#7056](#7056)
[`0be40aa94`](0be40aa)
Thanks [@laurkim](https://github.com/laurkim)! - Added `fullWidth` prop
to `AlphaStack` and updated styleguide docs


- [#7056](#7056)
[`0be40aa94`](0be40aa)
Thanks [@laurkim](https://github.com/laurkim)! - Added alpha
`ContentBlock` component

### Patch Changes

- [#7056](#7056)
[`0be40aa94`](0be40aa)
Thanks [@laurkim](https://github.com/laurkim)! - Updated `AlphaCard`
border radius to a boolean


- [#7056](#7056)
[`0be40aa94`](0be40aa)
Thanks [@laurkim](https://github.com/laurkim)! - Renamed `Columns`
spacing


- [#7056](#7056)
[`0be40aa94`](0be40aa)
Thanks [@laurkim](https://github.com/laurkim)! - Renamed `background`
prop on `AlphaCard` for consistency


- [#7056](#7056)
[`0be40aa94`](0be40aa)
Thanks [@laurkim](https://github.com/laurkim)! - Rename `Tiles`
component


- [#7056](#7056)
[`0be40aa94`](0be40aa)
Thanks [@laurkim](https://github.com/laurkim)! - Renamed `AlphaCard`
`shadow` prop


- [#7056](#7056)
[`0be40aa94`](0be40aa)
Thanks [@laurkim](https://github.com/laurkim)! - Refactored token types
in primitive Layout components
    Exposed `DepthShadowAlias` type


- [#7291](#7291)
[`3941f5281`](3941f52)
Thanks [@atesgoral](https://github.com/atesgoral)! - Improve default
style class selection of `Avatar` by using the entire name instead of
just the first letter


- [#7332](#7332)
[`2ee5c5d74`](2ee5c5d)
Thanks [@mattkubej](https://github.com/mattkubej)! - `PopoverOverlay`
closes focused `Popover` when pressing `Escape`

- Updated dependencies
\[[`0be40aa94`](0be40aa)]:
    -   @shopify/[email protected]

## @shopify/[email protected]

### Minor Changes

- [#7056](#7056)
[`0be40aa94`](0be40aa)
Thanks [@laurkim](https://github.com/laurkim)! - Refactored token types
in primitive Layout components
    Exposed `DepthShadowAlias` type

## @shopify/[email protected]

### Patch Changes

- Updated dependencies
\[[`5a1f45f7a`](5a1f45f),
[`c958899c7`](c958899)]:
    -   @shopify/[email protected]

## @shopify/[email protected]

### Patch Changes

- Updated dependencies
\[[`0be40aa94`](0be40aa)]:
    -   @shopify/[email protected]

## [email protected]

### Minor Changes

- [#7056](#7056)
[`0be40aa94`](0be40aa)
Thanks [@laurkim](https://github.com/laurkim)! - Added alpha pages for
`AlphaStack`, `Box`, `Columns`, `Inline`, and `Tile` components. Updated
`StatusBanner` to capitalize status value.


- [#7353](#7353)
[`558b1cfae`](558b1cf)
Thanks [@kyledurand](https://github.com/kyledurand)! - Ported
codesandbox init code to React 18


- [#7056](#7056)
[`0be40aa94`](0be40aa)
Thanks [@laurkim](https://github.com/laurkim)! - Added alpha page for
`ContentBlock`

### Patch Changes

- [#7056](#7056)
[`0be40aa94`](0be40aa)
Thanks [@laurkim](https://github.com/laurkim)! - Updated `AlphaCard`
border radius to a boolean


- [#7056](#7056)
[`0be40aa94`](0be40aa)
Thanks [@laurkim](https://github.com/laurkim)! - Renamed `Columns`
spacing


- [#7056](#7056)
[`0be40aa94`](0be40aa)
Thanks [@laurkim](https://github.com/laurkim)! - Renamed `background`
prop on `AlphaCard` for consistency


- [#7056](#7056)
[`0be40aa94`](0be40aa)
Thanks [@laurkim](https://github.com/laurkim)! - Rename `Tiles`
component


- [#7312](#7312)
[`2349db304`](2349db3)
Thanks [@martenbjork](https://github.com/martenbjork)! - Added a
redirect pointing to the Polaris license on Github


- [#7343](#7343)
[`7ced95bfb`](7ced95b)
Thanks [@laurkim](https://github.com/laurkim)! - Updated alpha `Box`
page to remove sentence regarding usage in existing components


- [#7056](#7056)
[`0be40aa94`](0be40aa)
Thanks [@laurkim](https://github.com/laurkim)! - Renamed `AlphaCard`
`shadow` prop


- [#7056](#7056)
[`0be40aa94`](0be40aa)
Thanks [@laurkim](https://github.com/laurkim)! - Added `fullWidth` prop
to `AlphaStack` and updated styleguide docs


- [#7311](#7311)
[`fc05e3152`](fc05e31)
Thanks [@martenbjork](https://github.com/martenbjork)! - Improved the
layout on mobile

- Updated dependencies
\[[`0be40aa94`](0be40aa),
[`0be40aa94`](0be40aa),
[`0be40aa94`](0be40aa),
[`0be40aa94`](0be40aa),
[`0be40aa94`](0be40aa),
[`0be40aa94`](0be40aa),
[`0be40aa94`](0be40aa),
[`0be40aa94`](0be40aa),
[`0be40aa94`](0be40aa),
[`0be40aa94`](0be40aa),
[`0be40aa94`](0be40aa),
[`0be40aa94`](0be40aa),
[`0be40aa94`](0be40aa),
[`3941f5281`](3941f52),
[`2ee5c5d74`](2ee5c5d)]:
    -   @shopify/[email protected]
    -   @shopify/[email protected]

## [email protected]

### Patch Changes

- Updated dependencies
\[[`0be40aa94`](0be40aa),
[`0be40aa94`](0be40aa),
[`0be40aa94`](0be40aa),
[`0be40aa94`](0be40aa),
[`0be40aa94`](0be40aa),
[`0be40aa94`](0be40aa),
[`0be40aa94`](0be40aa),
[`0be40aa94`](0be40aa),
[`0be40aa94`](0be40aa),
[`0be40aa94`](0be40aa),
[`0be40aa94`](0be40aa),
[`0be40aa94`](0be40aa),
[`0be40aa94`](0be40aa),
[`3941f5281`](3941f52),
[`2ee5c5d74`](2ee5c5d)]:
    -   @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.

4 participants