Skip to content

Commit a53908a

Browse files
authored
Merge pull request #2140 from OpenNeuroOrg/toggleCounter
update to some scss vars and created new toggle counter button
2 parents 4ff3a87 + 4c6bdfe commit a53908a

File tree

25 files changed

+416
-123
lines changed

25 files changed

+416
-123
lines changed

.pnp.js

Lines changed: 85 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/openneuro-components/.storybook/preview-head.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
@import url('https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300;0,400;0,600;0,700;1,300;1,400;1,600');
33
</style>
44

5-
<script src="https://kit.fontawesome.com/dbe89e3d01.js" crossorigin="anonymous"></script>
5+
<script src="https://kit.fontawesome.com/dbe89e3d01.js" crossorigin="anonymous"></script>
6+

packages/openneuro-components/src/accordion/AccordionTab.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Icon } from '../icon/Icon'
55
import './accordion.scss'
66

77
export interface AccordionTabProps {
8-
children: object
8+
children: React.ReactNode
99
tabId: string
1010
className: string
1111
label: string

packages/openneuro-components/src/accordion/AccordionWrap.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from 'react'
33
import './accordion.scss'
44

55
export interface AccordionWrapProps {
6-
children: object
6+
children: React.ReactNode
77
className: string
88
}
99

packages/openneuro-components/src/button/Button.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface ButtonProps {
1515
imgSrc?: string
1616
iconSize?: string
1717
className?: string
18+
children: React.ReactNode
1819
}
1920

2021
/**
@@ -32,6 +33,8 @@ export const Button: React.FC<ButtonProps> = ({
3233
imgSrc,
3334
iconSize,
3435
className,
36+
children,
37+
disabled,
3538
...props
3639
}) => {
3740
const mode =
@@ -53,6 +56,7 @@ export const Button: React.FC<ButtonProps> = ({
5356

5457
return (
5558
<button
59+
disabled={disabled}
5660
role="button"
5761
type="button"
5862
className={[
@@ -67,6 +71,7 @@ export const Button: React.FC<ButtonProps> = ({
6771
{imgIcon}
6872
{fontIcon}
6973
{label}
74+
{children}
7075
</button>
7176
)
7277
}

packages/openneuro-components/src/button/button.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@import '../scss/global';
1+
@import '../scss/variables';
22

33
.on-button {
44
font-family: $font-sans;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import React from 'react'
2+
import { Story, Meta } from '@storybook/react'
3+
import { CountToggle, CountToggleProps } from './CountToggle'
4+
5+
export default {
6+
title: 'Components/CountToggle',
7+
component: CountToggle,
8+
} as Meta
9+
10+
const CountToggleTemplate: Story<CountToggleProps> = ({
11+
label,
12+
icon,
13+
disabled,
14+
tooltip,
15+
}) => {
16+
const [displayOptions, setDisplayOptions] = React.useState(false)
17+
const [count, setCount] = React.useState(1)
18+
19+
const onClick = () => {
20+
setCount(count === 1 ? 2 : 1)
21+
}
22+
23+
return (
24+
<CountToggle
25+
label={label}
26+
icon={icon}
27+
disabled={disabled}
28+
onClick={onClick}
29+
tooltip={tooltip}
30+
displayOptions={displayOptions}
31+
setDisplayOptions={setDisplayOptions}
32+
count={count}
33+
/>
34+
)
35+
}
36+
37+
export const Example = CountToggleTemplate.bind({})
38+
Example.args = {
39+
icon: 'fa-thumbtack',
40+
disabled: false,
41+
tooltip: 'hello Tip',
42+
label: 'Follow',
43+
}
44+
45+
Example.parameters = {
46+
layout: 'centered',
47+
}
48+
49+
export const disabled = CountToggleTemplate.bind({})
50+
disabled.args = {
51+
icon: 'fa-thumbtack',
52+
disabled: true,
53+
tooltip: 'hello Tip',
54+
label: 'Follow',
55+
}
56+
57+
disabled.parameters = {
58+
layout: 'centered',
59+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import React from 'react'
2+
import './count-toggle.scss'
3+
import { Tooltip } from '../tooltip/Tooltip'
4+
import { Button } from '../button/Button'
5+
import { Modal } from '../modal/Modal'
6+
import { UserModalInner } from '../modal/UserModalInner'
7+
8+
export interface CountToggleProps {
9+
label?: string
10+
icon?: string
11+
disabled?: boolean
12+
tooltip?: string
13+
onClick?: () => void
14+
lock?: boolean
15+
displayOptions: boolean
16+
setDisplayOptions: (boolean) => void
17+
count: number
18+
}
19+
export const CountToggle = ({
20+
label,
21+
icon,
22+
disabled,
23+
tooltip,
24+
onClick,
25+
displayOptions,
26+
setDisplayOptions,
27+
count,
28+
}: CountToggleProps) => {
29+
const toggleClick = () => {
30+
onClick()
31+
setDisplayOptions(!displayOptions)
32+
}
33+
const [isOpen, setIsOpen] = React.useState(false)
34+
const toggleLogin = () => setIsOpen(!isOpen)
35+
const toggleButton = (
36+
<span className="toggle-counter">
37+
<Button
38+
className={displayOptions ? 'toggle-btn active' : 'toggle-btn'}
39+
iconSize="12px"
40+
icon={'fa ' + icon}
41+
onClick={() => toggleClick()}>
42+
{label} <span>{count}</span>
43+
</Button>
44+
</span>
45+
)
46+
const disabledToggleButton = (
47+
<span className="toggle-counter disabled">
48+
<Button
49+
className={displayOptions ? 'toggle-btn active' : 'toggle-btn'}
50+
iconSize="12px"
51+
icon={'fa ' + icon}
52+
onClick={() => toggleLogin()}>
53+
{label} <span>{count}</span>
54+
</Button>
55+
</span>
56+
)
57+
58+
return (
59+
<>
60+
<div className="toggle-counter-wrap">
61+
{tooltip ? (
62+
<Tooltip flow="up" tooltip={tooltip}>
63+
{disabled ? disabledToggleButton : toggleButton}
64+
</Tooltip>
65+
) : disabled ? (
66+
disabledToggleButton
67+
) : (
68+
toggleButton
69+
)}
70+
</div>
71+
<Modal isOpen={isOpen} toggle={toggleLogin} closeText="Close">
72+
<UserModalInner />
73+
</Modal>
74+
</>
75+
)
76+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
@import '../scss/variables';
2+
3+
.toggle-btn {
4+
border: 1px solid #aaa;
5+
padding: 7px;
6+
display: flex;
7+
justify-content: space-between;
8+
align-items: center;
9+
&:hover {
10+
text-decoration: none;
11+
background-color: #eee;
12+
}
13+
i {
14+
margin: 2px 13px 0 5px;
15+
color: #999;
16+
}
17+
span {
18+
border-left: 1px solid #aaa;
19+
margin: -7px 0 -7px 12px;
20+
display: block;
21+
position: relative;
22+
padding: 7px 3px 7px 10px;
23+
}
24+
25+
&.active {
26+
i {
27+
color: $current-theme-primary;
28+
}
29+
}
30+
}

packages/openneuro-components/src/dropdown/Dropdown.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import './dropdown.scss'
33

44
export interface DropdownProps {
55
label: Record<string, any>
6-
children
6+
children: React.ReactNode
77
className?: string
88
}
99

0 commit comments

Comments
 (0)