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

Replace <!-- colors --> with Colors MDX component #10401

Merged
merged 6 commits into from
Sep 12, 2023

Conversation

yurm04
Copy link
Contributor

@yurm04 yurm04 commented Sep 11, 2023

WHY are these changes introduced?

Fixes #10146

Screenshot 2023-09-11 at 4 16 37 PM

WHAT is this pull request doing?

Migrating the <!-- colors --> directive from makdown.mjs to MDX renderer

How to 🎩

  1. yarn run dev
  2. navigate to /design/colors
  3. The color palette should load on the page.

⚠️ The <h3> styling of the color titles doesn't currently match what's on prod. We'll fix this in a bigger sweep of styling regressions in a future PR

🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines

Copy-paste this code in playground/Playground.tsx:
import React from 'react';
import {Page} from '../src';

export function Playground() {
  return (
    <Page title="Playground">
      {/* Add the code you want to test in here */}
    </Page>
  );
}

🎩 checklist

@yurm04 yurm04 requested review from a team and jesstelford September 11, 2023 21:20
Comment on lines 3 to 15
.colors {
display: grid;
grid-template-columns: repeat(5, 1fr);
gap: var(--p-space-4);
margin-bottom: var(--p-space-8);
font-size: var(--font-size-75);
font-weight: var(--p-font-weight-semibold);

@media (min-width: $breakpointTablet) {
grid-template-columns: repeat(10, 1fr);
}

.colors-swatch {
Copy link
Contributor

Choose a reason for hiding this comment

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

Because this is a CSS Module, we should be able to export the classnames and use them in the JS rather than having global CSS classes:

Suggested change
.colors {
display: grid;
grid-template-columns: repeat(5, 1fr);
gap: var(--p-space-4);
margin-bottom: var(--p-space-8);
font-size: var(--font-size-75);
font-weight: var(--p-font-weight-semibold);
@media (min-width: $breakpointTablet) {
grid-template-columns: repeat(10, 1fr);
}
.colors-swatch {
.Colors {
display: grid;
grid-template-columns: repeat(5, 1fr);
gap: var(--p-space-4);
margin-bottom: var(--p-space-8);
font-size: var(--font-size-75);
font-weight: var(--p-font-weight-semibold);
@media (min-width: $breakpointTablet) {
grid-template-columns: repeat(10, 1fr);
}
.ColorsSwatch {

Comment on lines 3 to 45
import './Colors.module.scss';

type ColorScale = 50 | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;

type ColorValue = {
[index in ColorScale]: string;
};

interface Colors {
[key: string]: ColorValue;
}

const colors = colorsObj as unknown as Colors;

export function Colors() {
const colorOrder = [
'gray',
'green',
'teal',
'blue',
'purple',
'red',
'orange',
'yellow',
];

const colorMap = colorOrder.map((color) => {
const shades: ColorValue = colors[color] ?? [];
const swatches = Object.entries(shades)
.sort(([prevShade], [nextShade]) =>
Number(prevShade) < Number(nextShade) ? 1 : -1,
)
.map(([shade, value]) => (
<div key={value}>
<div className="colors-swatch" style={{backgroundColor: value}}></div>
<div>{shade}</div>
</div>
));

return (
<>
<h3>{capitalize(color)}</h3>
<div className="colors">{swatches}</div>
Copy link
Contributor

Choose a reason for hiding this comment

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

Using CSS modules:

Suggested change
import './Colors.module.scss';
type ColorScale = 50 | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;
type ColorValue = {
[index in ColorScale]: string;
};
interface Colors {
[key: string]: ColorValue;
}
const colors = colorsObj as unknown as Colors;
export function Colors() {
const colorOrder = [
'gray',
'green',
'teal',
'blue',
'purple',
'red',
'orange',
'yellow',
];
const colorMap = colorOrder.map((color) => {
const shades: ColorValue = colors[color] ?? [];
const swatches = Object.entries(shades)
.sort(([prevShade], [nextShade]) =>
Number(prevShade) < Number(nextShade) ? 1 : -1,
)
.map(([shade, value]) => (
<div key={value}>
<div className="colors-swatch" style={{backgroundColor: value}}></div>
<div>{shade}</div>
</div>
));
return (
<>
<h3>{capitalize(color)}</h3>
<div className="colors">{swatches}</div>
import styles from './Colors.module.scss';
type ColorScale = 50 | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;
type ColorValue = {
[index in ColorScale]: string;
};
interface Colors {
[key: string]: ColorValue;
}
const colors = colorsObj as unknown as Colors;
export function Colors() {
const colorOrder = [
'gray',
'green',
'teal',
'blue',
'purple',
'red',
'orange',
'yellow',
];
const colorMap = colorOrder.map((color) => {
const shades: ColorValue = colors[color] ?? [];
const swatches = Object.entries(shades)
.sort(([prevShade], [nextShade]) =>
Number(prevShade) < Number(nextShade) ? 1 : -1,
)
.map(([shade, value]) => (
<div key={value}>
<div className={styles.ColorsSwatch} style={{backgroundColor: value}}></div>
<div>{shade}</div>
</div>
));
return (
<>
<h3>{capitalize(color)}</h3>
<div className={styles.Colors}>{swatches}</div>

@@ -0,0 +1,29 @@
@import '../../../../styles/variables.scss';

.colors {
Copy link
Contributor

Choose a reason for hiding this comment

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

We can now delete the related styles from polaris.shopify.com/src/styles/globals.scss 🎉

Copy link
Contributor

@jesstelford jesstelford left a comment

Choose a reason for hiding this comment

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

Looks like the swatch headings aren't getting the correct styles because they're defined in JSX instead of markdown:

Local:
Screenshot 2023-09-12 at 11 52 43 am

Prod:
Screenshot 2023-09-12 at 11 52 37 am

I have a solution in mind which I'll try now.

Copy link
Contributor

@jesstelford jesstelford left a comment

Choose a reason for hiding this comment

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

I've pushed up 3 new commits:

  • Cleanup unused global styles
  • Use CSS modules
  • Push Color scale rendering down to MDX

The third one is the biggest, and it's designed to fix the unstyled / unlinked heading problem. Basically I just uncoupled the heading/scale rendering (and replaced div with Box).

@yurm04
Copy link
Contributor Author

yurm04 commented Sep 12, 2023

@jesstelford your changes look good overall, but I'm going to drop the last commit where you refactor to move more things to mdx. @tjonx is going to take a look at enhancing the existing color palette to be more interactive. I think the JSX approach makes this slightly easier since the new version will probably need to be a single, all-encompassing component that can handle component state for the interactivity.

If we're not able to go the interactive component route, let's pull your refactor back in in a separate PR as i do think it's the better approach

@yurm04 yurm04 merged commit f16ea4a into next Sep 12, 2023
6 checks passed
@yurm04 yurm04 deleted the ye/markdown-color-component branch September 12, 2023 15:58
sophschneider pushed a commit that referenced this pull request Sep 19, 2023
<!--
  ☝️How to write a good PR title:
- Prefix it with [ComponentName] (if applicable), for example: [Button]
  - Start with a verb, for example: Add, Delete, Improve, Fix…
  - Give as much context as necessary and as little as possible
  - Prefix it with [WIP] while it’s a work in progress
-->


### WHY are these changes introduced?

Fixes #10146 <!-- link to issue
if one exists -->

<img width="2032" alt="Screenshot 2023-09-11 at 4 16 37 PM"
src="https://github.com/Shopify/polaris/assets/4642404/f4f7865b-4d01-47ea-87b4-efc38d7c0585">

<!--
  Context about the problem that’s being addressed.
-->

### WHAT is this pull request doing?

Migrating the `<!-- colors -->` directive from `makdown.mjs` to MDX
renderer

<!--
  Summary of the changes committed.

Before / after screenshots are appreciated for UI changes. Make sure to
include alt text that describes the screenshot.

If you include an animated gif showing your change, wrapping it in a
details tag is recommended. Gifs usually autoplay, which can cause
accessibility issues for people reviewing your PR:

    <details>
      <summary>Summary of your gif(s)</summary>
      <img src="..." alt="Description of what the gif shows">
    </details>
-->

<!-- ℹ️ Delete the following for small / trivial changes -->

### How to 🎩
1. `yarn run dev`
2. navigate to [`/design/colors`](http://localhost:3000/design/colors)
3.  The color palette should load on the page. 

⚠️ The `<h3>` styling of the color titles doesn't currently match what's
on prod. We'll fix this in a bigger sweep of styling regressions in a
future PR

🖥 [Local development
instructions](https://github.com/Shopify/polaris/blob/main/README.md#local-development)
🗒 [General tophatting
guidelines](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md)
📄 [Changelog
guidelines](https://github.com/Shopify/polaris/blob/main/.github/CONTRIBUTING.md#changelog)

<!--
  Give as much information as needed to experiment with the component
  in the playground.
-->

<details>
<summary>Copy-paste this code in
<code>playground/Playground.tsx</code>:</summary>

```jsx
import React from 'react';
import {Page} from '../src';

export function Playground() {
  return (
    <Page title="Playground">
      {/* Add the code you want to test in here */}
    </Page>
  );
}
```

</details>

### 🎩 checklist

- [ ] Tested on
[mobile](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md#cross-browser-testing)
- [ ] Tested on [multiple
browsers](https://help.shopify.com/en/manual/shopify-admin/supported-browsers)
- [ ] Tested for
[accessibility](https://github.com/Shopify/polaris/blob/main/documentation/Accessibility%20testing.md)
- [ ] Updated the component's `README.md` with documentation changes
- [ ] [Tophatted
documentation](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting%20documentation.md)
changes in the style guide

---------

Co-authored-by: Jess Telford <jess.telford@shopify.com>
AnnaCheba pushed a commit to AnnaCheba/polaris that referenced this pull request Apr 22, 2024
<!--
  ☝️How to write a good PR title:
- Prefix it with [ComponentName] (if applicable), for example: [Button]
  - Start with a verb, for example: Add, Delete, Improve, Fix…
  - Give as much context as necessary and as little as possible
  - Prefix it with [WIP] while it’s a work in progress
-->


### WHY are these changes introduced?

Fixes Shopify#10146 <!-- link to issue
if one exists -->

<img width="2032" alt="Screenshot 2023-09-11 at 4 16 37 PM"
src="https://github.com/Shopify/polaris/assets/4642404/f4f7865b-4d01-47ea-87b4-efc38d7c0585">

<!--
  Context about the problem that’s being addressed.
-->

### WHAT is this pull request doing?

Migrating the `<!-- colors -->` directive from `makdown.mjs` to MDX
renderer

<!--
  Summary of the changes committed.

Before / after screenshots are appreciated for UI changes. Make sure to
include alt text that describes the screenshot.

If you include an animated gif showing your change, wrapping it in a
details tag is recommended. Gifs usually autoplay, which can cause
accessibility issues for people reviewing your PR:

    <details>
      <summary>Summary of your gif(s)</summary>
      <img src="..." alt="Description of what the gif shows">
    </details>
-->

<!-- ℹ️ Delete the following for small / trivial changes -->

### How to 🎩
1. `yarn run dev`
2. navigate to [`/design/colors`](http://localhost:3000/design/colors)
3.  The color palette should load on the page. 

⚠️ The `<h3>` styling of the color titles doesn't currently match what's
on prod. We'll fix this in a bigger sweep of styling regressions in a
future PR

🖥 [Local development
instructions](https://github.com/Shopify/polaris/blob/main/README.md#local-development)
🗒 [General tophatting
guidelines](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md)
📄 [Changelog
guidelines](https://github.com/Shopify/polaris/blob/main/.github/CONTRIBUTING.md#changelog)

<!--
  Give as much information as needed to experiment with the component
  in the playground.
-->

<details>
<summary>Copy-paste this code in
<code>playground/Playground.tsx</code>:</summary>

```jsx
import React from 'react';
import {Page} from '../src';

export function Playground() {
  return (
    <Page title="Playground">
      {/* Add the code you want to test in here */}
    </Page>
  );
}
```

</details>

### 🎩 checklist

- [ ] Tested on
[mobile](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md#cross-browser-testing)
- [ ] Tested on [multiple
browsers](https://help.shopify.com/en/manual/shopify-admin/supported-browsers)
- [ ] Tested for
[accessibility](https://github.com/Shopify/polaris/blob/main/documentation/Accessibility%20testing.md)
- [ ] Updated the component's `README.md` with documentation changes
- [ ] [Tophatted
documentation](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting%20documentation.md)
changes in the style guide

---------

Co-authored-by: Jess Telford <jess.telford@shopify.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.

2 participants