Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create TidCarouselV2 demo #10

Merged
merged 31 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
caa410b
Style check for TidCarouselV2.
patcon Sep 27, 2024
568d61d
Added first-pass animation with react-spring's useTransition.
patcon Sep 27, 2024
8b107df
Added barebones TidCarouselV3 component to experiment.
patcon Sep 30, 2024
42353dc
Smooth out animation. Use group selector to easily view transitions.
patcon Sep 30, 2024
14887f6
Include react-spring package.
patcon Sep 30, 2024
8370f01
Added selection to TidCarouselV2 for majority opinions.
patcon Sep 30, 2024
f74ca6a
Commit TidCarouselV2 action when first statement is auto-selected.
patcon Sep 30, 2024
5f832b3
TidCarouselV2: Added overflow row. Added scaleX rather than fontSize …
patcon Oct 1, 2024
0b21805
Use a majority opinion with 10 statements.
patcon Oct 1, 2024
7291611
Add way for buttons to know width they have to work with for spring. …
patcon Oct 1, 2024
7f77241
Only scaleX half the value when exiting.
patcon Oct 1, 2024
d81b38a
Merge branch 'main' into tidcarousel-v2
patcon Oct 8, 2024
b094ce7
Merge branch 'main' into tidcarousel-v2
patcon Oct 8, 2024
6aa564b
Merge branch 'main' into tidcarousel-v2
patcon Oct 8, 2024
8f55770
Merge branch 'main' into tidcarousel-v2
patcon Oct 8, 2024
93eb3a9
Merge branch 'main' into tidcarousel-v2
patcon Oct 8, 2024
042f819
Merge branch 'main' into tidcarousel-v2
patcon Oct 8, 2024
65faedc
Merge branch 'main' into tidcarousel-v2
patcon Oct 10, 2024
f06bb72
Updated TidCarouselV2 import.
patcon Oct 10, 2024
686eade
Added interactive story to Curate component.
patcon Oct 10, 2024
4428f0a
Added a CurateV2 component and stories.
patcon Oct 11, 2024
cdcae13
Added interactive story to TidCarousel component.
patcon Oct 11, 2024
1a78e4a
Dynamically load data into TidCarouselV2 story.
patcon Oct 11, 2024
0253dba
Renamed Curate story file.
patcon Oct 11, 2024
04d2a9f
Start with Curate group unselected.
patcon Oct 11, 2024
d69832a
Allow selecting number of groups to render for CurateV2.
patcon Oct 11, 2024
de4b8a0
Added tab aria roles to CurateV2 component.
patcon Oct 11, 2024
d06c308
Extracted TidCarouselV2 and CurateV2 components into own files.
patcon Oct 11, 2024
60464fc
Added a component for TidCarouselV2 and CurateV2 together.
patcon Oct 11, 2024
b1e4e47
Merge branch 'main' into tidcarousel-v2
patcon Oct 11, 2024
9ab8777
Added docs pages for our components, and ensured Overview comes first.
patcon Oct 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .storybook/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as globals from "../codebases/compdem/client-report/src/components/globals";
import participationData from './data/3ntrtcehas-participation-init.json'
import commentsData from './data/3ntrtcehas-comments.json'

export const getMath = () => {
return JSON.parse(participationData.pca)
Expand All @@ -20,6 +21,10 @@ export const getConversation = () => {
return participationData.conversation
}

export const getComments = () => {
return commentsData
}

export const getVoteColors = () => ({
agree: globals.brandColors.agree,
disagree: globals.brandColors.disagree,
Expand Down
87 changes: 85 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@
"storybook-branch-switcher": "github:patcon/storybook-branch-switcher#patcon/dev"
},
"dependencies": {
"@react-spring/web": "^9.7.4",
"color": "~4.2.3",
"d3-force": "~1.2.1",
"hull.js": "^0.2.11",
"radium": "^0.26.2",
"react-easy-emoji": "^1.8.1",
"react-use-measure": "^2.1.1",
"theme-ui": "^0.3.5",
"victory-core": "~36.6.8"
}
Expand Down
19 changes: 19 additions & 0 deletions stories/OurComponents.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import LinkTo from '@storybook/addon-links/react';
import { Meta } from '@storybook/blocks';

<Meta title="2. Our Components" />

# Our Custom Components

The vast majority of the components in this Storybook are unmodified from either:
1. the upstream Polis codebase maintained by Computational Democracy Project, or
2. the forked Polis codebases maintained by others.

As a helpful resource, these are the components (each a **clickable `Link`**) that we ourselves have modified or experimented with:

- <LinkTo kind="compdem/client-participation/CurateV2" story="Interactive">`CurateV2`</LinkTo>
(Replaces <LinkTo kind="compdem/client-participation/Curate" story="Interactive">`Curate`</LinkTo>)
- <LinkTo kind="compdem/client-participation/TidCarouselV2" story="Interactive">`TidCarouselV2`</LinkTo>
(Replaces <LinkTo kind="compdem/client-participation/TidCarousel" story="Interactive">`TidCarousel`</LinkTo>)
- <LinkTo kind="compdem/client-participation/SelectionWidgetV2" story="Interactive">`SelectionWidgetV2`</LinkTo>
(Replaces no single component)
4 changes: 4 additions & 0 deletions stories/Overview.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { Meta } from '@storybook/blocks';

<Meta title="1. Overview" />

# Overview: Polis-Storybook

🚧 This overview page is considered a work-in-progress until this line is removed
Expand Down
76 changes: 76 additions & 0 deletions stories/compdem/client-participation/CurateV2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import React from 'react'
import * as globals from '../../../codebases/compdem/client-participation/vis2/components/globals'

export const CurateV2Button = ({isSelected, onCurateButtonClick, style, children}) => {
const colors = {
polisBlue: "#03a9f4",
darkGray: "rgb(100,100,100)",
lightGray: "rgb(235,235,235)",
}
const buttonStyle = {
...style,
border: 0,
cursor: "pointer",
borderRadius: 4,
fontSize: 14,
padding: "6px 12px",
letterSpacing: 0.75,
// fontWeight: isSelected ? 700 : 500,
textShadow: isSelected ? "0 0 .65px #fff" : null,
backgroundColor: isSelected ? colors.polisBlue : colors.lightGray,
color: isSelected ? "white" : colors.darkGray,
}
return (
<button style={buttonStyle} role="tab" aria-selected={isSelected} onClick={onCurateButtonClick}>
{children}
</button>
)
}

const CurateV2 = ({selectedTidCuration, handleCurateButtonClick = () => {}, math}) => {
const GROUP_COUNT = math["group-clusters"].length
const styles = {
container: {
display: "flex",
flexDirection: "column",
rowGap: 5,
},
groupContainer: {
display: "flex",
gap: 5,
},
groupButton: {
flex: 1,
},
majorityButton: {
width: "100%",
},
}
const groups = ['A', 'B', 'C', 'D', 'E']

return(
<div style={styles.container} role="tablist">
<div style={styles.groupContainer}>
{groups.slice(0, GROUP_COUNT).map((groupLabel, index) => (
<CurateV2Button
key={groupLabel}
onCurateButtonClick={() => handleCurateButtonClick(index)}
isSelected={selectedTidCuration === index}
style={styles.groupButton}
>
{groupLabel}
</CurateV2Button>
))}
</div>
<CurateV2Button
onCurateButtonClick={() => handleCurateButtonClick(globals.tidCuration.majority)}
isSelected={selectedTidCuration === globals.tidCuration.majority}
style={styles.majorityButton}
>
Diverse Majority Opinion
</CurateV2Button>
</div>
)
}

export default CurateV2
61 changes: 61 additions & 0 deletions stories/compdem/client-participation/CurateV2.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import React, { useState } from 'react'
import { action } from '@storybook/addon-actions'
import * as globals from '../../../codebases/compdem/client-participation/vis2/components/globals'
import Strings from '../../../codebases/compdem/client-participation/js/strings/en_us'
import CurateV2 from './CurateV2'
import { getMath } from '../../../.storybook/utils'

const mathResults = getMath()

export default {
component: CurateV2,
argTypes: {
groupCount: {
options: [2, 3, 4],
control: { type: 'inline-radio' },
}
}
}

const Template = ({ groupCount, ...args }) => {
args.math["group-clusters"] = mathResults["group-clusters"].slice(0, groupCount)
const [selectedTidCuration, setSelectedTidCuration] = useState(globals.tidCuration.majority)
const handleCurateButtonClick = (tidCuration) => {
action("Clicked")(tidCuration)
setSelectedTidCuration(tidCuration)
}
return <CurateV2 {...{selectedTidCuration, handleCurateButtonClick}} {...args} />
}

export const Interactive = Template.bind({})
Interactive.args = {
groupCount: 4,
Strings: {
majorityOpinion: Strings.majorityOpinion,
group_123: Strings.group_123
},
math: mathResults,
}

export const Unselected = Template.bind({})
Unselected.args = {
selectedTidCuration: null,
Strings: {
majorityOpinion: Strings.majorityOpinion,
group_123: Strings.group_123
},
handleCurateButtonClick: action('Clicked'),
math: mathResults,
}

export const MajoritySelected = Template.bind({})
MajoritySelected.args = {
...Unselected.args,
selectedTidCuration: globals.tidCuration.majority
}

export const GroupSelected = Template.bind({})
GroupSelected.args = {
...Unselected.args,
selectedTidCuration: 1
}
4 changes: 2 additions & 2 deletions stories/compdem/client-participation/Graph.stories.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react'
import Graph from '../../../codebases/compdem/client-participation/vis2/components/graph'
import { getMath } from '../../../.storybook/utils'
import { getComments, getMath } from '../../../.storybook/utils'
import Strings from '../../../codebases/compdem/client-participation/js/strings/en_us'
import commentsData from '../../../.storybook/data/3ntrtcehas-comments.json'
import { action } from '@storybook/addon-actions'

const commentsData = getComments()
const mathResult = getMath()

export default {
Expand Down
Loading