ui-lib(button): size variants
This commit is contained in:
		
							parent
							
								
									edae4c6915
								
							
						
					
					
						commit
						401f13f7e3
					
				| @ -2,7 +2,15 @@ | |||||||
|   <div v-for="buttonVariant of buttonVariants" :key="buttonVariant"> |   <div v-for="buttonVariant of buttonVariants" :key="buttonVariant"> | ||||||
|     <h2>{{ _.capitalize(buttonVariant) }}</h2> |     <h2>{{ _.capitalize(buttonVariant) }}</h2> | ||||||
| 
 | 
 | ||||||
|     <c-button v-for="buttonType of buttonTypes" :key="buttonType" :variant="buttonVariant" :type="buttonType" mx-1> |     <div v-for="buttonSize of buttonSizes" :key="buttonSize" mb-2> | ||||||
|  |       <c-button | ||||||
|  |         v-for="buttonType of buttonTypes" | ||||||
|  |         :key="buttonType" | ||||||
|  |         :variant="buttonVariant" | ||||||
|  |         :type="buttonType" | ||||||
|  |         :size="buttonSize" | ||||||
|  |         mx-1 | ||||||
|  |       > | ||||||
|         Button |         Button | ||||||
|       </c-button> |       </c-button> | ||||||
| 
 | 
 | ||||||
| @ -11,19 +19,22 @@ | |||||||
|         :key="buttonType" |         :key="buttonType" | ||||||
|         :variant="buttonVariant" |         :variant="buttonVariant" | ||||||
|         :type="buttonType" |         :type="buttonType" | ||||||
|  |         :size="buttonSize" | ||||||
|         circle |         circle | ||||||
|         mx-1 |         mx-1 | ||||||
|       > |       > | ||||||
|         A |         A | ||||||
|       </c-button> |       </c-button> | ||||||
|     </div> |     </div> | ||||||
|  |   </div> | ||||||
| </template> | </template> | ||||||
| 
 | 
 | ||||||
| <script lang="ts" setup> | <script lang="ts" setup> | ||||||
| import _ from 'lodash'; | import _ from 'lodash'; | ||||||
| 
 | 
 | ||||||
| const buttonVariants = ['basic', 'text']; | const buttonVariants = ['basic', 'text'] as const; | ||||||
| const buttonTypes = ['default', 'primary']; | const buttonTypes = ['default', 'primary'] as const; | ||||||
|  | const buttonSizes = ['small', 'medium', 'large'] as const; | ||||||
| </script> | </script> | ||||||
| 
 | 
 | ||||||
| <style lang="less" scoped></style> | <style lang="less" scoped></style> | ||||||
|  | |||||||
| @ -27,6 +27,21 @@ const createTheme = ({ style }: { style: 'light' | 'dark' }) => { | |||||||
|   const theme = appThemes[style]; |   const theme = appThemes[style]; | ||||||
| 
 | 
 | ||||||
|   return { |   return { | ||||||
|  |     size: { | ||||||
|  |       small: { | ||||||
|  |         width: '28px', | ||||||
|  |         fontSize: '12px', | ||||||
|  |       }, | ||||||
|  |       medium: { | ||||||
|  |         width: '34px', | ||||||
|  |         fontSize: '14px', | ||||||
|  |       }, | ||||||
|  |       large: { | ||||||
|  |         width: '40px', | ||||||
|  |         fontSize: '16px', | ||||||
|  |       }, | ||||||
|  |     }, | ||||||
|  | 
 | ||||||
|     basic: { |     basic: { | ||||||
|       default: createState({ |       default: createState({ | ||||||
|         textColor: theme.text.baseColor, |         textColor: theme.text.baseColor, | ||||||
|  | |||||||
| @ -25,6 +25,7 @@ const props = withDefaults( | |||||||
|     circle?: boolean; |     circle?: boolean; | ||||||
|     href?: string; |     href?: string; | ||||||
|     to?: RouteLocationRaw; |     to?: RouteLocationRaw; | ||||||
|  |     size?: 'small' | 'medium' | 'large'; | ||||||
|   }>(), |   }>(), | ||||||
|   { |   { | ||||||
|     type: 'default', |     type: 'default', | ||||||
| @ -34,9 +35,10 @@ const props = withDefaults( | |||||||
|     circle: false, |     circle: false, | ||||||
|     href: undefined, |     href: undefined, | ||||||
|     to: undefined, |     to: undefined, | ||||||
|  |     size: 'medium', | ||||||
|   }, |   }, | ||||||
| ); | ); | ||||||
| const { variant, disabled, round, circle, href, type, to } = toRefs(props); | const { variant, disabled, round, circle, href, type, to, size: sizeName } = toRefs(props); | ||||||
| 
 | 
 | ||||||
| const emits = defineEmits(['click']); | const emits = defineEmits(['click']); | ||||||
| 
 | 
 | ||||||
| @ -58,18 +60,20 @@ const tag = computed(() => { | |||||||
|   return 'button'; |   return 'button'; | ||||||
| }); | }); | ||||||
| const appTheme = useAppTheme(); | const appTheme = useAppTheme(); | ||||||
|  | 
 | ||||||
|  | const size = computed(() => theme.value.size[sizeName.value]); | ||||||
| </script> | </script> | ||||||
| 
 | 
 | ||||||
| <style lang="less" scoped> | <style lang="less" scoped> | ||||||
| .c-button { | .c-button { | ||||||
|   line-height: 1; |   line-height: 1; | ||||||
|   font-family: inherit; |   font-family: inherit; | ||||||
|   font-size: inherit; |   font-size: v-bind('size.fontSize'); | ||||||
|   border: none; |   border: none; | ||||||
|   text-align: center; |   text-align: center; | ||||||
|   cursor: pointer; |   cursor: pointer; | ||||||
|   text-decoration: none; |   text-decoration: none; | ||||||
|   height: 34px; |   height: v-bind('size.width'); | ||||||
|   font-weight: 400; |   font-weight: 400; | ||||||
|   color: v-bind('variantTheme.textColor'); |   color: v-bind('variantTheme.textColor'); | ||||||
|   padding: 0 14px; |   padding: 0 14px; | ||||||
| @ -89,8 +93,9 @@ const appTheme = useAppTheme(); | |||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   &.circle { |   &.circle { | ||||||
|     border-radius: 40px; |     border-radius: v-bind('size.width'); | ||||||
|     width: 34px; |     width: v-bind('size.width'); | ||||||
|  |     padding: 0; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   &:not(.disabled) { |   &:not(.disabled) { | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user