Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(comp: button): add xs and lg sizes #780

Merged
merged 1 commit into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/components/button/__tests__/buttonGroup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ describe('ButtonGroup', () => {
const wrapper = mount(TestComponent)

expect(wrapper.findAll('.ix-button-lg').length).toBe(1)
expect(wrapper.findAll('.ix-button-sm').length).toBe(0)
expect(wrapper.findAll('.ix-button-md').length).toBe(3)

await wrapper.setProps({ size: 'sm' })
await wrapper.setProps({ size: 'xl' })

expect(wrapper.findAll('.ix-button-lg').length).toBe(1)
expect(wrapper.findAll('.ix-button-sm').length).toBe(3)
expect(wrapper.findAll('.ix-button-xl').length).toBe(3)
})

test('shape work', async () => {
Expand Down
29 changes: 23 additions & 6 deletions packages/components/button/docs/Index.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,26 @@ subtitle: 按钮
| `@button-zindex` | `@zindex-l1-1` | - | - |
| `@button-font-weight` | `@font-weight-md` | - | - |
| `@button-line-height` | `@line-height-base` | - | - |
| `@button-height-sm` | `@height-sm` | - | - |
| `@button-height-xs` | `@height-sm` | - | - |
| `@button-height-sm` | `@height-md` | - | - |
| `@button-height-md` | `@height-md` | - | - |
| `@button-height-lg` | `@height-lg` | - | - |
| `@button-font-size-sm` | `@font-size-md` | - | - |
| `@button-height-xl` | `@height-xl` | - | - |
| `@button-min-width-xs` | `@width-xs` | - | - |
| `@button-min-width-sm` | `@width-sm` | - | - |
| `@button-min-width-md` | `@width-md` | - | - |
| `@button-min-width-lg` | `@width-lg` | - | - |
| `@button-min-width-xl` | `@width-xl` | - | - |
| `@button-font-size-xs` | `@font-size-xs` | - | - |
| `@button-font-size-sm` | `@font-size-sm` | - | - |
| `@button-font-size-md` | `@font-size-md` | - | - |
| `@button-font-size-lg` | `@font-size-lg` | - | - |
| `@button-padding-sm` | `@spacing-sm` | - | - |
| `@button-padding-md` | `@spacing-md` | - | - |
| `@button-padding-lg` | `@spacing-lg` | - | - |
| `@button-font-size-lg` | `@font-size-md` | - | - |
| `@button-font-size-xl` | `@font-size-lg` | - | - |
| `@button-padding-xs` | `@spacing-sm` | - | - |
| `@button-padding-sm` | `@spacing-md` | - | - |
| `@button-padding-md` | `@spacing-lg` | - | - |
| `@button-padding-lg` | `@spacing-xl` | - | - |
| `@button-padding-xl` | `@spacing-2xl` | - | - |
| `@button-icon-margin-left` | `@spacing-xs` | - | - |
| `@button-border-style` | `@border-style` | - | - |
| `@button-border-size` | `@border-width-sm` | - | - |
Expand All @@ -65,6 +76,9 @@ subtitle: 按钮
| `@button-primary` | `@color-white` | - | - |
| `@button-primary-background-color` | `@color-primary` | - | - |
| `@button-primary-border-color` | `@color-primary` | - | - |
| `@button-primary-loading-color` | `@color-white` | - | - |
| `@button-primary-loading-background-color` | `@color-primary-l10` | - | - |
| `@button-primary-loading-border` | `@color-primary-l10` | - | - |
| `@button-primary-text-shadow` | `0 -1px 0 rgba(0, 0, 0, 0.15)` | - | - |
| `@button-primary-box-shadow` | `0 2px 0 rgba(0, 0, 0, 0.045)` | - | - |
| `@button-default-color` | `@text-color` | - | - |
Expand All @@ -77,8 +91,11 @@ subtitle: 按钮
| `@button-danger-active-color` | `@color-error-d10` | - | - |
| `@button-danger-active-border-color` | `@color-error-d10` | - | - |
| `@button-danger-background-color` | `@color-error` | - | - |
| `@button-loading-color` | `@color-graphite` | - | - |
| `@button-ghost-color` | `@background-color-component` | - | - |
| `@button-ghost-background-color` | `transparent` | - | - |
| `@button-ghost-hover-background-color` | `rgba(255,255,255,0.20)` | - | - |
| `@button-ghost-disabled-background-color` | `rgba(255,255,255,0.40)` | - | - |
| `@button-ghost-border-color` | `@background-color-component` | - | - |
| `@button-link-color` | `@color-primary` | - | - |
| `@button-link-hover-color` | `@color-primary-l10` | - | - |
Expand Down
4 changes: 2 additions & 2 deletions packages/components/button/src/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ export default defineComponent({
setup(props, { slots }) {
const common = useGlobalConfig('common')
const mergedPrefixCls = computed(() => `${common.prefixCls}-button`)

const config = useGlobalConfig('button')
const groupProps = inject(buttonToken, {})
const formContext = inject(FORM_TOKEN, null)

const mode = computed(() => props.mode ?? groupProps.mode ?? 'default')
const size = computed(() => props.size ?? groupProps.size ?? formContext?.size.value ?? 'md')
const size = computed(() => props.size ?? groupProps.size ?? formContext?.size.value ?? config.size)

const classes = computed(() => {
const { block, danger, disabled, ghost, loading, icon, shape = groupProps.shape } = props
Expand Down
6 changes: 3 additions & 3 deletions packages/components/button/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { IxPropTypes } from '@idux/cdk/utils'

export type ButtonMode = 'primary' | 'default' | 'dashed' | 'text' | 'link'
export type ButtonShape = 'circle' | 'round'
export type ButtonSize = 'lg' | 'md' | 'sm'
export type ButtonSize = 'lg' | 'xl' | 'md' | 'sm' | 'xs'
export type ButtonType = 'button' | 'submit' | 'reset'

export const buttonProps = {
Expand All @@ -21,7 +21,7 @@ export const buttonProps = {
ghost: IxPropTypes.bool,
disabled: IxPropTypes.bool,
loading: IxPropTypes.bool,
size: IxPropTypes.oneOf<ButtonSize>(['lg', 'md', 'sm']),
size: IxPropTypes.oneOf<ButtonSize>(['lg', 'xl', 'md', 'sm', 'xs']),
shape: IxPropTypes.oneOf<ButtonShape>(['circle', 'round']),
block: IxPropTypes.bool,
icon: IxPropTypes.string,
Expand All @@ -37,7 +37,7 @@ export type ButtonInstance = InstanceType<DefineComponent<ButtonProps>>

export const buttonGroupProps = {
mode: IxPropTypes.oneOf<ButtonMode>(['primary', 'default', 'dashed', 'text', 'link']),
size: IxPropTypes.oneOf<ButtonSize>(['lg', 'md', 'sm']),
size: IxPropTypes.oneOf<ButtonSize>(['lg', 'xl', 'md', 'sm', 'xs']),
shape: IxPropTypes.oneOf<ButtonShape>(['circle', 'round']),
}

Expand Down
13 changes: 12 additions & 1 deletion packages/components/button/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@
&&-loading {
position: relative;

&.@{button-prefix} {
background-color: @button-default-background-color;
color: @button-loading-color;

&-primary {
background-color: @button-primary-loading-background-color;
border-color: @button-primary-loading-border;
color: @button-primary-loading-color;
}
}

&::before {
display: block;
}
Expand Down Expand Up @@ -88,7 +99,7 @@
}

&-icon-only {
.button-icon-only(@button-prefix;);
.button-icon-only(@button-prefix);
}

&::before {
Expand Down
Loading