Skip to content

Commit

Permalink
Merge pull request #15 from Barba828/feat-layout
Browse files Browse the repository at this point in the history
Feat layout
  • Loading branch information
Barba828 authored Jan 22, 2024
2 parents 836fb00 + 54049a5 commit 42defc6
Show file tree
Hide file tree
Showing 27 changed files with 980 additions and 129 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
1 change: 1 addition & 0 deletions packages/buitar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"eslint": "^8.45.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.3",
"postcss-preset-env": "^9.3.0",
"sass": "^1.49.9",
"typescript": "^5.0.2",
"vite": "^4.4.5",
Expand Down
1 change: 0 additions & 1 deletion packages/buitar/src/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ body {
height: 100%;
overflow-x: hidden;
padding-left: 10vw;
padding-top: 5vh;
}

@media #{$pcLayout} {
Expand Down
23 changes: 12 additions & 11 deletions packages/buitar/src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BrowserRouter, useRoutes } from 'react-router-dom'
import { ConfigProvider, SlideMenu, AudioBtn, BoardProvider } from '@/components'
import { ConfigProvider, SlideMenu, FixedBtns, BoardProvider, PageHeader } from '@/components'
import { routeConfig } from '@/pages/router'
import { Suspense } from 'react'
import { HelmetProvider } from 'react-helmet-async'
Expand All @@ -11,9 +11,13 @@ export const App = () => {
<BrowserRouter>
<ConfigProvider>
<HelmetProvider>
<SlideMenu />
<Board />
<AudioBtn />
<BoardProvider>
<DrumProvider>
<SlideMenu />
<Board />
<FixedBtns />
</DrumProvider>
</BoardProvider>
</HelmetProvider>
</ConfigProvider>
</BrowserRouter>
Expand All @@ -23,12 +27,9 @@ export const App = () => {
const Board = () => {
const element = useRoutes(routeConfig)
return (
<BoardProvider>
<DrumProvider>
<main id="board">
<Suspense fallback={<div>Loading...</div>}>{element}</Suspense>
</main>
</DrumProvider>
</BoardProvider>
<main id="board">
<PageHeader />
<Suspense fallback={<div>Loading...</div>}>{element}</Suspense>
</main>
)
}
1 change: 0 additions & 1 deletion packages/buitar/src/components/audio-btn/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
.audio-btn {
position: fixed;
right: 20px;
top: 20px;
width: 32px !important;
height: 32px !important;
width: 32px;
height: 32px;
cursor: pointer;
background: none;
border: none;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { FC, memo, useEffect, useState } from 'react'
import { Icon } from '@/components/icon'
import cx from 'classnames'
import * as Tone from 'tone'

import styles from './audio-btn.module.scss'
import { TonePlayer } from '@buitar/tone-player'
import { waitAudioContext } from '@/utils/audio-play'

import styles from './audio-btn.module.scss'

/**
* audioContext状态开关
*/
export const AudioBtn: FC = memo(() => {
export const AudioBtn: FC<React.HTMLAttributes<HTMLButtonElement>> = memo((props) => {
const [mute, setMute] = useState<Boolean>(Tone.context.state !== 'running')
const context = (window.tonePlayer as TonePlayer).context || Tone.context

Expand All @@ -28,7 +28,7 @@ export const AudioBtn: FC = memo(() => {
return (
<button
className={cx(
// 'primary-button',
props.className,
styles['audio-btn'],
!mute && styles['audio-btn__hidden']
)}
Expand Down
23 changes: 23 additions & 0 deletions packages/buitar/src/components/fixed-btn/fixed-btns.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.btn-group {
position: fixed;
right: 20px;
bottom: 100px;
z-index: 99;
}
.btn {
width: 32px;
height: 32px;
cursor: pointer;
margin: $space-6;
background: $gray-02;
border-radius: 50%;
border: none;
color: inherit;
opacity: 0.8;
@include flex-center;
@media (any-hover: hover) {
&:hover {
background: $gray-03;
}
}
}
14 changes: 14 additions & 0 deletions packages/buitar/src/components/fixed-btn/fixed-btns.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { FC } from 'react'
import { AudioBtn } from './audio-btn'
import { SettingBtn } from './setting-btn'

import styles from './fixed-btns.module.scss'

export const FixedBtns: FC<{}> = () => {
return (
<div className={styles['btn-group']}>
<AudioBtn className={styles['btn']}></AudioBtn>
<SettingBtn className={styles['btn']}></SettingBtn>
</div>
)
}
2 changes: 2 additions & 0 deletions packages/buitar/src/components/fixed-btn/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './audio-btn'
export * from './fixed-btns'
21 changes: 21 additions & 0 deletions packages/buitar/src/components/fixed-btn/setting-btn.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { FC, memo, useState, useCallback } from 'react'
import { BoardOptionsController, Icon, Modal } from '@/components'

export const SettingBtn: FC<React.HTMLAttributes<HTMLButtonElement>> = memo((props) => {
const [settingModalVisible, setSettingModalVisible] = useState<boolean>(false)
const toggleSettingModalVisible = useCallback(() => {
setSettingModalVisible(!settingModalVisible)
}, [settingModalVisible])
return (
<button id="setting-btn" className={props.className}>
<Icon name="icon-setting" onClick={toggleSettingModalVisible} />
<Modal
visible={settingModalVisible}
onCancel={toggleSettingModalVisible}
onConfirm={toggleSettingModalVisible}
>
<BoardOptionsController />
</Modal>
</button>
)
})
4 changes: 2 additions & 2 deletions packages/buitar/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ export * from './drum-board'
export * from './sound-board'
export * from './sequencer'
export * from './guitar-player'
export * from './pages-intro'
export * from './pages-info'

export * from './ui'
export * from './slide-menu'
export * from './portal'
export * from './icon'
export * from './svg-chord'
export * from './audio-btn'
export * from './fixed-btn'
3 changes: 3 additions & 0 deletions packages/buitar/src/components/pages-info/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { PagesIntro } from './pages-intro.component'
export { PageHeader } from './page-header.component'
export { PagesMeta } from './pages-meta'
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { useMemo, memo } from 'react'
import { useRouteMatch } from '@/utils/hooks/use-routers'
import { Icon } from '@/components/icon'
import { useNavigate } from 'react-router-dom'

import styles from './page-header.module.scss'

export const PageHeader = memo(() => {
const curRoute = useRouteMatch()
const navigate = useNavigate()
const showBack = useMemo(() => !!curRoute?.meta?.back, [curRoute])

if(showBack){
return (
<header className={styles['page-header']} onClick={() => navigate(-1)}>
<Icon name="icon-back" size={16}></Icon>
<h2>{curRoute.name}</h2>
</header>
)
}

return null

})
10 changes: 10 additions & 0 deletions packages/buitar/src/components/pages-info/page-header.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.page-header {
display: flex;
align-items: center;
cursor: pointer;

> h2 {
margin: $font-16 $font-10;
font-size: $font-20;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC } from 'react'
import { memo } from 'react'
import { pagesIntroConfig } from '@/pages/pages.config'
import { useTopRoute } from '@/utils/hooks/use-routers'

Expand All @@ -7,7 +7,7 @@ import styles from './pages-intro.module.scss'
/**
* 页面介绍
*/
const PagesIntro: FC = () => {
export const PagesIntro = memo(() => {
const curTopRoute = useTopRoute()
if (!curTopRoute?.id) {
return null
Expand All @@ -22,14 +22,11 @@ const PagesIntro: FC = () => {
const { title, content } = pageInfo

return (
<div className={styles['pages-intro']}>
<section className={styles['pages-intro']}>
<h2>{title}</h2>
{content.map((item, index) => (
<p key={index}>{item}</p>
))}
</div>
</section>
)
}

export { PagesIntro }
export { PagesMeta } from './pages-meta'
})
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.pages-intro {
padding-right: 10%;
opacity: 0.7;
margin-bottom: 5%;
margin-bottom: 5vh;

h2 {
letter-spacing: 0.5px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const Modal: FC<ModalProps> = ({ visible, pure, title, children, onConfir

return (
<PortalInner>
<div className="modal flex-center">
<div className="modal flex-center fade-in">
{pure ? (
children
) : (
Expand All @@ -41,7 +41,7 @@ export const Modal: FC<ModalProps> = ({ visible, pure, title, children, onConfir
) : (
title
)}

{children}

<div className={styles['modal-options']}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
max-height: 92vh;
overflow-y: scroll;
background: $gray-01;
padding: $btn-margin;
padding: calc($btn-margin * 2);
border-radius: calc($btn-margin * 4);

.modal-options {
display: flex;
Expand All @@ -13,6 +14,7 @@
:global(.primary-button) {
height: calc($btn-size);
flex: 1;
border-radius: calc($btn-margin * 3);
}
}

Expand Down
Loading

0 comments on commit 42defc6

Please sign in to comment.