### Install and Run Development Server Source: https://github.com/shopify/polaris-react/blob/main/polaris.shopify.com/README.md Use these commands to install dependencies and start the development server for the project. ```bash pnpm pnpm dev ``` -------------------------------- ### Install Dependencies and Build Packages Source: https://github.com/shopify/polaris-react/blob/main/polaris-for-vscode/CONTRIBUTING.md Run these commands to install all project dependencies and build the necessary packages before starting development. ```sh pnpm install pnpm build ``` -------------------------------- ### Component Example Structure Source: https://github.com/shopify/polaris-react/blob/main/documentation/Component READMEs.md List component examples under the 'Examples' section, providing a description for each example before the code block. ```markdown --- ## Examples ### First example Example description. ```jsx ``` ``` -------------------------------- ### Manual Token Migration Example Source: https://github.com/shopify/polaris-react/blob/main/documentation/guides/migrating-from-v10-to-v11.md This example shows how to stage and format files after performing manual token migrations. ```sh # Stage all manually migrated files git add . # Format staged files only git diff --staged --name-only | xargs npx prettier --write # Commit manual migrations git commit -m "Manually migrate X custom properties from Polaris v10 to v11" ``` -------------------------------- ### Migrate HorizontalGrid to InlineGrid example Source: https://github.com/shopify/polaris-react/blob/main/polaris.shopify.com/content/version-guides/migrating-from-v11-to-v12.mdx Example demonstrating the renaming of the `HorizontalGrid` component to `InlineGrid`. ```diff - + ``` -------------------------------- ### Migrate List spacing prop example Source: https://github.com/shopify/polaris-react/blob/main/polaris.shopify.com/content/version-guides/migrating-from-v11-to-v12.mdx Example demonstrating the migration of the `spacing` prop to `gap` on `List`. ```diff - + ``` -------------------------------- ### Migrate Layout.Section fullWidth prop example Source: https://github.com/shopify/polaris-react/blob/main/polaris.shopify.com/content/version-guides/migrating-from-v11-to-v12.mdx Example demonstrating the migration of the `fullWidth` prop to `variant="fullWidth"` on `Layout.Section`. ```diff - + ``` -------------------------------- ### Migrate HorizontalStack to InlineStack example Source: https://github.com/shopify/polaris-react/blob/main/polaris.shopify.com/content/version-guides/migrating-from-v11-to-v12.mdx Example demonstrating the renaming of the `HorizontalStack` component to `InlineStack`. ```diff - + ``` -------------------------------- ### Migrate DescriptionList spacing prop example Source: https://github.com/shopify/polaris-react/blob/main/polaris.shopify.com/content/version-guides/migrating-from-v11-to-v12.mdx Example demonstrating the migration of the `spacing` prop to `gap` for the DescriptionList component. ```diff - + ``` -------------------------------- ### Migrate Layout.Section oneHalf prop example Source: https://github.com/shopify/polaris-react/blob/main/polaris.shopify.com/content/version-guides/migrating-from-v11-to-v12.mdx Example demonstrating the migration of the `oneHalf` prop to `variant="oneHalf"` on `Layout.Section`. ```diff - + ``` -------------------------------- ### Restricting Example to Platforms Source: https://github.com/shopify/polaris-react/blob/main/documentation/Component READMEs.md This example demonstrates how to include a React component without platform-specific restrictions. ```jsx ``` -------------------------------- ### Install Dependencies and Build Workspaces Source: https://github.com/shopify/polaris-react/blob/main/README.md This command installs all project dependencies and builds all workspaces within the monorepo. It requires pnpm to be installed. ```shell pnpm install && pnpm build ``` -------------------------------- ### Automated Token Migration Example Source: https://github.com/shopify/polaris-react/blob/main/documentation/guides/migrating-from-v10-to-v11.md This example demonstrates the steps for automated token migration, including staging files, formatting, and committing changes. ```sh # Example migration npx @shopify/polaris-migrator ... # Stage all migrated files git add . # Format staged files only git diff --staged --name-only | xargs npx prettier --write # Commit automated migrations git commit -m "Migrate X custom properties from Polaris v10 to v11" ``` -------------------------------- ### Migrate Layout.Section oneThird prop example Source: https://github.com/shopify/polaris-react/blob/main/polaris.shopify.com/content/version-guides/migrating-from-v11-to-v12.mdx Example demonstrating the migration of the `oneThird` prop to `variant="oneThird"` on `Layout.Section`. ```diff - + ``` -------------------------------- ### Install @shopify/polaris-icons with npm Source: https://github.com/shopify/polaris-react/blob/main/polaris-icons/README.md Install the @shopify/polaris-icons package as a dependency using npm. ```bash npm install @shopify/polaris-icons --save ``` -------------------------------- ### Install @shopify/polaris-icons with Yarn Source: https://github.com/shopify/polaris-react/blob/main/polaris-icons/README.md Install the @shopify/polaris-icons package as a dependency using Yarn. ```bash yarn add @shopify/polaris-icons ``` -------------------------------- ### Migrate Layout.Section secondary prop example Source: https://github.com/shopify/polaris-react/blob/main/polaris.shopify.com/content/version-guides/migrating-from-v11-to-v12.mdx Example demonstrating the migration of the `secondary` prop to `variant="oneThird"` on `Layout.Section`. ```diff - + ``` -------------------------------- ### Example Linter Output Source: https://github.com/shopify/polaris-react/blob/main/stylelint-polaris/plugins/media-query-allowed-list/README.md Example output from Stylelint indicating invalid media queries found in a SCSS file. ```text src/components/typography/textContainer/TextContainer.scss 4:3 ✖ Invalid media query [(min-width: 0px)]. polaris/media-query-allowed-list 6:5 ✖ Invalid media query [print and (min-width: 0px)]. polaris/media-query-allowed-list ``` -------------------------------- ### Migrate ButtonGroup spacing prop example Source: https://github.com/shopify/polaris-react/blob/main/polaris.shopify.com/content/version-guides/migrating-from-v11-to-v12.mdx Example demonstrating the migration of the `spacing` prop to `gap` for the ButtonGroup component. ```diff - + ``` -------------------------------- ### Stylelint Configuration Example Source: https://github.com/shopify/polaris-react/blob/main/stylelint-polaris/plugins/media-query-allowed-list/README.md Example configuration for the 'polaris/media-query-allowed-list' rule in Stylelint, specifying allowed media types, feature names, and SCSS interpolations. ```javascript const stylelintConfig = { rules: { 'polaris/media-query-allowed-list': { allowedMediaTypes: ['print'], allowedMediaFeatureNames: ['forced-colors', 'reduced-motion'], allowedScssInterpolations: [ '$p-breakpoints-sm-up', '$p-breakpoints-md-up', ], }, }, }; ``` -------------------------------- ### Recommended Component Migration Workflow Source: https://github.com/shopify/polaris-react/blob/main/documentation/guides/migrating-from-v10-to-v11.md Example commands for handling automated and manual migrations using git and prettier. ```sh # Example migration npx @shopify/polaris-migrator ... # Stash files with "polaris-migrator:" comments git stash push $(grep -r -l "polaris-migrator:" $(git ls-files -m)) # Stage all migrated files without "polaris-migrator:" comments git add . # Format staged files only git diff --staged --name-only | xargs npx prettier --write # Commit automated migrations git commit -m "Migrate X to Y" ``` ```sh # Bring back the files with "polaris-migrator:" comments git stash pop ``` ```sh # Stage all manually migrated files git add . # Format staged files only git diff --staged --name-only | xargs npx prettier --write # Commit manual migrations git commit -m "Manually migrate X to Y" ``` -------------------------------- ### Migrate IndexTable.Row subdued prop example Source: https://github.com/shopify/polaris-react/blob/main/polaris.shopify.com/content/version-guides/migrating-from-v11-to-v12.mdx Example demonstrating the migration of the `subdued` prop to `tone` on `IndexTable.Row`. ```diff - + ``` -------------------------------- ### Install Polaris v12 Source: https://github.com/shopify/polaris-react/blob/main/polaris.shopify.com/content/version-guides/migrating-from-v11-to-v12.mdx Install the latest version of Polaris using npm or yarn. ```bash npm install @shopify/polaris@12 # or yarn add @shopify/polaris@12 ``` -------------------------------- ### Install @shopify/polaris-tokens Source: https://github.com/shopify/polaris-react/blob/main/polaris-tokens/README.md Use npm to install the Polaris tokens package. This command should be run in your project's root directory. ```bash npm install @shopify/polaris-tokens ``` -------------------------------- ### Migration example: Text color prop Source: https://github.com/shopify/polaris-react/blob/main/polaris.shopify.com/content/version-guides/migrating-from-v11-to-v12.mdx Example showing the direct code change from using the `color` prop to the `tone` prop on the Text component. ```diff - + ``` -------------------------------- ### Fixing Missing Section Separator Source: https://github.com/shopify/polaris-react/blob/main/documentation/Component READMEs.md Add a '---' before the '## Examples' heading to ensure correct parsing of the examples section. ```diff + --- + ## Examples ``` -------------------------------- ### Migration example: Rename VerticalStack to BlockStack Source: https://github.com/shopify/polaris-react/blob/main/polaris.shopify.com/content/version-guides/migrating-from-v11-to-v12.mdx Example showing the direct code change from using the `VerticalStack` component to `BlockStack`. ```diff - + ``` -------------------------------- ### Resource Index Layout Example Source: https://github.com/shopify/polaris-react/blob/main/polaris.shopify.com/content/patterns/resource-index-layout/variants/default.mdx This example demonstrates a comprehensive resource index layout using multiple Polaris React components. It includes state management for filters, tabs, and search queries, showcasing interactive features like creating, renaming, duplicating, and deleting views. ```javascript function IndexFiltersDefault() { function disambiguateLabel(key, value) { switch (key) { case 'type': return value.map((val) => `type: ${val}`).join(', '); case 'tone': return value.map((val) => `tone: ${val}`).join(', '); default: return value; } } function isEmpty(value) { if (Array.isArray(value)) { return value.length === 0; } else { return value === '' || value == null; } } const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); const [itemStrings, setItemStrings] = useState([ 'All', 'Active', 'Draft', 'Archived', ]); const deleteView = (index) => { const newItemStrings = [...itemStrings]; newItemStrings.splice(index, 1); setItemStrings(newItemStrings); setSelected(0); }; const duplicateView = async (name) => { setItemStrings([...itemStrings, name]); setSelected(itemStrings.length); await sleep(1); return true; }; const tabs = itemStrings.map((item, index) => ({ content: item, index, onAction: () => {}, id: `${item}-${index}`, isLocked: index === 0, actions: index === 0 ? [] : [ { type: 'rename', onAction: () => {}, onPrimaryAction: async (value) => { const newItemsStrings = tabs.map((item, idx) => { if (idx === index) { return value; } return item.content; }); await sleep(1); setItemStrings(newItemsStrings); return true; }, }, { type: 'duplicate', onPrimaryAction: async (name) => { await sleep(1); duplicateView(name); return true; }, }, { type: 'edit', }, { type: 'delete', onPrimaryAction: async () => { await sleep(1); deleteView(index); return true; }, }, ], })); const [selected, setSelected] = useState(0); const onCreateNewView = async (value) => { await sleep(500); setItemStrings([...itemStrings, value]); setSelected(itemStrings.length); return true; }; const sortOptions = [ {label: 'Product', value: 'product asc', directionLabel: 'Ascending'}, {label: 'Product', value: 'product desc', directionLabel: 'Descending'}, {label: 'Status', value: 'tone asc', directionLabel: 'A-Z'}, {label: 'Status', value: 'tone desc', directionLabel: 'Z-A'}, {label: 'Type', value: 'type asc', directionLabel: 'A-Z'}, {label: 'Type', value: 'type desc', directionLabel: 'Z-A'}, {label: 'Vendor', value: 'vendor asc', directionLabel: 'Ascending'}, {label: 'Vendor', value: 'vendor desc', directionLabel: 'Descending'}, ]; const [sortSelected, setSortSelected] = useState(['product asc']); const {mode, setMode} = useSetIndexFiltersMode(); const onHandleCancel = () => {}; const onHandleSave = async () => { await sleep(1); return true; }; const primaryAction = selected === 0 ? { type: 'save-as', onAction: onCreateNewView, disabled: false, loading: false, } : { type: 'save', onAction: onHandleSave, disabled: false, loading: false, }; const [tone, setStatus] = useState(undefined); const [type, setType] = useState(undefined); const [queryValue, setQueryValue] = useState(''); const handleStatusChange = useCallback((value) => setStatus(value), []); const handleTypeChange = useCallback((value) => setType(value), []); const handleFiltersQueryChange = useCallback( (value) => setQueryValue(value), [], ); const handleStatusRemove = useCallback(() => setStatus(undefined), []); const handleTypeRemove = useCallback(() => setType(undefined), []); const handleQueryValueRemove = useCallback(() => setQueryValue(''), []); const handleFiltersClearAll = useCallback(() => { handleStatusRemove(); handleTypeRemove(); handleQueryValueRemove(); }, []); return ( Product 1 Active Digital Super Store Product 2 Draft Local Store Local Store Product 3 Archived Best Buy Best Buy ); } ``` -------------------------------- ### Migration example: TextField borderless prop Source: https://github.com/shopify/polaris-react/blob/main/polaris.shopify.com/content/version-guides/migrating-from-v11-to-v12.mdx Example showing the direct code change from using the `borderless` prop to `variant="borderless"` on the TextField component. ```diff - + ``` -------------------------------- ### Default FooterHelp example Source: https://github.com/shopify/polaris-react/blob/main/polaris.shopify.com/content/components/navigation/footer-help.mdx Use to direct merchants to more information related to the product or feature they’re working on. This example shows the default usage. ```tsx import {FooterHelp} from "@shopify/polaris"; function MyComponent() { return ( Learn more about{' '} shipping zones ); } ``` -------------------------------- ### Resource Details Layout Example Source: https://github.com/shopify/polaris-react/blob/main/polaris.shopify.com/content/patterns/resource-details-layout/variants/default.mdx This example demonstrates the Resource Details Layout pattern, showcasing how to arrange content within cards and grids for a product details page. It utilizes various Polaris components to create a structured and responsive layout. ```javascript function ResourceDetailsLayout() { const SkeletonLabel = (props) => { return ( ); }; return ( alert('Duplicate action'), }, { content: 'Archive', icon: ArchiveIcon, accessibilityLabel: 'Secondary action label', onAction: () => alert('Archive action'), }, { content: 'Delete', icon: DeleteIcon, destructive: true, accessibilityLabel: 'Secondary action label', onAction: () => alert('Delete action'), }, ]} pagination={{ hasPrevious: true, hasNext: true, }} > ); } ``` -------------------------------- ### Install Stylelint Polaris Source: https://github.com/shopify/polaris-react/blob/main/polaris.shopify.com/content/tools/stylelint-polaris.mdx Install the necessary packages for Stylelint Polaris. This includes the main package and Stylelint itself as a development dependency. ```sh yarn add -D @shopify/stylelint-polaris stylelint ``` -------------------------------- ### Migrate Icon color to tone Source: https://github.com/shopify/polaris-react/blob/main/polaris.shopify.com/content/version-guides/migrating-from-v11-to-v12.mdx Example showing the migration of an Icon component from a `color` prop to a `tone` prop. ```diff - + ``` -------------------------------- ### Stylelint Output Example Source: https://github.com/shopify/polaris-react/blob/main/stylelint-polaris/plugins/custom-property-allowed-list/README.md Example output from Stylelint indicating violations of the custom property allowed list rule. It highlights unexpected or invalid custom properties. ```text src/components/typography/textContainer/TextContainer.scss 4:3 ✖ Unexpected custom property [--p-text-container-spacing]. polaris/custom-property-allowed-list 6:5 ✖ Invalid custom properties [--p-text-container-spacing]. polaris/custom-property-allowed-list 15:3 ✖ Unexpected custom property [--p-text-container-spacing]. polaris/custom-property-allowed-list 19:3 ✖ Unexpected custom property [--p-text-container-spacing]. polaris/custom-property-allowed-list ``` -------------------------------- ### Install and Symlink Dependencies Source: https://github.com/shopify/polaris-react/blob/main/polaris.shopify.com/content/tools/stylelint-polaris.mdx Command to install and symlink dependencies in the polaris monorepo. This is a prerequisite for testing stylelint-polaris updates. ```sh pnpm install ``` -------------------------------- ### Troubleshooting: Syntax Errors in Examples Source: https://github.com/shopify/polaris-react/blob/main/documentation/Component READMEs.md This console output highlights a syntax error within a specific example, indicating the location (line and character) of the issue. ```console 🚨 Example "Autocomplete with loading" contains a syntax error in src/components/Autocomplete/README.md: Unexpected token (18:20) ``` -------------------------------- ### Migrate ButtonGroup segmented prop example Source: https://github.com/shopify/polaris-react/blob/main/polaris.shopify.com/content/version-guides/migrating-from-v11-to-v12.mdx Example demonstrating the migration of the `segmented` prop to `variant="segmented"` for the ButtonGroup component. ```diff - + ``` -------------------------------- ### Migration Example: ProgressBar prop change Source: https://github.com/shopify/polaris-react/blob/main/polaris.shopify.com/content/version-guides/migrating-from-v11-to-v12.mdx Demonstrates the replacement of the `color` prop with the `tone` prop for the ProgressBar component. ```diff - + ``` -------------------------------- ### Tabs With Actions Example Source: https://github.com/shopify/polaris-react/blob/main/polaris.shopify.com/content/components/navigation/tabs.mdx Use when actions need to be performed on a tab. This example shows how to include action elements alongside tab navigation. ```tsx import {Tabs} from "@shopify/polaris"; function TabsWithActionsExample() { return ( console.log('Primary action clicked') }, {content: 'Secondary action', onAction: () => console.log('Secondary action clicked') } ]}, {content: 'Fitted', id: 'customer'}, ]} selected={'all'} /> ); } ``` -------------------------------- ### Resource List with All Elements Source: https://github.com/shopify/polaris-react/blob/main/polaris.shopify.com/content/components/lists/resource-list.mdx A comprehensive example showcasing most of the available props for the ResourceList component. ```tsx import {{ ResourceList, Button, Select, ChoiceList, EmptyState }} from "@shopify/polaris"; import {{ useState }} from "react"; const users = [ { id: '1', name: 'Mae Jemison', email: 'mae@increments.com', role: 'Astronaut', }, { id: '2', name: 'Nicole Mann', email: 'nicole@increments.com', role: 'Astronaut', }, { id: '3', name: 'Ellen Ochoa', email: 'ellen@increments.com', role: 'Engineer', }, ]; const sortOptions = [ { label: 'Newest', value: 'newest' }, { label: 'Oldest', value: 'oldest' }, ]; const filterMarkup = ( {{ console.log('Filter changed') }} } /> ); const emptyState = (

Upload your first file here

); const emptySearchResultState = (

Try changing your search terms or filters.

); function App() {{ const [selectedItems, setSelectedItems] = useState([]); const [sort, setSort] = useState('newest'); const handleSortChange = (value: string) => {{ setSort(value); }}; const promotedBulkActions = [ {{ content: 'Add tags', onAction: () => console.log('Promoted bulk action: Add tags'), }}, ]; const bulkActions = [ {{ content: 'Mark as unread', onAction: () => console.log('Bulk action: Mark as unread'), }}, ]; const sortComponent = (