mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2024-12-09 04:31:35 +08:00
feat(spin): clsPrefix
This commit is contained in:
parent
013bd0de9b
commit
ba0164bc77
@ -1,2 +1,2 @@
|
|||||||
/* istanbul ignore file */
|
|
||||||
export { default as NSpin } from './src/Spin'
|
export { default as NSpin } from './src/Spin'
|
||||||
|
export type { SpinProps } from './src/Spin'
|
||||||
|
@ -8,9 +8,9 @@ import {
|
|||||||
} from 'vue'
|
} from 'vue'
|
||||||
import { useCompitable } from 'vooks'
|
import { useCompitable } from 'vooks'
|
||||||
import { NBaseLoading } from '../../_internal'
|
import { NBaseLoading } from '../../_internal'
|
||||||
import { useTheme } from '../../_mixins'
|
import { useConfig, useTheme } from '../../_mixins'
|
||||||
import type { ThemeProps } from '../../_mixins'
|
import type { ThemeProps } from '../../_mixins'
|
||||||
import { createKey, warn } from '../../_utils'
|
import { createKey, ExtractPublicPropTypes, warn } from '../../_utils'
|
||||||
import { spinLight } from '../styles'
|
import { spinLight } from '../styles'
|
||||||
import type { SpinTheme } from '../styles'
|
import type { SpinTheme } from '../styles'
|
||||||
import style from './styles/index.cssr'
|
import style from './styles/index.cssr'
|
||||||
@ -21,38 +21,51 @@ const STROKE_WIDTH = {
|
|||||||
large: 18
|
large: 18
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const spinProps = {
|
||||||
|
...(useTheme.props as ThemeProps<SpinTheme>),
|
||||||
|
stroke: {
|
||||||
|
type: String,
|
||||||
|
default: undefined
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
type: [String, Number] as PropType<'small' | 'medium' | 'large'>,
|
||||||
|
default: 'medium'
|
||||||
|
},
|
||||||
|
show: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
strokeWidth: {
|
||||||
|
type: Number,
|
||||||
|
default: undefined
|
||||||
|
},
|
||||||
|
spinning: {
|
||||||
|
type: Boolean,
|
||||||
|
validator: () => {
|
||||||
|
warn('spin', '`spinning` is deprecated, please use `show` instead.')
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
default: undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export type SpinProps = ExtractPublicPropTypes<typeof spinProps>
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'Spin',
|
name: 'Spin',
|
||||||
props: {
|
props: spinProps,
|
||||||
...(useTheme.props as ThemeProps<SpinTheme>),
|
|
||||||
stroke: {
|
|
||||||
type: String,
|
|
||||||
default: undefined
|
|
||||||
},
|
|
||||||
size: {
|
|
||||||
type: [String, Number] as PropType<'small' | 'medium' | 'large'>,
|
|
||||||
default: 'medium'
|
|
||||||
},
|
|
||||||
show: {
|
|
||||||
type: Boolean,
|
|
||||||
default: true
|
|
||||||
},
|
|
||||||
strokeWidth: {
|
|
||||||
type: Number,
|
|
||||||
default: undefined
|
|
||||||
},
|
|
||||||
spinning: {
|
|
||||||
type: Boolean,
|
|
||||||
validator: () => {
|
|
||||||
warn('spin', '`spinning` is deprecated, please use `show` instead.')
|
|
||||||
return true
|
|
||||||
},
|
|
||||||
default: undefined
|
|
||||||
}
|
|
||||||
},
|
|
||||||
setup (props) {
|
setup (props) {
|
||||||
const themeRef = useTheme('Spin', 'Spin', style, spinLight, props)
|
const { mergedClsPrefix } = useConfig(props)
|
||||||
|
const themeRef = useTheme(
|
||||||
|
'Spin',
|
||||||
|
'Spin',
|
||||||
|
style,
|
||||||
|
spinLight,
|
||||||
|
props,
|
||||||
|
mergedClsPrefix
|
||||||
|
)
|
||||||
return {
|
return {
|
||||||
|
cPrefix: mergedClsPrefix,
|
||||||
compitableShow: useCompitable(props, ['spinning', 'show']),
|
compitableShow: useCompitable(props, ['spinning', 'show']),
|
||||||
mergedStrokeWidth: computed(() => {
|
mergedStrokeWidth: computed(() => {
|
||||||
const { strokeWidth } = props
|
const { strokeWidth } = props
|
||||||
@ -76,15 +89,16 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
render () {
|
render () {
|
||||||
const { $slots } = this
|
const { $slots, cPrefix } = this
|
||||||
return $slots.default ? (
|
return $slots.default ? (
|
||||||
<div class="n-spin-container" style={this.cssVars as CSSProperties}>
|
<div
|
||||||
|
class={`${cPrefix}-spin-container`}
|
||||||
|
style={this.cssVars as CSSProperties}
|
||||||
|
>
|
||||||
<div
|
<div
|
||||||
class={[
|
class={[
|
||||||
'n-spin-content',
|
`${cPrefix}-spin-content`,
|
||||||
{
|
this.compitableShow && `${cPrefix}-spin-content--spinning`
|
||||||
'n-spin-content--spinning': this.compitableShow
|
|
||||||
}
|
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
{$slots}
|
{$slots}
|
||||||
@ -94,9 +108,10 @@ export default defineComponent({
|
|||||||
default: () =>
|
default: () =>
|
||||||
this.compitableShow ? (
|
this.compitableShow ? (
|
||||||
<NBaseLoading
|
<NBaseLoading
|
||||||
|
clsPrefix={cPrefix}
|
||||||
stroke={this.stroke}
|
stroke={this.stroke}
|
||||||
strokeWidth={this.mergedStrokeWidth}
|
strokeWidth={this.mergedStrokeWidth}
|
||||||
class="n-spin"
|
class={`${cPrefix}-spin`}
|
||||||
/>
|
/>
|
||||||
) : null
|
) : null
|
||||||
}}
|
}}
|
||||||
@ -104,10 +119,11 @@ export default defineComponent({
|
|||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<NBaseLoading
|
<NBaseLoading
|
||||||
|
clsPrefix={cPrefix}
|
||||||
style={this.cssVars as CSSProperties}
|
style={this.cssVars as CSSProperties}
|
||||||
stroke={this.stroke}
|
stroke={this.stroke}
|
||||||
stroke-width={this.mergedStrokeWidth}
|
stroke-width={this.mergedStrokeWidth}
|
||||||
class="n-spin"
|
class={`${cPrefix}-spin`}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user