mirror of
				https://github.com/antd-tiny-vue/antd-tiny-vue.git
				synced 2025-10-31 16:51:45 +08:00 
			
		
		
		
	feat: add wave
This commit is contained in:
		
							
								
								
									
										12
									
								
								components/_util/wave/index.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								components/_util/wave/index.tsx
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | |||||||
|  | import { defineComponent } from 'vue' | ||||||
|  |  | ||||||
|  | const Wave = defineComponent({ | ||||||
|  |   name: 'Wave', | ||||||
|  |   setup(_, { slots }) { | ||||||
|  |     return () => { | ||||||
|  |       return slots.default?.() | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | }) | ||||||
|  |  | ||||||
|  | export default Wave | ||||||
							
								
								
									
										34
									
								
								components/_util/wave/style.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								components/_util/wave/style.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,34 @@ | |||||||
|  | import { genComponentStyleHook } from '../../theme/internal' | ||||||
|  | import type { FullToken, GenerateStyle } from '../../theme/internal' | ||||||
|  |  | ||||||
|  | export interface ComponentToken {} | ||||||
|  |  | ||||||
|  | export interface WaveToken extends FullToken<'Wave'> {} | ||||||
|  |  | ||||||
|  | const genWaveStyle: GenerateStyle<WaveToken> = token => { | ||||||
|  |   const { componentCls, colorPrimary } = token | ||||||
|  |   return { | ||||||
|  |     [componentCls]: { | ||||||
|  |       position: 'absolute', | ||||||
|  |       background: 'transparent', | ||||||
|  |       pointerEvents: 'none', | ||||||
|  |       boxSizing: 'border-box', | ||||||
|  |       color: `var(--wave-color, ${colorPrimary})`, | ||||||
|  |  | ||||||
|  |       boxShadow: `0 0 0 0 currentcolor`, | ||||||
|  |       opacity: 0.2, | ||||||
|  |  | ||||||
|  |       // =================== Motion =================== | ||||||
|  |       '&.wave-motion-appear': { | ||||||
|  |         transition: [`box-shadow 0.4s ${token.motionEaseOutCirc}`, `opacity 2s ${token.motionEaseOutCirc}`].join(','), | ||||||
|  |  | ||||||
|  |         '&-active': { | ||||||
|  |           boxShadow: `0 0 0 6px currentcolor`, | ||||||
|  |           opacity: 0 | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | export default genComponentStyleHook('Wave', token => [genWaveStyle(token)]) | ||||||
							
								
								
									
										35
									
								
								components/_util/wave/util.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								components/_util/wave/util.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,35 @@ | |||||||
|  | export function isNotGrey(color: string) { | ||||||
|  |   // eslint-disable-next-line no-useless-escape | ||||||
|  |   const match = (color || '').match(/rgba?\((\d*), (\d*), (\d*)(, [\d.]*)?\)/) | ||||||
|  |   if (match && match[1] && match[2] && match[3]) { | ||||||
|  |     return !(match[1] === match[2] && match[2] === match[3]) | ||||||
|  |   } | ||||||
|  |   return true | ||||||
|  | } | ||||||
|  |  | ||||||
|  | export function isValidWaveColor(color: string) { | ||||||
|  |   return ( | ||||||
|  |     color && | ||||||
|  |     color !== '#fff' && | ||||||
|  |     color !== '#ffffff' && | ||||||
|  |     color !== 'rgb(255, 255, 255)' && | ||||||
|  |     color !== 'rgba(255, 255, 255, 1)' && | ||||||
|  |     isNotGrey(color) && | ||||||
|  |     !/rgba\((?:\d*, ){3}0\)/.test(color) && // any transparent rgba color | ||||||
|  |     color !== 'transparent' | ||||||
|  |   ) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | export function getTargetWaveColor(node: HTMLElement) { | ||||||
|  |   const { borderTopColor, borderColor, backgroundColor } = getComputedStyle(node) | ||||||
|  |   if (isValidWaveColor(borderTopColor)) { | ||||||
|  |     return borderTopColor | ||||||
|  |   } | ||||||
|  |   if (isValidWaveColor(borderColor)) { | ||||||
|  |     return borderColor | ||||||
|  |   } | ||||||
|  |   if (isValidWaveColor(backgroundColor)) { | ||||||
|  |     return backgroundColor | ||||||
|  |   } | ||||||
|  |   return null | ||||||
|  | } | ||||||
| @@ -1,5 +1,6 @@ | |||||||
| import { computed, defineComponent } from 'vue' | import { computed, defineComponent } from 'vue' | ||||||
| import { useProviderConfigState } from '../config-provider/context' | import { useProviderConfigState } from '../config-provider/context' | ||||||
|  | import Wave from '../_util/wave' | ||||||
| import useStyle from './style' | import useStyle from './style' | ||||||
|  |  | ||||||
| const Button = defineComponent({ | const Button = defineComponent({ | ||||||
| @@ -29,12 +30,14 @@ const Button = defineComponent({ | |||||||
|  |  | ||||||
|     return () => { |     return () => { | ||||||
|       return wrapSSR( |       return wrapSSR( | ||||||
|  |         <Wave> | ||||||
|           <button |           <button | ||||||
|             {...attrs} |             {...attrs} | ||||||
|             class={[cls.value, attrs.class]} |             class={[cls.value, attrs.class]} | ||||||
|           > |           > | ||||||
|             {slots.default?.()} |             {slots.default?.()} | ||||||
|           </button> |           </button> | ||||||
|  |         </Wave> | ||||||
|       ) |       ) | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -48,7 +48,7 @@ import type { ComponentToken as ButtonComponentToken } from '../../button/style' | |||||||
| // import type { ComponentToken as TourComponentToken } from '../../tour/style' | // import type { ComponentToken as TourComponentToken } from '../../tour/style' | ||||||
| // import type { ComponentToken as QRCodeComponentToken } from '../../qrcode/style' | // import type { ComponentToken as QRCodeComponentToken } from '../../qrcode/style' | ||||||
| // import type { ComponentToken as AppComponentToken } from '../../app/style' | // import type { ComponentToken as AppComponentToken } from '../../app/style' | ||||||
| // import type { ComponentToken as WaveToken } from '../../_util/wave/style' | import type { ComponentToken as WaveToken } from '../../_util/wave/style' | ||||||
|  |  | ||||||
| export interface ComponentTokenMap { | export interface ComponentTokenMap { | ||||||
|   Affix?: {} |   Affix?: {} | ||||||
| @@ -115,5 +115,5 @@ export interface ComponentTokenMap { | |||||||
|   // App?: AppComponentToken |   // App?: AppComponentToken | ||||||
|   // |   // | ||||||
|   // /** @private Internal TS definition. Do not use. */ |   // /** @private Internal TS definition. Do not use. */ | ||||||
|   // Wave?: WaveToken |   Wave?: WaveToken | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user