Skip to content

Commit

Permalink
feat: 单个Button开发
Browse files Browse the repository at this point in the history
  • Loading branch information
ZRMYDYCG committed Feb 8, 2025
1 parent 0d61936 commit 6a74dc9
Show file tree
Hide file tree
Showing 10 changed files with 1,652 additions and 256 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"dev": "pnpm --filter @breeze-ui/play dev",
"docs:dev": "pnpm --filter @breeze-ui/docs dev",
"docs:build": "pnpm --filter @breeze-ui/docs build",
"storybook": "pnpm --filter @breeze-ui/play storybook",
"test": "pnpm --filter @breeze-ui/components test"
},
"keywords": [],
Expand Down
18 changes: 17 additions & 1 deletion packages/components/Button/Button.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup lang="ts">
import { ref } from "vue"
import type { ButtonProps } from "./interface.ts"
import type { ButtonProps, ButtonEmits, ButtonInstance } from "./interface.ts"
import { throttle } from "lodash-es";
defineOptions({
name: "bre-button"
Expand All @@ -9,11 +10,25 @@ defineOptions({
const props = withDefaults(defineProps<ButtonProps>(), {
tag: "button",
nativeType: "button",
useThrottle: true,
throttleDuration: 300,
})
const emits = defineEmits<ButtonEmits>()
const slots = defineSlots()
const _ref = ref<HTMLButtonElement>()
const handleBtnClick = (e: MouseEvent) => {
emits("click", e)
}
const handleBtnClickThrottle = throttle(handleBtnClick, props.throttleDuration)
defineExpose<ButtonInstance>({
ref: _ref
})
</script>

<template>
Expand All @@ -32,6 +47,7 @@ const _ref = ref<HTMLButtonElement>()
'is-loading': loading,
'is-disabled': disabled,
}"
@click="(e: MouseEvent) => useThrottle ? handleBtnClickThrottle(e) : handleBtnClick(e)"
>
<slot></slot>
</component>
Expand Down
17 changes: 15 additions & 2 deletions packages/components/Button/interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Component } from "vue";
import type {Component, Ref} from "vue";

export type ButtonType = 'primary' | 'success' | 'warning' | 'danger' | 'info'
export type NativeButtonType = 'button' |'submit' |'reset'
Expand All @@ -15,4 +15,17 @@ export interface ButtonProps {
circle?: boolean
plain?: boolean
round?: boolean
}
loadingIcon?: string
autoFocus?: boolean
useThrottle?: boolean
throttleDuration?: number
}

export interface ButtonEmits {
(e: "click", val: MouseEvent): void
}

export interface ButtonInstance {
ref: Ref<HTMLButtonElement | void>
}

2 changes: 2 additions & 0 deletions packages/play/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ dist-ssr
*.njsproj
*.sln
*.sw?

*storybook.log
14 changes: 14 additions & 0 deletions packages/play/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/** @type { import('@storybook/vue3-vite').StorybookConfig } */
const config = {
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
addons: [
"@storybook/addon-onboarding",
"@storybook/addon-essentials",
"@storybook/addon-interactions",
],
framework: {
name: "@storybook/vue3-vite",
options: {},
},
};
export default config;
13 changes: 13 additions & 0 deletions packages/play/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/** @type { import('@storybook/vue3').Preview } */
const preview = {
parameters: {
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
},
},
},
};

export default preview;
15 changes: 13 additions & 2 deletions packages/play/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,20 @@
"scripts": {
"dev": "vite",
"build": "vue-tsc -b && vite build",
"preview": "vite preview"
"preview": "vite preview",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
},
"devDependencies": {
"@vitejs/plugin-vue": "^5.2.1"
"@chromatic-com/storybook": "3.2.4",
"@storybook/addon-essentials": "8.5.3",
"@storybook/addon-interactions": "8.5.3",
"@storybook/addon-onboarding": "8.5.3",
"@storybook/blocks": "8.5.3",
"@storybook/test": "8.5.3",
"@storybook/vue3": "8.5.3",
"@storybook/vue3-vite": "8.5.3",
"@vitejs/plugin-vue": "^5.2.1",
"storybook": "8.5.3"
}
}
2 changes: 1 addition & 1 deletion packages/play/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
</script>

<template>
<bre-button type="primary" size="small">按钮</bre-button>
<bre-button type="primary" size="large" round="large">按钮</bre-button>
</template>

<style scoped>
Expand Down
Empty file.
Loading

0 comments on commit 6a74dc9

Please sign in to comment.