PPolaris ComponentsConnect an agent

Collapsible

A container that animates its content open and closed, used to hide secondary settings behind a toggle until someone needs them.

Preview

Code

Example.jsx
import { useState } from 'react';
import { Card, BlockStack, InlineStack, Divider, Text, Button, Collapsible, TextField, Checkbox } from '@shopify/polaris';

const TRANSITION = { duration: '200ms', timingFunction: 'ease-in-out' };

export const Example = () => {
  const [open, setOpen] = useState(false);
  const [title, setTitle] = useState('Snowdevil | Winter gear built for the cold');
  const [description, setDescription] = useState('Shop insulated jackets, boots and gloves tested at -30C.');
  const [indexable, setIndexable] = useState(true);

  return (
    <Card>
      <BlockStack gap="300">
        <InlineStack align="space-between" blockAlign="center">
          <BlockStack gap="050">
            <Text as="h2" variant="headingMd">
              Search engine listing
            </Text>
            <Text as="p" tone="subdued" variant="bodySm">
              Controls how this page appears in Google results.
            </Text>
          </BlockStack>
          <Button
            onClick={() => setOpen((current) => !current)}
            ariaExpanded={open}
            ariaControls="search-engine-listing"
            disclosure={open ? 'up' : 'down'}
          >
            {open ? 'Hide' : 'Edit'}
          </Button>
        </InlineStack>

        <Collapsible
          open={open}
          id="search-engine-listing"
          transition={TRANSITION}
          expandOnPrint
        >
          <BlockStack gap="300">
            <Divider />
            <TextField
              label="Page title"
              value={title}
              onChange={setTitle}
              autoComplete="off"
              maxLength={70}
              showCharacterCount
            />
            <TextField
              label="Meta description"
              value={description}
              onChange={setDescription}
              autoComplete="off"
              multiline={3}
              maxLength={160}
              showCharacterCount
            />
            <Checkbox
              label="Allow search engines to index this page"
              checked={indexable}
              onChange={setIndexable}
            />
          </BlockStack>
        </Collapsible>
      </BlockStack>
    </Card>
  );
};