Skip to content

Commit

Permalink
Add variant prop to Layout.Section (#10041)
Browse files Browse the repository at this point in the history
<!--
  ☝️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 #9982
<!--
  Context about the problem that’s being addressed.
-->

### WHAT is this pull request doing?

Replaces boolean props on Layout.Section and replaces them with
`variant` prop

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

### How to 🎩
  • Loading branch information
kyledurand committed Aug 17, 2023
1 parent 045566d commit 6e5fff5
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 45 deletions.
5 changes: 5 additions & 0 deletions .changeset/silly-ligers-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/polaris': major
---

Replaced boolean props: `secondary`, `fullWidth`, `oneHalf`, `oneThird` on Layout.Section with `variant`
31 changes: 31 additions & 0 deletions documentation/guides/migrating-from-v11-to-v12.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Migrating from v11 to v12

Polaris v12.0.0 ([full release notes](https://github.com/Shopify/polaris/releases/tag/v12.0.0)) prop replacement, removal of components, renamed components, and token changes.

## Table of Contents

- [Quick migration guide](#quick-migration-guide)

## Quick migration guide

**Layout.Section**

One third:

`npx @shopify/polaris-migrator react-rename-component-prop <path> --componentName="Layout.Section" --from="oneThird" --to="variant" --newValue="oneThird"`

One half:

`npx @shopify/polaris-migrator react-rename-component-prop <path> --componentName="Layout.Section" --from="oneHalf" --to="variant" --newValue="oneHalf"`

Full width:

`npx @shopify/polaris-migrator react-rename-component-prop <path> --componentName="Layout.Section" --from="fullWidth" --to="variant" --newValue="fullWidth"`

Secondary, becomes oneThird:

`npx @shopify/polaris-migrator react-rename-component-prop <path> --componentName="Layout.Section" --from="secondary" --to="variant" --newValue="oneThird"`

**TextField**

`npx @shopify/polaris-migrator react-rename-component-prop <path> --componentName="TextField" --from="borderless" --to="variant" --newValue="borderless"`
2 changes: 1 addition & 1 deletion polaris-react/playground/DetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ export function DetailsPage() {
</DropZone>
</LegacyCard>
</Layout.Section>
<Layout.Section secondary>
<Layout.Section variant="oneThird">
<LegacyCard title="Organization">
<LegacyCard.Section>
<Select
Expand Down
5 changes: 0 additions & 5 deletions polaris-react/src/components/Layout/Layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ $relative-size: $primary-basis / $secondary-basis;
}
}

.Section-secondary {
flex: 1 1 $secondary-basis;
min-width: 0;
}

.Section-fullWidth {
flex: 1 1 100%;
}
Expand Down
12 changes: 6 additions & 6 deletions polaris-react/src/components/Layout/Layout.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function TwoColumnsWithPrimaryAndSecondaryWidths() {
</p>
</LegacyCard>
</Layout.Section>
<Layout.Section secondary>
<Layout.Section variant="oneThird">
<LegacyCard title="Tags" sectioned>
<p>Add tags to your order.</p>
</LegacyCard>
Expand All @@ -102,7 +102,7 @@ export function TwoColumnsWithEqualWidth() {
return (
<Page fullWidth>
<Layout>
<Layout.Section oneHalf>
<Layout.Section variant="oneHalf">
<LegacyCard title="Florida" actions={[{content: 'Manage'}]}>
<LegacyCard.Section>
<Text color="subdued" as="span">
Expand Down Expand Up @@ -164,7 +164,7 @@ export function TwoColumnsWithEqualWidth() {
</LegacyCard.Section>
</LegacyCard>
</Layout.Section>
<Layout.Section oneHalf>
<Layout.Section variant="oneHalf">
<LegacyCard title="Nevada" actions={[{content: 'Manage'}]}>
<LegacyCard.Section>
<Text color="subdued" as="span">
Expand Down Expand Up @@ -235,7 +235,7 @@ export function ThreeColumnsWithEqualWidth() {
return (
<Page fullWidth>
<Layout>
<Layout.Section oneThird>
<Layout.Section variant="oneThird">
<LegacyCard title="Florida" actions={[{content: 'Manage'}]}>
<LegacyCard.Section>
<Text color="subdued" as="span">
Expand Down Expand Up @@ -297,7 +297,7 @@ export function ThreeColumnsWithEqualWidth() {
</LegacyCard.Section>
</LegacyCard>
</Layout.Section>
<Layout.Section oneThird>
<Layout.Section variant="oneThird">
<LegacyCard title="Nevada" actions={[{content: 'Manage'}]}>
<LegacyCard.Section>
<Text color="subdued" as="span">
Expand Down Expand Up @@ -359,7 +359,7 @@ export function ThreeColumnsWithEqualWidth() {
</LegacyCard.Section>
</LegacyCard>
</Layout.Section>
<Layout.Section oneThird>
<Layout.Section variant="oneThird">
<LegacyCard title="Minneapolis" actions={[{content: 'Manage'}]}>
<LegacyCard.Section>
<Text color="subdued" as="span">
Expand Down
21 changes: 3 additions & 18 deletions polaris-react/src/components/Layout/components/Section/Section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,11 @@ import styles from '../../Layout.scss';

export interface SectionProps {
children?: React.ReactNode;
secondary?: boolean;
fullWidth?: boolean;
oneHalf?: boolean;
oneThird?: boolean;
variant?: 'oneHalf' | 'oneThird' | 'fullWidth';
}

export function Section({
children,
secondary,
fullWidth,
oneHalf,
oneThird,
}: SectionProps) {
const className = classNames(
styles.Section,
secondary && styles['Section-secondary'],
fullWidth && styles['Section-fullWidth'],
oneHalf && styles['Section-oneHalf'],
oneThird && styles['Section-oneThird'],
);
export function Section({children, variant}: SectionProps) {
const className = classNames(styles.Section, styles[`Section-${variant}`]);

return <div className={className}>{children}</div>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function WithDynamicContent() {
</TextContainer>
</LegacyCard>
</Layout.Section>
<Layout.Section secondary>
<Layout.Section variant="oneThird">
<LegacyCard>
<LegacyCard.Section>
<TextContainer>
Expand Down Expand Up @@ -78,7 +78,7 @@ export function WithStaticContent() {
<SkeletonBodyText />
</LegacyCard>
</Layout.Section>
<Layout.Section secondary>
<Layout.Section variant="oneThird">
<LegacyCard title="Sales channels">
<LegacyCard.Section>
<SkeletonBodyText lines={2} />
Expand Down Expand Up @@ -122,7 +122,7 @@ export function WithNarrowWidth() {
</TextContainer>
</LegacyCard>
</Layout.Section>
<Layout.Section secondary>
<Layout.Section variant="oneThird">
<LegacyCard>
<LegacyCard.Section>
<TextContainer>
Expand Down Expand Up @@ -172,7 +172,7 @@ export function WithFullWidth() {
</TextContainer>
</LegacyCard>
</Layout.Section>
<Layout.Section secondary>
<Layout.Section variant="oneThird">
<LegacyCard>
<LegacyCard.Section>
<TextContainer>
Expand Down Expand Up @@ -222,7 +222,7 @@ export function WithBackAction() {
</TextContainer>
</LegacyCard>
</Layout.Section>
<Layout.Section secondary>
<Layout.Section variant="oneThird">
<LegacyCard>
<LegacyCard.Section>
<TextContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function LayoutExample() {
return (
<Page fullWidth>
<Layout>
<Layout.Section oneThird>
<Layout.Section variant="oneThird">
<div style={{marginTop: 'var(--p-space-5)'}}>
<TextContainer>
<Text id="storeDetails" variant="headingMd" as="h2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function LayoutExample() {
return (
<Page fullWidth>
<Layout>
<Layout.Section oneThird>
<Layout.Section variant="oneThird">
<LegacyCard title="Florida" actions={[{content: 'Manage'}]}>
<LegacyCard.Section>
<Text color="subdued" as="span">
Expand Down Expand Up @@ -73,7 +73,7 @@ function LayoutExample() {
</LegacyCard.Section>
</LegacyCard>
</Layout.Section>
<Layout.Section oneThird>
<Layout.Section variant="oneThird">
<LegacyCard title="Nevada" actions={[{content: 'Manage'}]}>
<LegacyCard.Section>
<Text color="subdued" as="span">
Expand Down Expand Up @@ -133,7 +133,7 @@ function LayoutExample() {
</LegacyCard.Section>
</LegacyCard>
</Layout.Section>
<Layout.Section oneThird>
<Layout.Section variant="oneThird">
<LegacyCard title="Minneapolis" actions={[{content: 'Manage'}]}>
<LegacyCard.Section>
<Text color="subdued" as="span">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function LayoutExample() {
return (
<Page fullWidth>
<Layout>
<Layout.Section oneHalf>
<Layout.Section variant="oneHalf">
<LegacyCard title="Florida" actions={[{content: 'Manage'}]}>
<LegacyCard.Section>
<Text color="subdued" as="span">
Expand Down Expand Up @@ -73,7 +73,7 @@ function LayoutExample() {
</LegacyCard.Section>
</LegacyCard>
</Layout.Section>
<Layout.Section oneHalf>
<Layout.Section variant="oneHalf">
<LegacyCard title="Nevada" actions={[{content: 'Manage'}]}>
<LegacyCard.Section>
<Text color="subdued" as="span">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function LayoutExample() {
</p>
</LegacyCard>
</Layout.Section>
<Layout.Section secondary>
<Layout.Section variant="oneThird">
<LegacyCard title="Tags" sectioned>
<p>Add tags to your order.</p>
</LegacyCard>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function SkeletonExample() {
</TextContainer>
</LegacyCard>
</Layout.Section>
<Layout.Section secondary>
<Layout.Section variant="oneThird">
<LegacyCard>
<LegacyCard.Section>
<TextContainer>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import {SkeletonPage, Layout, LegacyCard, SkeletonBodyText} from '@shopify/polaris';
import {
SkeletonPage,
Layout,
LegacyCard,
SkeletonBodyText,
} from '@shopify/polaris';
import React from 'react';
import {withPolarisExample} from '../../src/components/PolarisExampleWrapper';

Expand All @@ -17,7 +22,7 @@ function SkeletonExample() {
<SkeletonBodyText />
</LegacyCard>
</Layout.Section>
<Layout.Section secondary>
<Layout.Section variant="oneThird">
<LegacyCard title="Sales channels">
<LegacyCard.Section>
<SkeletonBodyText lines={2} />
Expand Down

0 comments on commit 6e5fff5

Please sign in to comment.