diff --git a/common/changes/pcln-design-system/feat-docs-for-swatch_2023-07-10-17-28.json b/common/changes/pcln-design-system/feat-docs-for-swatch_2023-07-10-17-28.json new file mode 100644 index 0000000000..fcc81aa7ff --- /dev/null +++ b/common/changes/pcln-design-system/feat-docs-for-swatch_2023-07-10-17-28.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "pcln-design-system", + "comment": "Update docs for Swatch", + "type": "patch" + } + ], + "packageName": "pcln-design-system" +} \ No newline at end of file diff --git a/common/changes/pcln-icons/feat-docs-for-swatch_2023-07-10-17-28.json b/common/changes/pcln-icons/feat-docs-for-swatch_2023-07-10-17-28.json new file mode 100644 index 0000000000..9f33a59289 --- /dev/null +++ b/common/changes/pcln-icons/feat-docs-for-swatch_2023-07-10-17-28.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "pcln-icons", + "comment": "", + "type": "none" + } + ], + "packageName": "pcln-icons" +} \ No newline at end of file diff --git a/packages/core/src/Swatch/Swatch.stories.tsx b/packages/core/src/Swatch/Swatch.stories.tsx index 20cdbeb35b..e2b460d267 100644 --- a/packages/core/src/Swatch/Swatch.stories.tsx +++ b/packages/core/src/Swatch/Swatch.stories.tsx @@ -1,43 +1,97 @@ +/* eslint-disable react/no-unescaped-entities */ +import { ArgsTable, Primary, PRIMARY_STORY } from '@storybook/addon-docs' +import { Meta, StoryObj } from '@storybook/react' +import { Hero, Section, StoryStage, TableOfContents, Flex, Swatch, Text, ThemeProvider } from '..' +import type { ISwatchProps } from './Swatch' import React, { useState } from 'react' -import Swatch from './Swatch' -import { Box, Flex, Text } from '../' -export default { - title: 'Swatch', - component: Swatch, +type SwatchStory = StoryObj + +export const Playground: SwatchStory = { + render: (args) => , + args: { + colors: [ + '#D50032', + '#1B7742', + '#0033A0', + '#002244', + '#6244BB', + '#31225D', + '#31225D', + '#FFC658', + '#4F6F8F', + ], + }, + argTypes: { + onClick: () => null, + }, +} + +export const SingleColor: SwatchStory = { + render: () => ( + + + + ), } -export const SingleColor = () => - -export const MultipleColors = () => - -export const Wrap = () => ( - - - -) - -export const SelectColor = () => { +export const MultipleColors: SwatchStory = { + render: () => ( + + + + ), +} + +const SwatchWithState = () => { const [color, setColor] = useState('#D50032') return ( - <> - setColor(color)} /> - + + (typeof color === 'string' ? setColor(color) : undefined)} + /> + Color: {color} - + ) } + +export const SelectColor: SwatchStory = { + render: () => , +} + +const meta: Meta = { + title: 'Swatch', + component: Swatch, + parameters: { + docs: { + page: () => ( + + + Use the Swatch component to render a group of colors. Clicking one of the colors will execute + onClick callback, that can be passed as a prop. + + + + +
+ + Use the Swatch component to render a group of colors. Clicking one of the colors will execute + onClick callback, that can be passed as a prop. + +
+ +
+ + +
+
+ ), + }, + }, +} + +export default meta diff --git a/packages/core/src/Swatch/Swatch.tsx b/packages/core/src/Swatch/Swatch.tsx index d359f40023..46d75eb26f 100644 --- a/packages/core/src/Swatch/Swatch.tsx +++ b/packages/core/src/Swatch/Swatch.tsx @@ -1,4 +1,3 @@ -import PropTypes, { InferProps } from 'prop-types' import React from 'react' import styled from 'styled-components' import { Flex } from '../Flex' @@ -15,25 +14,25 @@ const SwatchColor = styled.div` cursor: ${(props) => (props.onClick ? 'pointer' : 'default')}; ` -const propTypes = { - colors: PropTypes.arrayOf(PropTypes.string), - onClick: PropTypes.func, +export interface ISwatchProps { + colors?: string[] + onClick?: (color: string) => void } -const Swatch: React.FC> = ({ colors, onClick, ...props }) => ( - - {colors.map((color, idx) => ( - onClick(color) : undefined} - /> - ))} - -) - -Swatch.propTypes = propTypes -Swatch.displayName = 'Swatch' +const Swatch: React.FC = (props: ISwatchProps) => { + const { colors, onClick } = props + return ( + + {colors.map((color, idx) => ( + onClick(color) : undefined} + /> + ))} + + ) +} export default Swatch diff --git a/packages/core/src/Swatch/index.ts b/packages/core/src/Swatch/index.ts index 019a8b9498..dae809e4f8 100644 --- a/packages/core/src/Swatch/index.ts +++ b/packages/core/src/Swatch/index.ts @@ -1 +1,2 @@ export { default as Swatch } from './Swatch' +export type { ISwatchProps } from './Swatch' diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 49fec7ad1a..f7c5f31da5 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,4 +1,5 @@ export type { IButtonProps } from './Button' +export type { ISwatchProps } from './Swatch' export { Absolute } from './Absolute' export * from './Animate' diff --git a/packages/icons/src/index.js b/packages/icons/src/index.js index 1f77459663..ddd12ef1ea 100644 --- a/packages/icons/src/index.js +++ b/packages/icons/src/index.js @@ -276,4 +276,4 @@ export { default as Whirlpool } from './Whirlpool.jsx' export { default as Widgets } from './Widgets.jsx' export { default as Wifi } from './Wifi.jsx' export { default as Youtube } from './Youtube.jsx' -export { default as ZoomOut } from './ZoomOut.jsx' +export { default as ZoomOut } from './ZoomOut.jsx' \ No newline at end of file