From fcd42f17001149ca06e214acd423ad6676d3971e Mon Sep 17 00:00:00 2001 From: unix Date: Sun, 10 May 2020 23:39:00 +0800 Subject: [PATCH 1/5] feat(button-group): add component feat(button-group): buttons arranged vertically --- .../button-group/button-group-context.ts | 20 +++ components/button-group/button-group.tsx | 116 ++++++++++++++++++ components/button-group/index.ts | 3 + components/button/button.tsx | 79 +++++------- components/button/utils.tsx | 56 +++++++++ components/index.ts | 1 + lib/data/metadata-en-us.json | 2 +- pages/en-us/components/button-group.mdx | 47 +++++++ 8 files changed, 278 insertions(+), 46 deletions(-) create mode 100644 components/button-group/button-group-context.ts create mode 100644 components/button-group/button-group.tsx create mode 100644 components/button-group/index.ts create mode 100644 components/button/utils.tsx create mode 100644 pages/en-us/components/button-group.mdx diff --git a/components/button-group/button-group-context.ts b/components/button-group/button-group-context.ts new file mode 100644 index 0000000..a9c9329 --- /dev/null +++ b/components/button-group/button-group-context.ts @@ -0,0 +1,20 @@ +import React from 'react' +import { NormalSizes, ButtonTypes } from '../utils/prop-types' + +export interface ButtonGroupConfig { + size?: NormalSizes + type?: ButtonTypes + ghost?: boolean + disabled?: boolean + isButtonGroup: boolean +} + +const defaultContext = { + isButtonGroup: false, + disabled: false, +} + +export const ButtonGroupContext = React.createContext(defaultContext) + +export const useButtonGroupContext = (): ButtonGroupConfig => + React.useContext(ButtonGroupContext) diff --git a/components/button-group/button-group.tsx b/components/button-group/button-group.tsx new file mode 100644 index 0000000..867ebda --- /dev/null +++ b/components/button-group/button-group.tsx @@ -0,0 +1,116 @@ +import React, { useMemo } from 'react' +import useTheme from '../styles/use-theme' +import withDefaults from '../utils/with-defaults' +import { NormalSizes, ButtonTypes } from '../utils/prop-types' +import { ButtonGroupContext, ButtonGroupConfig } from './button-group-context' +import { getButtonColors } from '../button/styles' + +interface Props { + disabled?: boolean + vertical?: boolean + ghost?: boolean + size?: NormalSizes + type?: ButtonTypes + className?: string +} + +const defaultProps = { + disabled: false, + vertical: false, + ghost: false, + size: 'medium' as NormalSizes, + type: 'default' as ButtonTypes, + className: '', +} + +type NativeAttrs = Omit, keyof Props> +export type ButtonGroupProps = Props & typeof defaultProps & NativeAttrs + +const ButtonGroup: React.FC> = ({ + disabled, + size, + type, + ghost, + vertical, + children, + className, +}) => { + const theme = useTheme() + const initialValue = useMemo( + () => ({ + disabled, + size, + type, + ghost, + isButtonGroup: true, + }), + [disabled, size, type], + ) + + const { border } = useMemo(() => { + const results = getButtonColors(theme, type, disabled, ghost) + if (!ghost && type !== 'default') + return { + ...results, + border: theme.palette.background, + } + return results + }, [theme, type, disabled, ghost]) + + return ( + +
+ {children} + +
+
+ ) +} + +const MemoButtonGroup = React.memo(ButtonGroup) + +export default withDefaults(MemoButtonGroup, defaultProps) diff --git a/components/button-group/index.ts b/components/button-group/index.ts new file mode 100644 index 0000000..cc398ed --- /dev/null +++ b/components/button-group/index.ts @@ -0,0 +1,3 @@ +import ButtonGroup from './button-group' + +export default ButtonGroup diff --git a/components/button/button.tsx b/components/button/button.tsx index 3817103..9f2f0b9 100644 --- a/components/button/button.tsx +++ b/components/button/button.tsx @@ -1,10 +1,11 @@ import React, { useRef, useState, MouseEvent, useMemo } from 'react' -import withDefaults from '../utils/with-defaults' import useTheme from '../styles/use-theme' -import { ButtonTypes, NormalSizes } from '../utils/prop-types' +import withDefaults from '../utils/with-defaults' import ButtonDrip from './button.drip' import ButtonLoading from '../loading' -import ButtonIcon from './button-icon' +import { ButtonTypes, NormalSizes } from '../utils/prop-types' +import { filterPropsWithGroup, getButtonChildrenWithIcon } from './utils' +import { useButtonGroupContext } from '../button-group/button-group-context' import { getButtonColors, getButtonCursor, getButtonHoverColors, getButtonSize } from './styles' interface Props { @@ -37,27 +38,30 @@ const defaultProps = { type NativeAttrs = Omit, keyof Props> export type ButtonProps = Props & typeof defaultProps & NativeAttrs -const Button: React.FC> = ({ - children, - disabled, - type, - loading, - shadow, - ghost, - effect, - onClick, - auto, - size, - icon, - iconRight, - className, - ...props -}) => { +const Button: React.FC> = ({ ...btnProps }) => { const theme = useTheme() const buttonRef = useRef(null) const [dripShow, setDripShow] = useState(false) const [dripX, setDripX] = useState(0) const [dripY, setDripY] = useState(0) + const groupConfig = useButtonGroupContext() + const { + children, + disabled, + type, + loading, + shadow, + ghost, + effect, + onClick, + auto, + size, + icon, + iconRight, + className, + ...props + } = filterPropsWithGroup(btnProps, groupConfig) + const { bg, border, color } = useMemo(() => getButtonColors(theme, type, disabled, ghost), [ theme, type, @@ -99,35 +103,19 @@ const Button: React.FC> = ({ onClick && onClick(event) } - const childrenWithIcon = useMemo(() => { - const hasIcon = icon || iconRight - const isRight = Boolean(iconRight) - const paddingForAutoMode = - auto || size === 'mini' - ? `calc(var(--zeit-ui-button-height) / 2 + var(--zeit-ui-button-padding) * .5)` - : 0 - if (!hasIcon) return
{children}
- return ( - <> - {hasIcon} -
- {children} - -
- - ) - }, [children, icon, auto, size]) + const childrenWithIcon = useMemo( + () => + getButtonChildrenWithIcon(auto, size, children, { + icon, + iconRight, + }), + [auto, size, children, icon, iconRight], + ) return ( + + + +`} /> + + +Button.Props + +| Attribute | Description | Type | Accepted values | Default +| ---------- | ---------- | ---- | -------------- | ------ | +| **type** | button type | `ButtonTypes` | [ButtonTypes](#buttontypes) | `default` | +| **size** | button size | `NormalSizes` | [NormalSizes](#normalsizes) | `medium` | +| ... | native props | `ButtonHTMLAttributes` | `'id', 'className', ...` | - | + +ButtonTypes + +```ts +type ButtonTypes = 'default' | 'secondary' | 'success' | 'warning' | 'error' | 'abort' +``` + +NormalSizes + +```ts +type NormalSizes = 'mini' | 'small' | 'medium' | 'large' +``` + + + +export default ({ children }) => {children} From 3dce6beefa39befabf12e5110357cb4e359d142b Mon Sep 17 00:00:00 2001 From: unix Date: Mon, 11 May 2020 18:36:25 +0800 Subject: [PATCH 2/5] docs(button-group): add docs for button-group docs: add docs --- lib/data/metadata-zh-cn.json | 2 +- pages/en-us/components/button-group.mdx | 79 +++++++++++++++- pages/zh-cn/components/button-group.mdx | 116 ++++++++++++++++++++++++ 3 files changed, 191 insertions(+), 6 deletions(-) create mode 100644 pages/zh-cn/components/button-group.mdx diff --git a/lib/data/metadata-zh-cn.json b/lib/data/metadata-zh-cn.json index 3004f31..a2be0e6 100644 --- a/lib/data/metadata-zh-cn.json +++ b/lib/data/metadata-zh-cn.json @@ -1 +1 @@ -[{"name":"guide","children":[{"name":"快速上手","children":[{"name":"什么是 ZEIT UI","url":"/zh-cn/guide/introduction","index":5,"group":"快速上手"},{"name":"安装","url":"/zh-cn/guide/installation","index":10,"group":"快速上手"},{"name":"服务端渲染","url":"/zh-cn/guide/server-render","index":15,"group":"快速上手"}]},{"name":"定制化","children":[{"name":"色彩","url":"/zh-cn/guide/colors","index":100,"group":"定制化"},{"name":"主题","url":"/zh-cn/guide/themes","index":100,"group":"定制化"}]}],"localeName":"上手指南"},{"name":"components","children":[{"name":"通用","children":[{"name":"文本 Text","url":"/zh-cn/components/text","index":10,"group":"通用"},{"name":"按钮 Button","url":"/zh-cn/components/button","index":100,"group":"通用"},{"name":"代码 Code","url":"/zh-cn/components/code","index":100,"group":"通用"},{"name":"图标 Icons","url":"/zh-cn/components/icons","index":100,"group":"通用"}]},{"name":"布局","children":[{"name":"栅格 Grid","url":"/zh-cn/components/grid","index":100,"group":"布局"},{"name":"布局 Layout","url":"/zh-cn/components/layout","index":100,"group":"布局"},{"name":"页面 Page","url":"/zh-cn/components/page","index":100,"group":"布局"},{"name":"间距 Spacer","url":"/zh-cn/components/spacer","index":100,"group":"布局"}]},{"name":"表面","children":[{"name":"卡片 Card","url":"/zh-cn/components/card","index":100,"group":"表面"},{"name":"折叠框 Collapse","url":"/zh-cn/components/collapse","index":100,"group":"表面"},{"name":"控件组 Fieldset","url":"/zh-cn/components/fieldset","index":100,"group":"表面"}]},{"name":"数据录入","children":[{"name":"复选框 Checkbox","url":"/zh-cn/components/checkbox","index":100,"group":"数据录入"},{"name":"输入框 Input","url":"/zh-cn/components/input","index":100,"group":"数据录入"},{"name":"单选框 Radio","url":"/zh-cn/components/radio","index":100,"group":"数据录入"},{"name":"选择器 Select","url":"/zh-cn/components/select","index":100,"group":"数据录入"},{"name":"滑动输入 Slider","url":"/zh-cn/components/slider","index":100,"group":"数据录入"},{"name":"文本输入框 Textarea","url":"/zh-cn/components/textarea","index":100,"group":"数据录入"},{"name":"开关 Toggle","url":"/zh-cn/components/toggle","index":100,"group":"数据录入"},{"name":"自动完成 Auto-Complete","url":"/zh-cn/components/auto-complete","index":104,"group":"数据录入"}]},{"name":"数据展示","children":[{"name":"头像 Avatar","url":"/zh-cn/components/avatar","index":100,"group":"数据展示"},{"name":"徽章 Badge","url":"/zh-cn/components/badge","index":100,"group":"数据展示"},{"name":"容量 Capacity","url":"/zh-cn/components/capacity","index":100,"group":"数据展示"},{"name":"描述 Description","url":"/zh-cn/components/description","index":100,"group":"数据展示"},{"name":"陈列框 Display","url":"/zh-cn/components/display","index":100,"group":"数据展示"},{"name":"点 Dot","url":"/zh-cn/components/dot","index":100,"group":"数据展示"},{"name":"文件树 File Tree","url":"/zh-cn/components/file-tree","index":100,"group":"数据展示"},{"name":"图片 Image","url":"/zh-cn/components/image","index":100,"group":"数据展示"},{"name":"键盘 keyboard","url":"/zh-cn/components/keyboard","index":100,"group":"数据展示"},{"name":"气泡卡片 Popover","url":"/zh-cn/components/popover","index":100,"group":"数据展示"},{"name":"表格 Table","url":"/zh-cn/components/table","index":100,"group":"数据展示"},{"name":"标签 Tag","url":"/zh-cn/components/tag","index":100,"group":"数据展示"},{"name":"文字提示 Tooltip","url":"/zh-cn/components/tooltip","index":100,"group":"数据展示"},{"name":"用户 User","url":"/zh-cn/components/user","index":100,"group":"数据展示"}]},{"name":"反馈","children":[{"name":"加载中 Loading","url":"/zh-cn/components/loading","index":100,"group":"反馈"},{"name":"对话框 Modal","url":"/zh-cn/components/modal","index":100,"group":"反馈"},{"name":"提示 Note","url":"/zh-cn/components/note","index":100,"group":"反馈"},{"name":"进度条 Progress","url":"/zh-cn/components/progress","index":100,"group":"反馈"},{"name":"指示器 Spinner","url":"/zh-cn/components/spinner","index":100,"group":"反馈"},{"name":"通知 Toast","url":"/zh-cn/components/toast","index":100,"group":"反馈"}]},{"name":"导航","children":[{"name":"链接 Link","url":"/zh-cn/components/link","index":100,"group":"导航"},{"name":"选项卡 Tabs","url":"/zh-cn/components/tabs","index":100,"group":"导航"},{"name":"下拉按钮 Btn Dropdown","url":"/zh-cn/components/button-dropdown","index":105,"group":"导航"}]},{"name":"其他","children":[{"name":"分割线 Divider","url":"/zh-cn/components/divider","index":100,"group":"其他"},{"name":"片段 Snippet","url":"/zh-cn/components/snippet","index":100,"group":"其他"}]},{"name":"工具包","children":[{"name":"锁定滚动 useBodyScroll","url":"/zh-cn/components/use-body-scroll","index":100,"group":"工具包"},{"name":"点击他处 useClickAway","url":"/zh-cn/components/use-click-away","index":100,"group":"工具包"},{"name":"剪切板 useClipboard","url":"/zh-cn/components/use-clipboard","index":100,"group":"工具包"},{"name":" 当前值 useCurrentState","url":"/zh-cn/components/use-current-state","index":100,"group":"工具包"}]}],"localeName":"所有组件"},{"name":"customization","children":[],"localeName":"定制化"}] +[{"name":"guide","children":[{"name":"快速上手","children":[{"name":"什么是 ZEIT UI","url":"/zh-cn/guide/introduction","index":5,"group":"快速上手"},{"name":"安装","url":"/zh-cn/guide/installation","index":10,"group":"快速上手"},{"name":"服务端渲染","url":"/zh-cn/guide/server-render","index":15,"group":"快速上手"}]},{"name":"定制化","children":[{"name":"色彩","url":"/zh-cn/guide/colors","index":100,"group":"定制化"},{"name":"主题","url":"/zh-cn/guide/themes","index":100,"group":"定制化"}]}],"localeName":"上手指南"},{"name":"components","children":[{"name":"通用","children":[{"name":"文本 Text","url":"/zh-cn/components/text","index":10,"group":"通用"},{"name":"按钮 Button","url":"/zh-cn/components/button","index":100,"group":"通用"},{"name":"代码 Code","url":"/zh-cn/components/code","index":100,"group":"通用"},{"name":"图标 Icons","url":"/zh-cn/components/icons","index":100,"group":"通用"}]},{"name":"布局","children":[{"name":"栅格 Grid","url":"/zh-cn/components/grid","index":100,"group":"布局"},{"name":"布局 Layout","url":"/zh-cn/components/layout","index":100,"group":"布局"},{"name":"页面 Page","url":"/zh-cn/components/page","index":100,"group":"布局"},{"name":"间距 Spacer","url":"/zh-cn/components/spacer","index":100,"group":"布局"}]},{"name":"表面","children":[{"name":"卡片 Card","url":"/zh-cn/components/card","index":100,"group":"表面"},{"name":"折叠框 Collapse","url":"/zh-cn/components/collapse","index":100,"group":"表面"},{"name":"控件组 Fieldset","url":"/zh-cn/components/fieldset","index":100,"group":"表面"}]},{"name":"数据录入","children":[{"name":"按钮组 Button-Group","url":"/zh-cn/components/button-group","index":100,"group":"数据录入"},{"name":"复选框 Checkbox","url":"/zh-cn/components/checkbox","index":100,"group":"数据录入"},{"name":"输入框 Input","url":"/zh-cn/components/input","index":100,"group":"数据录入"},{"name":"单选框 Radio","url":"/zh-cn/components/radio","index":100,"group":"数据录入"},{"name":"选择器 Select","url":"/zh-cn/components/select","index":100,"group":"数据录入"},{"name":"滑动输入 Slider","url":"/zh-cn/components/slider","index":100,"group":"数据录入"},{"name":"文本输入框 Textarea","url":"/zh-cn/components/textarea","index":100,"group":"数据录入"},{"name":"开关 Toggle","url":"/zh-cn/components/toggle","index":100,"group":"数据录入"},{"name":"自动完成 Auto-Complete","url":"/zh-cn/components/auto-complete","index":104,"group":"数据录入"}]},{"name":"数据展示","children":[{"name":"头像 Avatar","url":"/zh-cn/components/avatar","index":100,"group":"数据展示"},{"name":"徽章 Badge","url":"/zh-cn/components/badge","index":100,"group":"数据展示"},{"name":"容量 Capacity","url":"/zh-cn/components/capacity","index":100,"group":"数据展示"},{"name":"描述 Description","url":"/zh-cn/components/description","index":100,"group":"数据展示"},{"name":"陈列框 Display","url":"/zh-cn/components/display","index":100,"group":"数据展示"},{"name":"点 Dot","url":"/zh-cn/components/dot","index":100,"group":"数据展示"},{"name":"文件树 File Tree","url":"/zh-cn/components/file-tree","index":100,"group":"数据展示"},{"name":"图片 Image","url":"/zh-cn/components/image","index":100,"group":"数据展示"},{"name":"键盘 keyboard","url":"/zh-cn/components/keyboard","index":100,"group":"数据展示"},{"name":"气泡卡片 Popover","url":"/zh-cn/components/popover","index":100,"group":"数据展示"},{"name":"表格 Table","url":"/zh-cn/components/table","index":100,"group":"数据展示"},{"name":"标签 Tag","url":"/zh-cn/components/tag","index":100,"group":"数据展示"},{"name":"文字提示 Tooltip","url":"/zh-cn/components/tooltip","index":100,"group":"数据展示"},{"name":"用户 User","url":"/zh-cn/components/user","index":100,"group":"数据展示"}]},{"name":"反馈","children":[{"name":"加载中 Loading","url":"/zh-cn/components/loading","index":100,"group":"反馈"},{"name":"对话框 Modal","url":"/zh-cn/components/modal","index":100,"group":"反馈"},{"name":"提示 Note","url":"/zh-cn/components/note","index":100,"group":"反馈"},{"name":"进度条 Progress","url":"/zh-cn/components/progress","index":100,"group":"反馈"},{"name":"指示器 Spinner","url":"/zh-cn/components/spinner","index":100,"group":"反馈"},{"name":"通知 Toast","url":"/zh-cn/components/toast","index":100,"group":"反馈"}]},{"name":"导航","children":[{"name":"链接 Link","url":"/zh-cn/components/link","index":100,"group":"导航"},{"name":"选项卡 Tabs","url":"/zh-cn/components/tabs","index":100,"group":"导航"},{"name":"下拉按钮 Btn Dropdown","url":"/zh-cn/components/button-dropdown","index":105,"group":"导航"}]},{"name":"其他","children":[{"name":"分割线 Divider","url":"/zh-cn/components/divider","index":100,"group":"其他"},{"name":"片段 Snippet","url":"/zh-cn/components/snippet","index":100,"group":"其他"}]},{"name":"工具包","children":[{"name":"锁定滚动 useBodyScroll","url":"/zh-cn/components/use-body-scroll","index":100,"group":"工具包"},{"name":"点击他处 useClickAway","url":"/zh-cn/components/use-click-away","index":100,"group":"工具包"},{"name":"剪切板 useClipboard","url":"/zh-cn/components/use-clipboard","index":100,"group":"工具包"},{"name":" 当前值 useCurrentState","url":"/zh-cn/components/use-current-state","index":100,"group":"工具包"}]}],"localeName":"所有组件"},{"name":"customization","children":[],"localeName":"定制化"}] diff --git a/pages/en-us/components/button-group.mdx b/pages/en-us/components/button-group.mdx index 2416f91..d4a969b 100644 --- a/pages/en-us/components/button-group.mdx +++ b/pages/en-us/components/button-group.mdx @@ -14,20 +14,89 @@ A set of related buttons. title="Basic" scope={{ Button, ButtonGroup }} code={` - - - - + + + + `} /> + + + + + + + + + + + + + + + +`} /> + + + + + + + + + + + + +`} /> + + + + + + + + + +`} /> + + + + + + + + +`} /> -Button.Props +ButtonGroup.Props | Attribute | Description | Type | Accepted values | Default | ---------- | ---------- | ---- | -------------- | ------ | | **type** | button type | `ButtonTypes` | [ButtonTypes](#buttontypes) | `default` | | **size** | button size | `NormalSizes` | [NormalSizes](#normalsizes) | `medium` | +| **ghost** | the opposite color | `boolean` | - | `false` | +| **vertical** | show all buttons vertically | `boolean` | - | `false` | +| **disabled** | disable all buttons | `boolean` | - | `false` | | ... | native props | `ButtonHTMLAttributes` | `'id', 'className', ...` | - | ButtonTypes diff --git a/pages/zh-cn/components/button-group.mdx b/pages/zh-cn/components/button-group.mdx new file mode 100644 index 0000000..0ee4b2e --- /dev/null +++ b/pages/zh-cn/components/button-group.mdx @@ -0,0 +1,116 @@ +import { Layout, Playground, Attributes } from 'lib/components' +import { Button, Spacer, ButtonGroup } from 'components' + +export const meta = { + title: '按钮组 Button-Group', + group: '数据录入', +} + +## Button Group / 按钮组 + +展示一组具备相关性的按钮。 + + + + + + +`} /> + + + + + + + + + + + + + + + + +`} /> + + + + + + + + + + + + +`} /> + + + + + + + + + +`} /> + + + + + + + + +`} /> + +ButtonGroup.Props + +| 属性 | 描述 | 类型 | 推荐值 | 默认 +| ---------- | ---------- | ---- | -------------- | ------ | +| **type** | 按钮类型 | `ButtonTypes` | [ButtonTypes](#buttontypes) | `default` | +| **size** | 按钮大小 | `NormalSizes` | [NormalSizes](#normalsizes) | `medium` | +| **ghost** | 相反色彩模式的按钮 | `boolean` | - | `false` | +| **vertical** | 以垂直方式显示所有按钮 | `boolean` | - | `false` | +| **disabled** | 是否禁用所有按钮 | `boolean` | - | `false` | +| ... | 原生属性 | `ButtonHTMLAttributes` | `'id', 'className', ...` | - | + +ButtonTypes + +```ts +type ButtonTypes = 'default' | 'secondary' | 'success' | 'warning' | 'error' | 'abort' +``` + +NormalSizes + +```ts +type NormalSizes = 'mini' | 'small' | 'medium' | 'large' +``` + + + +export default ({ children }) => {children} From eb596f4592ebc69186f9fa4fe214770cc3c69973 Mon Sep 17 00:00:00 2001 From: unix Date: Mon, 11 May 2020 18:36:58 +0800 Subject: [PATCH 3/5] test(button-group): add testcase test: update snapshots --- .../__snapshots__/index.test.tsx.snap | 493 ++++++++++++++++++ .../button-group/__tests__/index.test.tsx | 53 ++ .../__snapshots__/icon.test.tsx.snap | 38 +- .../__snapshots__/index.test.tsx.snap | 10 +- 4 files changed, 572 insertions(+), 22 deletions(-) create mode 100644 components/button-group/__tests__/__snapshots__/index.test.tsx.snap create mode 100644 components/button-group/__tests__/index.test.tsx diff --git a/components/button-group/__tests__/__snapshots__/index.test.tsx.snap b/components/button-group/__tests__/__snapshots__/index.test.tsx.snap new file mode 100644 index 0000000..ae8ca85 --- /dev/null +++ b/components/button-group/__tests__/__snapshots__/index.test.tsx.snap @@ -0,0 +1,493 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ButtonGroup buttons should be displayed vertically 1`] = ` +"
" +`; + +exports[`ButtonGroup props should be passed to each button 1`] = ` +"
" +`; + +exports[`ButtonGroup props should be passed to each button 2`] = ` +"
" +`; + +exports[`ButtonGroup should render correctly 1`] = ` +"
" +`; diff --git a/components/button-group/__tests__/index.test.tsx b/components/button-group/__tests__/index.test.tsx new file mode 100644 index 0000000..d85eda9 --- /dev/null +++ b/components/button-group/__tests__/index.test.tsx @@ -0,0 +1,53 @@ +import React from 'react' +import { mount } from 'enzyme' +import { ButtonGroup, Button } from 'components' +import { nativeEvent } from 'tests/utils' + +describe('ButtonGroup', () => { + it('should render correctly', () => { + const wrapper = mount( + + + , + ) + expect(wrapper.html()).toMatchSnapshot() + expect(() => wrapper.unmount()).not.toThrow() + }) + + it('props should be passed to each button', () => { + const wrapper = mount( + + + , + ) + expect(wrapper.html()).toMatchSnapshot() + wrapper.setProps({ ghost: true }) + expect(wrapper.html()).toMatchSnapshot() + expect(() => wrapper.unmount()).not.toThrow() + }) + + it('should ignore events when group disabled', () => { + const handler = jest.fn() + const wrapper = mount( + + + , + ) + wrapper.find('button').simulate('click', nativeEvent) + expect(handler).toHaveBeenCalledTimes(1) + wrapper.setProps({ disabled: true }) + wrapper.find('button').simulate('click', nativeEvent) + expect(handler).toHaveBeenCalledTimes(1) + }) + + it('buttons should be displayed vertically', () => { + const wrapper = mount( + + + + , + ) + expect(wrapper.html()).toMatchSnapshot() + expect(() => wrapper.unmount()).not.toThrow() + }) +}) diff --git a/components/button/__tests__/__snapshots__/icon.test.tsx.snap b/components/button/__tests__/__snapshots__/icon.test.tsx.snap index 07c3288..cdaf903 100644 --- a/components/button/__tests__/__snapshots__/icon.test.tsx.snap +++ b/components/button/__tests__/__snapshots__/icon.test.tsx.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`ButtonIcon should render correctly 1`] = ` -"