Skip to content

Commit d31539c

Browse files
authored
Merge pull request #3 from thewca/development
Version 0.5: RegistrationsTable and EventSelector as Controlled Component
2 parents 3cb72c2 + a67fcfa commit d31539c

15 files changed

+451
-164
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ When you are transitioning a Rails Component to React or you are building a new
1818
3. Write your component and provide type information for its props
1919
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
2020
4. Write tests for your components using jest
21-
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)
21+
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)
2222
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)
2323
6. Create a PR with your changes

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@thewca/wca-components",
3-
"version": "0.4.0",
3+
"version": "0.5.0",
44
"description": "The WCA React Component Library",
55
"repository": {
66
"type": "git",

src/components/CubingIcon/CubingIcon.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import './cubingicon.scss'
2-
import { EventId } from '@wca/helpers'
2+
import { EventId, getEventName } from '@wca/helpers'
33
import React from 'react'
4+
import { Popup } from 'semantic-ui-react'
45

56
export type IconSize = '1x' | '2x' | '3x' | '4x' | '5x'
67

@@ -16,10 +17,17 @@ export default function CubingIcon({
1617
size = '1x',
1718
}: CubingIconProps) {
1819
return (
19-
<i
20-
className={`icon cubing-icon event-${event} cubing-icon-${size} ${
21-
selected ? 'cubing-icon-selected' : 'cubing-icon-unselected'
22-
}`}
23-
/>
20+
<Popup
21+
inverted
22+
trigger={
23+
<i
24+
className={`icon cubing-icon event-${event} cubing-icon-${size} ${
25+
selected ? 'cubing-icon-selected' : 'cubing-icon-unselected'
26+
}`}
27+
/>
28+
}
29+
>
30+
{getEventName(event)}
31+
</Popup>
2432
)
2533
}

src/components/EventSelector/EventSelector.stories.ts

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import type { Meta, StoryObj } from '@storybook/react'
2+
import { EventId } from '@wca/helpers'
3+
import React, { useState } from 'react'
4+
import EventSelector from './EventSelector'
5+
6+
const meta: Meta<typeof EventSelector> = {
7+
title: 'WCA-Components/EventSelector',
8+
component: EventSelector,
9+
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/react/writing-docs/autodocs
10+
tags: ['autodocs'],
11+
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes
12+
}
13+
export default meta
14+
15+
type Story = StoryObj<typeof EventSelector>
16+
17+
export const AllEvents: Story = {
18+
// More on args: https://storybook.js.org/docs/react/writing-stories/args
19+
args: {
20+
selected: [],
21+
events: [
22+
'333',
23+
'222',
24+
'444',
25+
'555',
26+
'666',
27+
'777',
28+
'333bf',
29+
'333fm',
30+
'333oh',
31+
'clock',
32+
'minx',
33+
'pyram',
34+
'skewb',
35+
'sq1',
36+
'444bf',
37+
'555bf',
38+
'333mbf',
39+
],
40+
},
41+
decorators: [
42+
(DecoratedStory) => {
43+
const [selected, setSelected] = useState<EventId[]>([])
44+
return (
45+
<DecoratedStory
46+
args={{
47+
selected,
48+
handleEventSelection: setSelected,
49+
events: [
50+
'333',
51+
'222',
52+
'444',
53+
'555',
54+
'666',
55+
'777',
56+
'333bf',
57+
'333fm',
58+
'333oh',
59+
'clock',
60+
'minx',
61+
'pyram',
62+
'skewb',
63+
'sq1',
64+
'444bf',
65+
'555bf',
66+
'333mbf',
67+
],
68+
}}
69+
/>
70+
)
71+
},
72+
],
73+
}
74+
75+
export const SomePreSelected: Story = {
76+
// More on args: https://storybook.js.org/docs/react/writing-stories/args
77+
args: {
78+
selected: ['333'],
79+
events: ['333', '444', '555'],
80+
},
81+
decorators: [
82+
(DecoratedStory) => {
83+
const [selected, setSelected] = useState<EventId[]>(['333'])
84+
return (
85+
<DecoratedStory
86+
args={{
87+
selected,
88+
handleEventSelection: setSelected,
89+
events: ['333', '444', '555'],
90+
}}
91+
/>
92+
)
93+
},
94+
],
95+
}

src/components/EventSelector/EventSelector.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('EventSelector', () => {
99
handleEventSelection={() => {}}
1010
events={['333']}
1111
size="2x"
12-
initialSelected={[]}
12+
selected={[]}
1313
/>
1414
)
1515
})

src/components/EventSelector/EventSelector.tsx

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,48 @@
11
import './eventselector.scss'
22
import { EventId } from '@wca/helpers'
3-
import React, { useState } from 'react'
3+
import React from 'react'
44
import CubingIcon from '../CubingIcon'
55
import { IconSize } from '../CubingIcon/CubingIcon'
66

77
type HandleEventSelectionCallback = (events: EventId[]) => void
88

99
interface EventSelectorProps {
1010
handleEventSelection: HandleEventSelectionCallback
11-
initialSelected: EventId[]
11+
selected: EventId[]
1212
events: EventId[]
1313
size: IconSize
1414
}
1515

1616
export default function EventSelector({
1717
handleEventSelection,
18+
selected,
1819
events,
19-
initialSelected,
2020
size = '2x',
2121
}: EventSelectorProps) {
22-
const [selectedEvents, setSelectedEvents] =
23-
useState<EventId[]>(initialSelected)
24-
2522
const handleEventToggle = (event: EventId) => {
26-
if (selectedEvents.includes(event)) {
27-
const newEvents = selectedEvents.filter(
23+
if (selected.includes(event)) {
24+
const newEvents = selected.filter(
2825
(selectedEvent) => selectedEvent !== event
2926
)
30-
setSelectedEvents(newEvents)
3127
handleEventSelection(newEvents)
3228
} else {
33-
const newEvents = [...selectedEvents, event]
34-
setSelectedEvents(newEvents)
29+
const newEvents = [...selected, event]
3530
handleEventSelection(newEvents)
3631
}
3732
}
3833

3934
const setAllEvents = () => {
40-
setSelectedEvents(events)
4135
handleEventSelection(events)
4236
}
4337

4438
const clearAllEvents = () => {
45-
setSelectedEvents([])
4639
handleEventSelection([])
4740
}
4841

4942
return (
5043
<div className="event-selection-container">
5144
<div className="side-bar">
52-
Events ({selectedEvents.length}) <br />
45+
Events ({selected.length}) <br />
5346
<button className="all-button" onClick={setAllEvents}>
5447
{' '}
5548
All{' '}
@@ -64,7 +57,7 @@ export default function EventSelector({
6457
<label key={wcaEvent} className="event-label">
6558
<CubingIcon
6659
event={wcaEvent}
67-
selected={selectedEvents.includes(wcaEvent)}
60+
selected={selected.includes(wcaEvent)}
6861
size={size}
6962
/>
7063
<input

src/components/NonInteractiveTable/NonInteractiveTable.test.tsx

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +0,0 @@
1-
.floatThead-container{
2-
overflow-x: hidden;
3-
width: 100%;
4-
}
5-
.floatThead-table{
6-
border-collapse: collapse;
7-
border: 0 none rgba(0, 0, 0, 0.87);
8-
display: table;
9-
margin: 0;
10-
table-layout: fixed;
11-
}
12-
.floatThead-col{
13-
width: auto;
14-
}
15-
.table-condensed > thead > tr > th, .table-condensed > thead > tr > td, .table-condensed > tbody > tr > th, .table-condensed > tbody > tr > td, .table-condensed > tfoot > tr > th, .table-condensed > tfoot > tr > td {
16-
padding: 5px;
17-
}
18-
.table > thead > tr > th, .table > thead > tr > td, .table > tbody > tr > th, .table > tbody > tr > td, .table > tfoot > tr > th, .table > tfoot > tr > td {
19-
padding: 8px;
20-
line-height: 1.428571429;
21-
vertical-align: top;
22-
border-top: 1px solid #ddd;
23-
}
24-
.table th {
25-
text-align:left;
26-
}
27-
28-
table.table tfoot {
29-
font-weight: bold;
30-
}
31-
table.table-greedy-last-column,
32-
#person table.table-greedy-last-column {
33-
white-space:nowrap
34-
}
35-
table.table-greedy-last-column>thead>tr>th:last-child,
36-
#person table.table-greedy-last-column>thead>tr>th:last-child {
37-
width:100%
38-
}
39-
table.table-greedy-last-column>tbody>tr>td:last-child,
40-
#person table.table-greedy-last-column>tbody>tr>td:last-child {
41-
width:100%
42-
}

0 commit comments

Comments
 (0)