diff --git a/README.md b/README.md index 28aefdb..d3d6e39 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,6 @@ When you are transitioning a Rails Component to React or you are building a new 3. Write your component and provide type information for its props 1. If your component has a state that would make sense to communicate to a parent component make sure to provide callback functions that are triggered on state changes 4. Write tests for your components using jest - 1. You can also add a Story to your component using Storybook to more easily visualize how arguments affect your component and how to interact with it. See an example in [EventSelector.stories.ts](src%2Fcomponents%2FEventSelector%2FEventSelector.stories.ts) + 1. You can also add a Story to your component using Storybook to more easily visualize how arguments affect your component and how to interact with it. See an example in [EventSelector.stories.tsx](src%2Fcomponents%2FEventSelector%2FEventSelector.stories.ts) 5. Create an index.ts in your directory to export your component and add its desired exported name to [src/components/index.ts](src%2Fcomponents%2Findex.ts) 6. Create a PR with your changes \ No newline at end of file diff --git a/package.json b/package.json index 3b47f7d..8e62058 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@thewca/wca-components", - "version": "0.4.0", + "version": "0.5.0", "description": "The WCA React Component Library", "repository": { "type": "git", diff --git a/src/components/CubingIcon/CubingIcon.tsx b/src/components/CubingIcon/CubingIcon.tsx index 956165b..e66d21d 100644 --- a/src/components/CubingIcon/CubingIcon.tsx +++ b/src/components/CubingIcon/CubingIcon.tsx @@ -1,6 +1,7 @@ import './cubingicon.scss' -import { EventId } from '@wca/helpers' +import { EventId, getEventName } from '@wca/helpers' import React from 'react' +import { Popup } from 'semantic-ui-react' export type IconSize = '1x' | '2x' | '3x' | '4x' | '5x' @@ -16,10 +17,17 @@ export default function CubingIcon({ size = '1x', }: CubingIconProps) { return ( - + + } + > + {getEventName(event)} + ) } diff --git a/src/components/EventSelector/EventSelector.stories.ts b/src/components/EventSelector/EventSelector.stories.ts deleted file mode 100644 index b8aa944..0000000 --- a/src/components/EventSelector/EventSelector.stories.ts +++ /dev/null @@ -1,47 +0,0 @@ -import type { Meta, StoryObj } from '@storybook/react' -import EventSelector from './EventSelector' - -const meta: Meta = { - title: 'WCA-Components/EventSelector', - component: EventSelector, - // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/react/writing-docs/autodocs - tags: ['autodocs'], - // More on argTypes: https://storybook.js.org/docs/react/api/argtypes -} -export default meta - -type Story = StoryObj - -export const AllEvents: Story = { - // More on args: https://storybook.js.org/docs/react/writing-stories/args - args: { - initialSelected: [], - events: [ - '333', - '222', - '444', - '555', - '666', - '777', - '333bf', - '333fm', - '333oh', - 'clock', - 'minx', - 'pyram', - 'skewb', - 'sq1', - '444bf', - '555bf', - '333mbf', - ], - }, -} - -export const SomePreSelected: Story = { - // More on args: https://storybook.js.org/docs/react/writing-stories/args - args: { - initialSelected: ['333'], - events: ['333', '444', '555'], - }, -} diff --git a/src/components/EventSelector/EventSelector.stories.tsx b/src/components/EventSelector/EventSelector.stories.tsx new file mode 100644 index 0000000..3c57840 --- /dev/null +++ b/src/components/EventSelector/EventSelector.stories.tsx @@ -0,0 +1,95 @@ +import type { Meta, StoryObj } from '@storybook/react' +import { EventId } from '@wca/helpers' +import React, { useState } from 'react' +import EventSelector from './EventSelector' + +const meta: Meta = { + title: 'WCA-Components/EventSelector', + component: EventSelector, + // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/react/writing-docs/autodocs + tags: ['autodocs'], + // More on argTypes: https://storybook.js.org/docs/react/api/argtypes +} +export default meta + +type Story = StoryObj + +export const AllEvents: Story = { + // More on args: https://storybook.js.org/docs/react/writing-stories/args + args: { + selected: [], + events: [ + '333', + '222', + '444', + '555', + '666', + '777', + '333bf', + '333fm', + '333oh', + 'clock', + 'minx', + 'pyram', + 'skewb', + 'sq1', + '444bf', + '555bf', + '333mbf', + ], + }, + decorators: [ + (DecoratedStory) => { + const [selected, setSelected] = useState([]) + return ( + + ) + }, + ], +} + +export const SomePreSelected: Story = { + // More on args: https://storybook.js.org/docs/react/writing-stories/args + args: { + selected: ['333'], + events: ['333', '444', '555'], + }, + decorators: [ + (DecoratedStory) => { + const [selected, setSelected] = useState(['333']) + return ( + + ) + }, + ], +} diff --git a/src/components/EventSelector/EventSelector.test.tsx b/src/components/EventSelector/EventSelector.test.tsx index 152d4c2..a98f48b 100644 --- a/src/components/EventSelector/EventSelector.test.tsx +++ b/src/components/EventSelector/EventSelector.test.tsx @@ -9,7 +9,7 @@ describe('EventSelector', () => { handleEventSelection={() => {}} events={['333']} size="2x" - initialSelected={[]} + selected={[]} /> ) }) diff --git a/src/components/EventSelector/EventSelector.tsx b/src/components/EventSelector/EventSelector.tsx index 37fc97f..465a185 100644 --- a/src/components/EventSelector/EventSelector.tsx +++ b/src/components/EventSelector/EventSelector.tsx @@ -1,6 +1,6 @@ import './eventselector.scss' import { EventId } from '@wca/helpers' -import React, { useState } from 'react' +import React from 'react' import CubingIcon from '../CubingIcon' import { IconSize } from '../CubingIcon/CubingIcon' @@ -8,48 +8,41 @@ type HandleEventSelectionCallback = (events: EventId[]) => void interface EventSelectorProps { handleEventSelection: HandleEventSelectionCallback - initialSelected: EventId[] + selected: EventId[] events: EventId[] size: IconSize } export default function EventSelector({ handleEventSelection, + selected, events, - initialSelected, size = '2x', }: EventSelectorProps) { - const [selectedEvents, setSelectedEvents] = - useState(initialSelected) - const handleEventToggle = (event: EventId) => { - if (selectedEvents.includes(event)) { - const newEvents = selectedEvents.filter( + if (selected.includes(event)) { + const newEvents = selected.filter( (selectedEvent) => selectedEvent !== event ) - setSelectedEvents(newEvents) handleEventSelection(newEvents) } else { - const newEvents = [...selectedEvents, event] - setSelectedEvents(newEvents) + const newEvents = [...selected, event] handleEventSelection(newEvents) } } const setAllEvents = () => { - setSelectedEvents(events) handleEventSelection(events) } const clearAllEvents = () => { - setSelectedEvents([]) handleEventSelection([]) } return (
- Events ({selectedEvents.length})
+ Events ({selected.length})