-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Uses CSS module instead of Stitches for Loader component #2178
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
.loader { | ||
color: var(--loader-color, #1a202c); | ||
} | ||
|
||
.loaderCircle { | ||
display: inline-block; | ||
border-top: 2px solid currentcolor; | ||
border-right: 2px solid currentcolor; | ||
border-bottom: 2px solid transparent; | ||
border-left: 2px solid transparent; | ||
border-radius: 99999px; | ||
animation: fullRotation 0.45s linear infinite; | ||
width: var(--spinner-size); | ||
height: var(--spinner-size); | ||
--spinner-size: var(--loader-spinner-size, 2rem); | ||
} | ||
|
||
.loaderAccessibilityText { | ||
border: 0px; | ||
clip: rect(0px, 0px, 0px, 0px); | ||
width: 1px; | ||
height: 1px; | ||
margin: -1px; | ||
padding: 0px; | ||
overflow: hidden; | ||
white-space: nowrap; | ||
position: absolute; | ||
} | ||
|
||
@keyframes fullRotation { | ||
0% { | ||
transform: rotate(0deg); | ||
} | ||
100% { | ||
transform: rotate(360deg); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,12 @@ | ||
import { styled, keyframes } from 'wasp/core/stitches.config' | ||
import styles from './Loader.module.css' | ||
|
||
const fullRotationKeyframes = keyframes({ | ||
'0%': { transform: 'rotate(0deg)' }, | ||
'100%': { transform: 'rotate(360deg)' }, | ||
}) | ||
|
||
// DefaultLoader is a React component that spans accross the whole screen and displays | ||
// a spinner in the very middle. | ||
// Spans a accross the whole screen and displays a spinner in the very middle. | ||
export function Loader() { | ||
const loaderClassName = ['loader', styles.loader].join(' ') | ||
return ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would maybe just inline this, but do as you like. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Btw why do you also need to set 'loader' class here? I would imagine only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I prefer this 🤷
I wanted to give users a stable class name ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In that case, shouldn't we name it sometihng like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most people use Tailwind these days or one of the CSS-in-JS options, so I don't think there will be a lot of interference with built in classes. If it happens to happen, let's change it then. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So you are saying that our global CSS hopefully wont cause any issues because others might not use global CSS themselves? That is ok, but we can't count on that. Also, as a library/framework, we should at least try to not affect their global space if we can. I think we should do this now, it is an easy change and is a good practice and we know it has a potential to cause problems down the road: it would be downright sloppy to leave this as it is now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I can add the |
||
<SpinnerWrapper className="loader"> | ||
<Spinner /> | ||
<SpinnerAccessbilityText>Loading...</SpinnerAccessbilityText> | ||
</SpinnerWrapper> | ||
<div className={loaderClassName}> | ||
<div className={styles.loaderCircle} /> | ||
<div className={styles.loaderAccessibilityText}>Loading...</div> | ||
</div> | ||
) | ||
} | ||
|
||
const SpinnerWrapper = styled('div', { | ||
color: '$gray900', | ||
}) | ||
|
||
// Taken from Chakra UI Spinner component | ||
const Spinner = styled('div', { | ||
display: 'inline-block', | ||
borderTop: '2px solid currentcolor', | ||
borderRight: '2px solid currentcolor', | ||
borderBottomStyle: 'solid', | ||
borderLeftStyle: 'solid', | ||
borderRadius: '99999px', | ||
borderBottomWidth: '2px', | ||
borderLeftWidth: '2px', | ||
borderBottomColor: 'transparent', | ||
borderLeftColor: 'transparent', | ||
animation: `0.45s linear 0s infinite normal none running ${fullRotationKeyframes}`, | ||
width: 'var(--spinner-size)', | ||
height: 'var(--spinner-size)', | ||
'--spinner-size': '2rem', | ||
}) | ||
|
||
const SpinnerAccessbilityText = styled('span', { | ||
border: '0px', | ||
clip: 'rect(0px, 0px, 0px, 0px)', | ||
width: '1px', | ||
height: '1px', | ||
margin: '-1px', | ||
padding: '0px', | ||
overflow: 'hidden', | ||
whiteSpace: 'nowrap', | ||
position: 'absolute', | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrote it like this to enable users to adjust the loader color with CSS vars. It's undocumented but we can tell users that info if they ask.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is still local CSS, is it? Not global, right? Because of the ".module.css"? WHo is enabling this, Vite, or are we using something special?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Vite supports CSS modules out of the box: https://vitejs.dev/config/shared-options.html#css-modules