Skip to content

Commit

Permalink
Optimize upload component styles
Browse files Browse the repository at this point in the history
  • Loading branch information
trheyi committed Nov 1, 2024
1 parent d43b7a1 commit 37fd352
Show file tree
Hide file tree
Showing 24 changed files with 452 additions and 984 deletions.
13 changes: 9 additions & 4 deletions packages/xgen/build/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,23 @@ const target_root = path.join(cwd, `/public/components`)
// Generate the sss files for the components
const compile = (name: string, component: ExportComponent) => {
const output = path.join(target_root, `${name}`)
const input = path.join(cwd, `__main.less`)

// Clean the output directory
if (fs.existsSync(output)) {
fs.rmSync(output, { recursive: true })
}

// Generate the main.less file import the component styles
const imports: string[] = []
component.styles.forEach((style, index) => {
let chunkIndex = 0
component.styles.forEach((style) => {
if (style.startsWith('@/')) {
imports.push(`@import url('/__yao_admin_root/${style.substring(2, style.length)}');`)
return
}
// fs.appendFileSync(input, `@import ".${style}";\n`)
chunkIndex++
const lessFile = path.join(cwd, style)
const targetName = `chunk.${index}.css`
const targetName = `chunk.${chunkIndex}.css`
const targetPath = path.join(output, targetName)
imports.push(`@import url('/__yao_admin_root/components/${name}/${targetName}');`)

Expand Down
35 changes: 0 additions & 35 deletions packages/xgen/components/edit/Upload/components/Audio.less

This file was deleted.

5 changes: 2 additions & 3 deletions packages/xgen/components/edit/Upload/components/Audio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { DefaultAudioLayout, DefaultLayoutIcons, defaultLayoutIcons } from '@vid
import { useGlobal } from '@/context/app'
import '@vidstack/react/player/styles/default/theme.css'
import '@vidstack/react/player/styles/default/layouts/audio.css'
import styles from './Audio.less'
import clsx from 'clsx'
import { GetPreviewURL } from '../utils/handleFileList'
import Toolbar from './Toolbar'
Expand Down Expand Up @@ -43,7 +42,7 @@ const Index = (props: IPropsCustomRender) => {

return (
<div
className={clsx([styles._local, 'upload_custom_wrap', 'flex', 'relative'])}
className={clsx(['xgen-edit-upload-preview-wrap', 'preview-audio', 'flex', 'relative'])}
onMouseEnter={() => setShowOpration(true)}
onMouseLeave={() => setShowOpration(false)}
>
Expand All @@ -66,7 +65,7 @@ const Index = (props: IPropsCustomRender) => {
>
<MediaPlayer
style={{ height: '52px', width: size?.width || '100%' }}
className={clsx([styles._local])}
className={clsx(['mediaplayer_wrap'])}
title={title}
src={url + `&${file.name}`}
>
Expand Down
42 changes: 0 additions & 42 deletions packages/xgen/components/edit/Upload/components/File.less

This file was deleted.

3 changes: 1 addition & 2 deletions packages/xgen/components/edit/Upload/components/File.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Icon } from '@/widgets'

import '@vidstack/react/player/styles/default/theme.css'
import '@vidstack/react/player/styles/default/layouts/audio.css'
import styles from './File.less'
import clsx from 'clsx'
import { GetPreviewURL } from '../utils/handleFileList'
import Toolbar from './Toolbar'
Expand Down Expand Up @@ -36,7 +35,7 @@ const Index = (props: IPropsCustomRender) => {

return (
<div
className={clsx([styles._local, 'upload_custom_wrap', 'flex', 'relative'])}
className={clsx(['xgen-edit-upload-preview-wrap', 'preview-file', 'flex', 'relative'])}
onMouseEnter={() => setShowOpration(true)}
onMouseLeave={() => setShowOpration(false)}
>
Expand Down
7 changes: 0 additions & 7 deletions packages/xgen/components/edit/Upload/components/Image.less

This file was deleted.

9 changes: 1 addition & 8 deletions packages/xgen/components/edit/Upload/components/Image.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { IPropsCustomRender } from '../types'
import { useEffect, useState } from 'react'

import styles from './Image.less'
import clsx from 'clsx'
import { GetPreviewURL } from '../utils/handleFileList'
import Loader from './Loader'
Expand All @@ -27,13 +26,7 @@ const Index = (props: IPropsCustomRender) => {

return (
<div
className={clsx([
styles['xgen-edit-upload-image'],
'xgen-edit-upload-image',
'upload_custom_wrap',
'flex',
'relative'
])}
className={clsx(['xgen-edit-upload-preview-wrap', 'preview-image', 'flex', 'relative'])}
onMouseEnter={() => setShowOpration(true)}
onMouseLeave={() => setShowOpration(false)}
>
Expand Down
70 changes: 0 additions & 70 deletions packages/xgen/components/edit/Upload/components/Loader.less

This file was deleted.

21 changes: 9 additions & 12 deletions packages/xgen/components/edit/Upload/components/Loader.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import clsx from 'clsx'
import type { IPropsLoader } from '../types'
import styles from './Loader.less'

const Index = (props: IPropsLoader) => {
const { size, events, remove } = props
const { size, events } = props
const ProgressBar = () => {
const percent = events?.progress?.total
? Math.floor(((events?.progress?.loaded || 0) / events?.progress?.total) * 100)
Expand All @@ -14,14 +13,12 @@ const Index = (props: IPropsLoader) => {
const humanReadable = `${percent}%`

return (
<div className={clsx([styles.progress_wrap, events?.error && styles.has_error])}>
<div className={styles.progress}>
<div className={styles.bar} style={{ width: humanReadable }}></div>
<div className={clsx(['progress_wrap', events?.error && 'has_error'])}>
<div className={'progress'}>
<div className={'bar'} style={{ width: humanReadable }}></div>
</div>
<div className={styles.text}>
<span className={styles.percent}>
{events?.error ? events?.error.message : humanReadable}
</span>
<div className={'text'}>
<span className={'percent'}>{events?.error ? events?.error.message : humanReadable}</span>
{(events?.progress?.total || 0) > 0 && !events?.error && (
<span>
{loadedMB}MB / {totalMB}MB
Expand All @@ -35,9 +32,9 @@ const Index = (props: IPropsLoader) => {
const Loading = (
<div
className={clsx([
styles._local,
events?.error && styles.has_error,
'xgen-upload xgen-upload-select xgen-upload-select-picture-card'
'xgen-edit-upload-preview-loader',
'xgen-upload xgen-upload-select xgen-upload-select-picture-card',
events?.error && 'has_error'
])}
style={{
width: size?.width || '90px',
Expand Down
21 changes: 0 additions & 21 deletions packages/xgen/components/edit/Upload/components/Video.less

This file was deleted.

5 changes: 2 additions & 3 deletions packages/xgen/components/edit/Upload/components/Video.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { useGlobal } from '@/context/app'
import '@vidstack/react/player/styles/default/theme.css'
import '@vidstack/react/player/styles/default/layouts/video.css'

import styles from './Video.less'
import clsx from 'clsx'
import { GetPreviewURL } from '../utils/handleFileList'
import Loader from './Loader'
Expand Down Expand Up @@ -45,7 +44,7 @@ const Index = (props: IPropsCustomRender) => {

return (
<div
className={clsx([styles._local, 'upload_custom_wrap', 'flex', 'relative'])}
className={clsx(['xgen-edit-upload-preview-wrap', 'preview-video', 'flex', 'relative'])}
onMouseEnter={() => setShowOpration(true)}
onMouseLeave={() => setShowOpration(false)}
>
Expand All @@ -72,7 +71,7 @@ const Index = (props: IPropsCustomRender) => {
height: size?.height || '162px',
width: size?.width
}}
className={clsx([styles._local])}
className={clsx(['mediaplayer_wrap'])}
title={title}
src={url + `&${file.name}`}
>
Expand Down
Loading

0 comments on commit 37fd352

Please sign in to comment.