Skip to content

Commit

Permalink
feat(task-counter): enable default is collapse in task counter
Browse files Browse the repository at this point in the history
  • Loading branch information
glrodasz committed Apr 20, 2021
1 parent 8373e66 commit e02db79
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
1 change: 0 additions & 1 deletion .storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,5 @@ export const parameters = {
styles: { table: { disable: true } },
getStyles: { table: { disable: true } },
},
args: { isPlayground: true },
actions: { argTypesRegex: '^on[A-Z].*' },
}
25 changes: 18 additions & 7 deletions molecules/TaskCounter/TaskCounter.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,55 +16,66 @@ const handleToggle = ({ onToggle, isCollapsed, setIsCollapsed }) => () => {
}

export const TaskCounter = ({
title,
children,
current,
total,
isToggleable,
onToggle,
getStyles,
defaultIsCollapsed,
}) => {
const [isCollapsed, setIsCollapsed] = useState(true)
const [isCollapsed, setIsCollapsed] = useState(defaultIsCollapsed)

return (
<div className={getStyles('task-counter')}>
<div className={getStyles('container')}>
<div
className={getStyles('container', { 'is-toggleable': isToggleable })}
onClick={
isToggleable &&
handleToggle({ onToggle, isCollapsed, setIsCollapsed })
}
>
{isToggleable && (
<>
<Icon
color="inverted"
size="sm"
name={isCollapsed ? 'angleUp' : 'angleDown'}
background="fulfilled"
isClickable
onClick={handleToggle({ onToggle, isCollapsed, setIsCollapsed })}
/>
<Spacer.Vertical size="xs" />
<Spacer.Vertical size="sm" />
</>
)}
<Paragraph weight="medium">{children}</Paragraph>
<Paragraph weight="medium">{title}</Paragraph>
<Paragraph weight="medium" isInline>
{total ? `${current}/${total}` : current}
</Paragraph>
</div>
<Spacer.Horizontal size="xs" />
<Divider />
{!isCollapsed && children}
</div>
)
}

TaskCounter.propTypes = {
children: PropTypes.node.isRequired,
title: PropTypes.string.isRequired,
getStyles: PropTypes.func.isRequired,
type: PropTypes.oneOf(options.types),
current: PropTypes.number.isRequired,
children: PropTypes.node,
onToggle: PropTypes.func,
isToggleable: PropTypes.bool,
total: PropTypes.number,
defaultIsCollapsed: PropTypes.bool,
}

TaskCounter.defaultProps = {
getStyles: () => {},
onToggle: () => {},
current: 0,
defaultIsCollapsed: true,
}

export default withStyles(styles)(TaskCounter)
4 changes: 4 additions & 0 deletions molecules/TaskCounter/TaskCounter.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@
line-height: 1;
text-transform: uppercase;
}

.is-toggleable {
cursor: pointer;
}
9 changes: 7 additions & 2 deletions molecules/TaskCounter/TaskCounter.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
title: 'Molecules/TaskCounter',
component: TaskCounter,
args: {
children: 'Em Sméagol body.',
title: 'Em Sméagol body.',
current: 2,
},
argTypes: {
Expand All @@ -21,4 +21,9 @@ export const Total = Template.bind({})
Total.args = { total: 10 }

export const Toggleable = Template.bind({})
Toggleable.args = { isToggleable: true, total: 10 }
Toggleable.args = {
isToggleable: true,
total: 10,
children:
"Fells defeated veins this. There and Back Again. A Hobbit's Tale. Loved lucky Istari difficult lay? Dale fellow's rioting. Blanket Misty Mountain started rival wriggles flatten convinced succumbed closing? Slug town fond pipe-weed flatten recognizes Goblins! Innards pouf admirable freely nothingness sleepless exactly afternoon cruelty Bofur? Craftsmen tested fair Alfrid gets figure words winter's field offer healed squash? These galumphing Grima tread mustn't seen melt ideal picked recover employment. Nazgûl alas luckiest?",
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ exports[`Storyshots Molecules/TaskCounter Toggleable 1`] = `
className="task-counter"
>
<div
className="container"
className="container is-toggleable"
onClick={[Function]}
>
<div
className="icon color-inverted size-sm background-fulfilled is-clickable"
onClick={[Function]}
className="icon color-inverted size-sm background-fulfilled"
style={
Object {
"height": 25,
Expand All @@ -97,7 +97,7 @@ exports[`Storyshots Molecules/TaskCounter Toggleable 1`] = `
Object {
"height": "100%",
"maxHeight": "auto",
"width": 5,
"width": 15,
}
}
/>
Expand Down

1 comment on commit e02db79

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for cero-components ready!

✅ Preview
https://cero-components-fuotuolxk-glrodasz.vercel.app

Built with commit e02db79.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.