1
0
mirror of https://github.com/phuoc-ng/csslayout.git synced 2025-08-08 07:07:15 +02:00
Files
csslayout/client/loaders/DetailsLoader.tsx
2021-04-01 17:04:26 +07:00

54 lines
1.7 KiB
TypeScript

/**
* A collection of popular layouts and patterns made with CSS (https://csslayout.io)
* (c) 2019 - 2021 Nguyen Huu Phuoc <https://twitter.com/nghuuphuoc>
*/
import loadable, { LoadableComponent } from '@loadable/component';
import * as React from 'react';
import './spinner.css';
interface DetailsLoaderProps {
pattern: string;
}
const slug = (item: string) => item.toLowerCase().split(' ').join('-');
// In order to create a link to another page that is dynamically loaded (via <Link to="...">),
// the page chunks have to be loadable by @loadable.
// We have to add a magic comment /* #__LOADABLE__ */ here
// and the following plugin to Babel's settings (.babelrc):
// {
// "plugins": ["@loadable/babel-plugin"],
// }
const loadDetails = /* #__LOADABLE__ */ (props: DetailsLoaderProps) => import(`../patterns/${slug(props.pattern)}/Details`);
const DetailsLoader: LoadableComponent<DetailsLoaderProps> = loadable(loadDetails, {
fallback: (
<div
style={{
alignItems: 'center',
display: 'flex',
height: '100%',
justifyContent: 'center',
width: '100%',
}}
>
<svg className="spinner" width="64px" height="64px" viewBox="0 0 32 32">
<circle
cx="16"
cy="16"
fill="none"
r="12"
stroke="rgba(0, 0, 0, 0.4)"
strokeDasharray={Math.PI * 2 * 9}
strokeLinecap="round"
strokeWidth="4"
/>
</svg>
</div>
),
});
export default DetailsLoader;