forked from tusen-ai/naive-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(float-button): new component (tusen-ai#5627)
* feat: create template * feat: add demo * feat: change to css * feat: add style * feat: add demo * feat: add demo * feat: add group * feat: add docs * feat: add log * fix: style error * feat: add docs
- Loading branch information
Showing
32 changed files
with
1,041 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export { | ||
default as NFloatButtonGroup, | ||
floatButtonGroupProps | ||
} from './src/FloatButtonGroup' | ||
export type { FloatButtonGroupProps } from './src/FloatButtonGroup' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import { | ||
h, | ||
type PropType, | ||
defineComponent, | ||
computed, | ||
type CSSProperties | ||
} from 'vue' | ||
import type { Size } from '../../button/src/interface' | ||
import { type ThemeProps, useConfig, useTheme } from '../../_mixins' | ||
import type { ExtractPublicPropTypes } from '../../_utils' | ||
import style from './styles/index.cssr' | ||
import floatButtonGroupLight, { | ||
type FloatButtonGroupTheme | ||
} from '../styles/light' | ||
|
||
export interface ButtonGroupInjection { | ||
size?: Size | undefined | ||
} | ||
|
||
export const floatButtonGroupProps = { | ||
...(useTheme.props as ThemeProps<FloatButtonGroupTheme>), | ||
width: { | ||
type: [Number, String] as PropType<string | number>, | ||
default: 'auto' | ||
}, | ||
height: { | ||
type: [Number, String] as PropType<string | number>, | ||
default: 'auto' | ||
}, | ||
left: { | ||
type: [Number, String] as PropType<string | number>, | ||
default: undefined | ||
}, | ||
right: { | ||
type: [Number, String] as PropType<string | number>, | ||
default: 40 | ||
}, | ||
top: { | ||
type: [Number, String] as PropType<string | number>, | ||
default: undefined | ||
}, | ||
bottom: { | ||
type: [Number, String] as PropType<string | number>, | ||
default: 40 | ||
}, | ||
radius: { | ||
type: [Number, String] as PropType<string | number>, | ||
default: 22 | ||
}, | ||
backgroundColor: String, | ||
vertical: Boolean | ||
} as const | ||
|
||
export type FloatButtonGroupProps = ExtractPublicPropTypes< | ||
typeof floatButtonGroupProps | ||
> | ||
|
||
export default defineComponent({ | ||
name: 'FloatButtonGroup', | ||
props: floatButtonGroupProps, | ||
setup (props) { | ||
const { mergedClsPrefixRef, inlineThemeDisabled } = useConfig(props) | ||
|
||
const themeRef = useTheme( | ||
'FloatButtonGroup', | ||
'-float-button-group', | ||
style, | ||
floatButtonGroupLight, | ||
props, | ||
mergedClsPrefixRef | ||
) | ||
|
||
const cssVarsRef = computed(() => { | ||
const { | ||
self: { color, textColor, boxShadow, boxShadowHover, boxShadowPressed }, | ||
common: { cubicBezierEaseInOut } | ||
} = themeRef.value | ||
return { | ||
'--n-bezier': cubicBezierEaseInOut, | ||
'--n-box-shadow': boxShadow, | ||
'--n-box-shadow-hover': boxShadowHover, | ||
'--n-box-shadow-pressed': boxShadowPressed, | ||
'--n-color': color, | ||
'--n-text-color': textColor, | ||
left: formatNumber(props.left), | ||
right: formatNumber(props.right), | ||
top: formatNumber(props.top), | ||
bottom: formatNumber(props.bottom), | ||
width: formatNumber(props.width), | ||
height: formatNumber(props.height), | ||
borderRadius: formatNumber(props.radius), | ||
backgroundColor: props.backgroundColor | ||
} | ||
}) | ||
|
||
const formatNumber = ( | ||
value: number | string | undefined | ||
): string | undefined => { | ||
if (typeof value === 'number') return `${value}px` | ||
return value | ||
} | ||
|
||
return { | ||
cssVars: inlineThemeDisabled ? undefined : cssVarsRef, | ||
mergedClsPrefix: mergedClsPrefixRef, | ||
formatNumber | ||
} | ||
}, | ||
render () { | ||
const { mergedClsPrefix, cssVars } = this | ||
return ( | ||
<div | ||
class={[ | ||
`${mergedClsPrefix}-float-button-group`, | ||
this.vertical && `${mergedClsPrefix}-float-button-group--vertical` | ||
]} | ||
style={cssVars as CSSProperties} | ||
role="group" | ||
> | ||
{this.$slots} | ||
</div> | ||
) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { cB, cM, cNotM } from '../../../_utils/cssr/index' | ||
|
||
export default cB('float-button-group', ` | ||
position: fixed; | ||
cursor: pointer; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
color: var(--n-text-color); | ||
transition: | ||
color .3s var(--n-bezier), | ||
box-shadow .3s var(--n-bezier), | ||
background-color .3s var(--n-bezier); | ||
`, [ | ||
cNotM('vertical', { | ||
flexDirection: 'row' | ||
}, [ | ||
|
||
]), | ||
cM('vertical', { | ||
flexDirection: 'column' | ||
}, [ | ||
]) | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { commonDark } from '../../_styles/common' | ||
import type { FloatButtonGroupTheme } from './light' | ||
|
||
const floatButtonGroupDark: FloatButtonGroupTheme = { | ||
name: 'FloatButtonGroup', | ||
common: commonDark, | ||
self (vars) { | ||
const { popoverColor, textColor2 } = vars | ||
return { | ||
color: popoverColor, | ||
textColor: textColor2, | ||
boxShadow: '0 2px 8px 0px rgba(0, 0, 0, .12)', | ||
boxShadowHover: '0 2px 12px 0px rgba(0, 0, 0, .18)', | ||
boxShadowPressed: '0 2px 12px 0px rgba(0, 0, 0, .18)' | ||
} | ||
} | ||
} | ||
|
||
export default floatButtonGroupDark |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { default as floatButtonGroupDark } from './dark' | ||
export { default as floatButtonGroupLight } from './light' | ||
export type { FloatButtonGroupTheme } from './light' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { type Theme } from '../../_mixins' | ||
import { type ThemeCommonVars } from '../../config-provider' | ||
import { commonLight } from '../../styles' | ||
|
||
const self = (vars: ThemeCommonVars) => { | ||
const { popoverColor, textColor2 } = vars | ||
return { | ||
color: popoverColor, | ||
textColor: textColor2, | ||
boxShadow: '0 2px 8px 0px rgba(0, 0, 0, .12)', | ||
boxShadowHover: '0 2px 12px 0px rgba(0, 0, 0, .18)', | ||
boxShadowPressed: '0 2px 12px 0px rgba(0, 0, 0, .18)' | ||
} | ||
} | ||
|
||
export type FloatButtonGroupThemeVars = ReturnType<typeof self> | ||
|
||
const themeLight: Theme<'FloatButtonGroup', FloatButtonGroupThemeVars> = { | ||
name: 'FloatButtonGroup', | ||
common: commonLight, | ||
self | ||
} | ||
|
||
export default themeLight | ||
export type FloatButtonGroupTheme = typeof themeLight |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<markdown> | ||
# Badge | ||
|
||
You can put a hover button with the number of badges on any element. | ||
|
||
</markdown> | ||
|
||
<template> | ||
<div style="height: 200px; transform: translate(0)"> | ||
<n-float-button :right="0" :bottom="0"> | ||
<n-badge :value="9" :offset="[6, -8]"> | ||
<n-icon :size="22" color="grey"> | ||
<alarm-outline-icon /> | ||
</n-icon> | ||
</n-badge> | ||
</n-float-button> | ||
<n-float-button :right="70" :bottom="0"> | ||
<n-badge :value="100" :max="99" :offset="[6, -8]"> | ||
<n-icon :size="22" color="grey"> | ||
<alarm-outline-icon /> | ||
</n-icon> | ||
</n-badge> | ||
</n-float-button> | ||
<n-float-button :right="142" :bottom="0"> | ||
<n-badge dot :offset="[4, -4]"> | ||
<n-icon :size="22" color="grey"> | ||
<alarm-outline-icon /> | ||
</n-icon> | ||
</n-badge> | ||
</n-float-button> | ||
<n-float-button :right="142" :bottom="0"> | ||
<n-badge dot :offset="[4, -4]"> | ||
<n-icon :size="22" color="grey"> | ||
<alarm-outline-icon /> | ||
</n-icon> | ||
</n-badge> | ||
</n-float-button> | ||
<n-float-button :right="0" :bottom="60"> | ||
<n-badge value="New" :offset="[10, -10]"> | ||
<n-icon :size="22" color="grey"> | ||
<alarm-outline-icon /> | ||
</n-icon> | ||
</n-badge> | ||
</n-float-button> | ||
<n-float-button :right="70" :bottom="60"> | ||
<n-badge :value="9" :offset="[6, -8]" color="grey"> | ||
<n-icon :size="22" color="grey"> | ||
<alarm-outline-icon /> | ||
</n-icon> | ||
</n-badge> | ||
</n-float-button> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { AlarmOutline as AlarmOutlineIcon } from '@vicons/ionicons5' | ||
import { defineComponent } from 'vue' | ||
export default defineComponent({ | ||
components: { | ||
AlarmOutlineIcon | ||
} | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<markdown> | ||
# Basic | ||
</markdown> | ||
|
||
<template> | ||
<div style="height: 200px; transform: translate(0)"> | ||
<n-float-button :right="0" :bottom="0"> | ||
<n-icon :size="24"> | ||
<cash-icon /> | ||
</n-icon> | ||
</n-float-button> | ||
<n-float-button :left="0" :bottom="0"> | ||
<n-icon :size="24"> | ||
<cash-icon /> | ||
</n-icon> | ||
</n-float-button> | ||
<n-float-button :right="0" :top="0"> | ||
<n-icon :size="24"> | ||
<cash-icon /> | ||
</n-icon> | ||
</n-float-button> | ||
<n-float-button :left="0" :top="0"> | ||
<n-icon :size="24"> | ||
<cash-icon /> | ||
</n-icon> | ||
</n-float-button> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { CashOutline as CashIcon } from '@vicons/ionicons5' | ||
import { defineComponent } from 'vue' | ||
export default defineComponent({ | ||
components: { | ||
CashIcon | ||
} | ||
}) | ||
</script> |
Oops, something went wrong.