kitze / twizzy-landing
- суббота, 24 ноября 2018 г. в 00:15:20
JavaScript
The landing page for Twizzy, built with React 16.7
It's CRA 2
with customize-cra
and react-app-rewired
.
The config file is adding/changing the following:
babel-plugin-styled-components
inline-react-svg
to inline svg files (I know CRA has this functionality but you import every file in a specific way)The magic happens in components/App/index.js
All of the hooks are in utils/hooks.js
useCanHover
- detect if the device supports hover, if it doesn't, use onClick
for the "tweeting" buttonuseToggleBodyClass
- toggle a body class based on a boolean. Used to trigger dark/light
and scroll/no-scroll
classes on the body
tag.useGoogleAnalytics
- inserts a google analytics script, but only when the app is readyuseMousePosition
- track the mouse position. It's used to detect if the user is over the menu bar, otherwise the tweet composer gets glitchy.I'll move these hooks to react-hanger soon.
LoadScript
Yeah, yeah, I know we shouldn't use react-cache
yet, but YOLO.
I made this LoadScript component to delay the loading of the Paddle script for payments until the page is ready.
Suspense
wants you to put alternative UI in the fallback
prop, and I didn't want an alternative UI, I just wanted the Buy
button to be disabled until the script is ready, so I used render propsstartLoading
to true and it starts loading the Paddle script.Buy
button is disabled. The user woulnd't click the button in the first few seconds anyway.Script
component.desertLoaded
boolean to detect when the dark image is completely loaded, and fade it in (otherwise it would look ugly on slow connections)setTimeout
for the amount of ms. There is more info in this article.It's really nothing fancy, just couple of styled divs. I feel a bit guilty because it's completely inaccessible by keyboard users.
So, z-index has been driving me crazy for a long time, so I decided to simplify the logic by ordering all elements in an order
array and then using ...zIndexFor(ELEMENTS.COMPOSE)
in the styles for the component that needs z-index. Smooth.
The app has a dark and a light mode, and all the logic for them is in styles/themes.js.
Other components can use the themes either by destructuring the theme
prop, or with the following mixins:
whenTheme
- It applies style only when the certain theme name is active. Exapmle: whenTheme('dark', {backgroundColor: 'black})
applyTheme
- It applies certain theme styles to the element. Example: applyTheme('windowBar')
will get the theme.windowBar
styles from the current theme
getThemeColor
- It reads a certain color from the current theme. Example: getThemeColor('icon')
will return the icon color for the current theme.
Just open an issue if you're interested about anything else in the app, and I'll add it in the readme.
All of the materials for the upcoming React Academy workshops are using hooks and Suspense. If your company or conference is interested in a beginner or an advanced workshop just get in touch.