Skip to content

Commit

Permalink
Merge pull request #49 from 46ki75/feature/cube
Browse files Browse the repository at this point in the history
Feature/cube
  • Loading branch information
46ki75 authored Oct 27, 2024
2 parents d56adb2 + c86f558 commit 47fdb05
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/components/fallback/FullscreenFallback.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import React from 'react'

import { DotLoadingIcon } from '../icon/DotLoadingIcon'

import { RectangleWave } from './RectangleWave'

import isEqual from 'react-fast-compare'

import styles from './FullscreenFallback.module.scss'
import { Cube } from '../icon/Cube'

// # --------------------------------------------------------------------------------
//
Expand Down Expand Up @@ -45,7 +44,7 @@ const FullscreenFallbackComponent = ({
}}
>
<RectangleWave color='rgba(128,128,128,0.8)' />
<DotLoadingIcon size={64} color='rgba(128,128,128,0.8)' />
<Cube size={64} isDark={isDark} />
</div>
)
}
Expand Down
31 changes: 31 additions & 0 deletions src/components/icon/Cube.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.cube {
position: relative;
transform-style: preserve-3d;
transform: rotateX(-30deg) rotateY(-45deg);
animation: rotate 1500ms infinite linear;
}

.face {
position: absolute;
width: 100%;
height: 100%;
border-width: 1px;
border-style: solid;
border-radius: 2px;
display: flex;
justify-content: center;
align-items: center;
font-weight: bold;
color: gray;
backface-visibility: hidden;
user-select: none;
}

@keyframes rotate {
from {
transform: rotateX(-30deg) rotateY(-45deg) rotateZ(0deg);
}
to {
transform: rotateX(-30deg) rotateY(315deg) rotateZ(360deg);
}
}
15 changes: 15 additions & 0 deletions src/components/icon/Cube.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { Meta, StoryObj } from '@storybook/react'
import { Cube } from './Cube'

const meta: Meta<typeof Cube> = {
title: 'Components/Icon/Cube',
component: Cube,
tags: ['autodocs']
}

export default meta
type Story = StoryObj<typeof meta>

export const Primary: Story = {
args: { style: {} }
}
72 changes: 72 additions & 0 deletions src/components/icon/Cube.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import React from 'react'
import isEqual from 'react-fast-compare'

import styles from './Cube.module.scss'

// # --------------------------------------------------------------------------------
//
// props
//
// # --------------------------------------------------------------------------------

export interface CubeProps {
style?: React.CSSProperties
size?: number

/**
* Whether or not to use the dark theme
*/
isDark?: boolean
}

// # --------------------------------------------------------------------------------
//
// component
//
// # --------------------------------------------------------------------------------

const CubeComponent = ({ style, size = 128, isDark = false }: CubeProps) => {
const commonTranslateZ = `translateZ(${size / 2}px)`

const faces = [
{ name: 'front', rotate: '' },
{ name: 'back', rotate: 'rotateY(180deg)' },
{ name: 'left', rotate: 'rotateY(-90deg)' },
{ name: 'right', rotate: 'rotateY(90deg)' },
{ name: 'top', rotate: 'rotateX(90deg)' },
{ name: 'bottom', rotate: 'rotateX(-90deg)' }
]

return (
<div
className={styles.cube}
style={{
width: `${size}px`,
height: `${size}px`,
...style
}}
>
{faces.map((face) => (
<div
key={face.name}
className={styles.face}
style={{
transform: `${face.rotate} ${commonTranslateZ}`,
backgroundColor: isDark
? 'rgba(0,0,0,0.2)'
: 'rgba(255,255,255,0.2)',
borderColor: !isDark ? 'rgba(0,0,0,0.8)' : 'rgba(255,255,255,0.8)'
}}
></div>
))}
</div>
)
}

// # --------------------------------------------------------------------------------
//
// memoize
//
// # --------------------------------------------------------------------------------

export const Cube = React.memo(CubeComponent, isEqual)

0 comments on commit 47fdb05

Please sign in to comment.