Skip to content

Commit 81a0660

Browse files
authored
DO NOT MERGE add toggle for star (#272)
* add toggle for star * hide toggle section temporarily * remove unused import
1 parent 4603df7 commit 81a0660

File tree

4 files changed

+62
-64
lines changed

4 files changed

+62
-64
lines changed

example/src/components/ToggleSection/ToggleSection.js

+38-34
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import styles from "./toggle-section.module.scss";
66
const ToggleSection = () => {
77
const [notificationAnimating, setNotificationAnimating] = useState(false)
88
const [notificationFilledAnimating, setNotificationFilledAnimating] = useState(false)
9-
const [starAnimating, setStarAnimating] = useState(false)
9+
const [ starFilled, setStarFilled ] = useState(false)
10+
11+
12+
const toggleStar = () => { setStarFilled(!starFilled); console.log(starFilled) };
13+
// const toggleStarClass = starFilled ? styles.StarFilled : styles.Unfilled
1014

1115
return (
1216
<section className="icon-section">
@@ -15,39 +19,39 @@ const ToggleSection = () => {
1519
<h2>Toggle</h2>
1620
</div>
1721
<ul className='bx--row'>
18-
<div className={styles.RowContainer}>
19-
<li
20-
className='icon-tile'
21-
onMouseEnter={() => setNotificationAnimating(true)}
22-
onMouseLeave={() => setNotificationAnimating(false)}
23-
>
24-
<h3>Notification</h3>
25-
<icons.NotificationMotion
26-
isAnimating={notificationAnimating}
27-
size={32} />
28-
</li>
29-
<li
30-
className='icon-tile'
31-
onMouseEnter={() => setNotificationFilledAnimating(true)}
32-
onMouseLeave={() => setNotificationFilledAnimating(false)}
33-
>
34-
<h3>Notification filled</h3>
35-
<icons.NotificationFilledMotion
36-
isAnimating={notificationFilledAnimating}
37-
size={32} />
38-
</li>
39-
<li
40-
className='icon-tile'
41-
onMouseEnter={() => setStarAnimating(true)}
42-
onMouseLeave={() => setStarAnimating(false)}
43-
>
44-
<h3>Star</h3>
45-
<icons.StarMotion
46-
isAnimating={starAnimating}
47-
size={32} />
48-
</li>
49-
</div>
50-
</ul>
22+
<div className={styles.RowContainer}>
23+
<li
24+
className='icon-tile'
25+
onMouseEnter={() => setNotificationAnimating(true)}
26+
onMouseLeave={() => setNotificationAnimating(false)}
27+
>
28+
<h3>Notification</h3>
29+
<icons.NotificationMotion
30+
isAnimating={notificationAnimating}
31+
size={32} />
32+
</li>
33+
<li
34+
className='icon-tile'
35+
onMouseEnter={() => setNotificationFilledAnimating(true)}
36+
onMouseLeave={() => setNotificationFilledAnimating(false)}
37+
>
38+
<h3>Notification filled</h3>
39+
<icons.NotificationFilledMotion
40+
isAnimating={notificationFilledAnimating}
41+
size={32} />
42+
</li>
43+
<li
44+
className='icon-tile'
45+
>
46+
<h3>Star</h3>
47+
<div onClick = { () => toggleStar() }>
48+
<icons.StarMotion
49+
fillStatus = { starFilled }
50+
size={32} />
51+
</div>
52+
</li>
53+
</div>
54+
</ul>
5155
</div>
5256
</section>
5357
)

example/src/pages/CollectionPage/CollectionPage.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react'
22
import FormattingSection from '../../components/FormattingSection'
33
import NavigationSection from '../../components/NavigationSection'
44
import OperationsSection from '../../components/OperationsSection'
5-
import ToggleSection from '../../components/ToggleSection'
5+
// import ToggleSection from '../../components/ToggleSection'
66
import StatusSection from '../../components/StatusSection'
77

88
import '../../app.scss'
@@ -18,7 +18,7 @@ const CollectionPage = () => {
1818
<FormattingSection></FormattingSection>
1919
<NavigationSection></NavigationSection>
2020
<OperationsSection></OperationsSection>
21-
<ToggleSection></ToggleSection>
21+
{/*<ToggleSection></ToggleSection>*/}
2222
<StatusSection></StatusSection>
2323
</div>
2424
)

src/components/Toggle/StarMotion/StarMotion.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,27 @@ import styles from './star--motion.module.scss'
33

44
const StarMotion = (props) => {
55
const iconRef = useRef(null)
6-
const [isAnimating, setIsAnimating] = useState(props.isAnimating)
6+
const [ starFilled, setStarFilled ] = useState(props.fillStatus)
77

88
let iconStyles = {
99
width: props.size,
1010
height: props.size
1111
}
12-
12+
1313
React.useEffect(() => {
14-
setIsAnimating(props.isAnimating)
15-
}, [props.isAnimating])
14+
setStarFilled(props.fillStatus)
15+
}, [props.fillStatus])
1616

17-
const shouldAnimate = isAnimating ? styles.isAnimating : ''
17+
const toggleStarBorderClass = starFilled ? styles.StarBorderFilled : styles.StarBorderUnfilled;
18+
const toggleStarInnerClass = starFilled ? styles.StarInnerFilled : styles.StarInnerUnfilled;
1819

1920
return (
20-
<div ref={iconRef} className={`${shouldAnimate}`}>
21-
<svg style={iconStyles} viewBox='0 0 32 32' className={styles.StarMotion}>
21+
<div ref={iconRef}>
22+
<svg style={iconStyles} viewBox='0 0 32 32'>
2223
<title>Star</title>
23-
<path className={styles.Star} d="M16,6.5l2.8,5.6l0.5,1l1,0.1l6.2,0.9L22,18.4l-0.8,0.7l0.2,1l1,6.1L17,23.4L16,23l-0.9,0.5l-5.5,2.9l1-6.1l0.2-1L10,18.4
24+
<path className={` ${toggleStarBorderClass}`} d="M16,6.5l2.8,5.6l0.5,1l1,0.1l6.2,0.9L22,18.4l-0.8,0.7l0.2,1l1,6.1L17,23.4L16,23l-0.9,0.5l-5.5,2.9l1-6.1l0.2-1L10,18.4
2425
l-4.4-4.4l6.2-0.9l1-0.1l0.5-1L16,6.5 M16,2l-4.6,9.2L1.3,12.7l7.4,7.2L6.9,30l9.1-4.8l9.1,4.8l-1.7-10.1l7.4-7.2l-10.2-1.5L16,2z" />
25-
<path className={styles.StarFilled } d="M16,2l-4.6,9.2L1.3,12.7l7.4,7.2L6.9,30l9.1-4.8l9.1,4.8l-1.7-10.1l7.4-7.2l-10.2-1.5L16,2z" />
26+
<path className={` ${toggleStarInnerClass}`} d="M16,2l-4.6,9.2L1.3,12.7l7.4,7.2L6.9,30l9.1-4.8l9.1,4.8l-1.7-10.1l7.4-7.2l-10.2-1.5L16,2z" />
2627
</svg>
2728
</div>
2829
)

src/components/Toggle/StarMotion/star--motion.module.scss

+12-19
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
100% { transform: scale(1)}
77
}
88

9-
109
@keyframes star-filled {
1110
0% {
1211
scale: 1;
@@ -30,28 +29,22 @@
3029
}
3130
}
3231

33-
34-
.Star {
35-
transform-origin: 1rem 1rem;
36-
will-change: transform;
32+
.StarBorderUnfilled {
33+
transform-origin: 50% 50%;
34+
transform: scale(1);
3735
}
3836

39-
.StarFilled {
40-
transform-origin: 1rem 1rem;
41-
opacity: 0;
37+
.StarBorderFilled {
38+
transform-origin: 50% 50%;
39+
animation: star 2s cubic-bezier(0.2, 0, 0.38, 0.9)
4240
}
4341

44-
45-
46-
.isAnimating {
47-
.Star {
48-
animation: star 2s cubic-bezier(0.2, 0, 0.38, 0.9)
49-
}
42+
.StarInnerUnfilled {
43+
opacity: 0;
44+
transform-origin: 50% 50%;
5045
}
5146

52-
53-
.isAnimating {
54-
.StarFilled {
55-
animation: star-filled 2s cubic-bezier(0.2, 0, 0.38, 0.9)
56-
}
47+
.StarInnerFilled {
48+
transform-origin: 50% 50%;
49+
animation: star-filled 2s cubic-bezier(0.2, 0, 0.38, 0.9)
5750
}

0 commit comments

Comments
 (0)