Skip to content

Commit

Permalink
Add way for buttons to know width they have to work with for spring. …
Browse files Browse the repository at this point in the history
…Use gap instead of margin values. Don't change fontSize.
  • Loading branch information
patcon committed Oct 8, 2024
1 parent 0b21805 commit 7291611
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
18 changes: 18 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"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
26 changes: 14 additions & 12 deletions stories/client-participation/TidCarouselV2.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,27 @@ import { action } from '@storybook/addon-actions'
import Strings from '../../polis/client-participation/js/strings/en_us'
import { animated, useTransition } from '@react-spring/web'
import commentsData from '../../.storybook/data/3ntrtcehas-comments.json'
import useMeasure from 'react-use-measure'

commentsData.sort((a,b) => a.tid - b.tid)

const TidCarouselButton = ({ label, isShown, isSelected, handleClick }) => {
const TidCarouselButton = ({ label, isShown, isSelected, handleClick, containerWidth }) => {
const transition = useTransition(isShown, {
from: {
width: 0,
marginRight: 0,
fontSize: 6,
opacity: 1,
},
enter: {
width: 32,
marginRight: 5,
fontSize: 14,
width: containerWidth/5-5,
marginRight: 0,
opacity: 1,
},
leave: {
width: 0,
marginRight: 0,
fontSize: 0,
marginRight: -5,
opacity: 0,
}
},
})
return (
transition((style, isShownTransition) => (
Expand All @@ -38,7 +36,6 @@ const TidCarouselButton = ({ label, isShown, isSelected, handleClick }) => {
// fontSize changes seem slow. Scale span instead.
// fontSize: style.fontSize,
opacity: style.opacity,
marginBottom: 5,
padding: 0,
border: 0,
cursor: "pointer",
Expand Down Expand Up @@ -71,21 +68,26 @@ const TidCarouselV2 = ({
Strings,
}) => {
if ( selectedTidCuration === null ) return null
const [ref, bounds] = useMeasure()

allComments = allComments.sort((a, b) => a.tid - b.tid)
const commentsToShowTids = commentsToShow.map(c => c.tid)

// ref not available on first render, so only render map after bounds exists.
return (
<div style={{
<div ref={ref} style={{
display: "flex",
flex: 1,
width: 185,
width: "100%",
height: 65,
paddingX: 0,
gap: 5,
rowGap: 5,
flexWrap: "wrap",
}}>
{allComments.map(c => (
{!bounds.width || allComments.map((c, i) => (
<TidCarouselButton
containerWidth={bounds.width}
id={c.tid}
label={c.tid}
handleClick={() => handleCommentClick(c)}
Expand Down

0 comments on commit 7291611

Please sign in to comment.