Generating a new component

The fastest way to get started with creating a new component is to generate it from the command line. Run the following command to have your new component scaffolded for you:

$ yarn new-package

? SWC package name (i.e. color-area)

Note that your component name should be provided in kebab case and should relate as closely as possible to the Spectrum core naming.

- packages
    - [new-component-name]
        - src
            - index.ts
            - spectrum-[new-component-name].css
            - [new-component-name]-overrides.css
            - [new-component-name].css
            - [NewComponentName].ts
        - stories
            - [new-component-name].stories.ts
            - args.ts
            - template.ts
        - test
            - benchmark
                - basic-test.ts
            - [new-component-name].test.ts
        - .npmrc
        - CHANGELOG.md
        - custom-elements.json
        - package.json
        - README.md
        - sp-[new-component-name].ts
        - tsconfig.json

Outside of your new package, you will need to manually add information about your new package to the tsconfig-all.json and tsconfig-react-wrapper.json files, as well as the bundle package:

Open tsconfig-all.json, find "references", and add an entry for your package ({ "path": "packages/package-name" }), alphabetically (replacing "package-name" with the pattern you're implementing, such as "action-button" or "progress-bar"). The tsconfig-all.json config is used to build types for the project in parallel with the JS build that is handled outside of tsc. This will ensure that the types for your new package are available throughout the library, including at demonstration and test time.

Open tsconfig-react-wrapper.json, find "references", and add an entry for your package ({ "path": "react/package-name" }), alphabetically (replacing "package-name" with the pattern you're implementing, such as "action-button" or "progress-bar"). The tsconfig-react-wrapper.json config is used to build types for the @swc-react project, so that consumers can benefit from type definitions for SWC components even when using the React wrapper.

Include a listing for your package in bundle/elements.ts and bundle/src/index.js. Then, confirm that your new package is already listed in tools/bundle/package.json. The bundle package makes it possible to build demo projects with all of the components from the library registered in a single place, and is also leveraged for ease of component consumption in the documentation site build.

Finally, run yarn in your terminal. This will grab any newly-added packages, as well as to ensure that you have the provided CSS processed for use in your component. You can now see your component in the Storybook, using the command yarn storybook, or test its functionality via yarn test.

If you run into any issues with the instructions above, or the ones linked across this documentation site, please feel free to raise questions or issues on GitHub. You can do this either by creating a brand new issue when it specifically relates to the process of generating a component, or by leaving a comment on an already-created issue for a specific pattern when it concerns bringing that component to life.

Thanks for stopping by. We look forward to your contribution!

Getting started Dev mode Registry conflicts Components Accordion Accordion Item Action Bar Action Button Action Group Action Menu Alert Banner Alert Dialog Asset Avatar Badge Breadcrumbs Breadcrumb Item Button Clear Button Close Button Button Group Card Checkbox Coachmark Coach Indicator Color Area Color Field Color Handle Color Loupe Color Slider Color Wheel Combobox Contextual Help Dialog Dialog Base Dialog Wrapper Divider Dropzone Field Group Field Label Help Text Help Text Mixin Icon Icons Icons UI Icons Workflow Iconset Illustrated Message Infield Button Link Menu Menu Group Menu Item Meter Number Field Overlay Imperative Api Overlay Trigger Slottable Request Trigger Directive Picker Picker Button Popover Progress Bar Progress Circle Radio Radio Group Search Sidenav Sidenav Heading Sidenav Item Slider Slider Handle Split View Status Light Swatch Swatch Group Switch Table Tabs Tab Panel Tab Tabs Overflow Tags Tag Textfield Textarea Thumbnail Toast Tooltip Tooltip Directive Top Nav Top Nav Item Tray Underlay Tools Base Bundle Grid Opacity Checkerboard Reactive Controllers Color Controller Dependency Manager Element Resolution Match Media Pending State Roving Tab Index Shared Styles Theme Core Tokens Truncated Contributing Developing a Component Configuring your project Generating a new component Styling Components Writing Changesets Migration Guides 2024/10/31 (v1.0.0) 2021/11/8 2023/8/18 Deprecation Guide Using swc-react Storybook Storybook Spectrum Spectrum CSS
Morty Proxy This is a proxified and sanitized view of the page, visit original site.