Skip to content

Commit

Permalink
feat(button): update button round property
Browse files Browse the repository at this point in the history
  • Loading branch information
shaobeichen committed Nov 9, 2022
1 parent eca21dd commit 7f11ef1
Show file tree
Hide file tree
Showing 7 changed files with 46,545 additions and 25,507 deletions.
1 change: 1 addition & 0 deletions examples/test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const App: React.FC = () => {
<Button
btnType="primary"
size="lg"
round
onClick={(e) => {
alert('线上包 测试 success!')
}}
Expand Down
72,013 changes: 46,511 additions & 25,502 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"scripts": {
"dev": "vite",
"build": "npm run clean && vite build && npm run build-css && npm run copy-readme",
"build": "npm run test && npm run clean && vite build && npm run build-css && npm run copy-readme",
"preview": "vite preview",
"build-css": "sass ./src/styles/index.scss ./lib/index.css",
"copy-readme": "cp ./README.md ./lib/README.md",
Expand Down Expand Up @@ -87,6 +87,7 @@
"dotenv-cli": "^6.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "^5.0.1",
"rimraf": "^3.0.2",
"sass": "^1.55.0",
"semantic-release": "^19.0.5",
Expand All @@ -95,4 +96,4 @@
"typescript": "^4.6.4",
"vite": "^3.2.0"
}
}
}
1 change: 1 addition & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const App: React.FC = () => {
<Button
btnType={ButtonType.Primary}
size={ButtonSize.Large}
round
onClick={(e) => {
alert('本地包 测试 success!')
}}
Expand Down
17 changes: 15 additions & 2 deletions src/components/Button/_style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,20 @@
}

.btn-lg {
@include button-size($btn-padding-y-lg, $btn-padding-x-lg, $btn-font-size-lg, $btn-border-radius-lg);
@include button-size(
$btn-padding-y-lg,
$btn-padding-x-lg,
$btn-font-size-lg,
$btn-border-radius-lg
);
}
.btn-sm {
@include button-size($btn-padding-y-sm, $btn-padding-x-sm, $btn-font-size-sm, $btn-border-radius-sm);
@include button-size(
$btn-padding-y-sm,
$btn-padding-x-sm,
$btn-font-size-sm,
$btn-border-radius-sm
);
}

.btn-primary {
Expand Down Expand Up @@ -62,3 +72,6 @@
pointer-events: none;
}
}
.btn-round {
border-radius: 999px;
}
10 changes: 10 additions & 0 deletions src/components/Button/button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ const disabledProps: ButtonProps = {
onClick: jest.fn(),
}

const roundProps: ButtonProps = {
round: true,
}

describe('test button components', () => {
it('should render default button', () => {
const wrapper = render(<Button {...defaultProps}>Click</Button>)
Expand Down Expand Up @@ -53,4 +57,10 @@ describe('test button components', () => {
fireEvent.click(element)
expect(disabledProps.onClick).not.toHaveBeenCalled()
})
it('should render round button when round set to true', () => {
const wrapper = render(<Button {...roundProps}>Click</Button>)
const element = wrapper.getByText('Click') as HTMLButtonElement
expect(element).toBeInTheDocument()
expect(element).toHaveClass('btn-round')
})
})
5 changes: 4 additions & 1 deletion src/components/Button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export enum ButtonType {
interface BaseButtonProps {
className?: string
disabled?: boolean
round?: boolean
size?: ButtonSize
btnType?: ButtonType
children: React.ReactNode
Expand All @@ -27,13 +28,14 @@ type AnchorButtonProps = BaseButtonProps & React.AnchorHTMLAttributes<HTMLElemen
export type ButtonProps = Partial<NetiveButtonProps & AnchorButtonProps>

const Button: React.FC<ButtonProps> = (props) => {
const { btnType, className, disabled, size, children, href, ...restProps } = props
const { btnType, className, disabled, round, size, children, href, ...restProps } = props

// btn,btn-lg,btn-primary
const classes = classNames('btn', className, {
[`btn-${btnType}`]: btnType,
[`btn-${size}`]: size,
disabled: btnType === ButtonType.Link && disabled,
'btn-round': round,
})

if (btnType === ButtonType.Link && href) {
Expand All @@ -54,6 +56,7 @@ const Button: React.FC<ButtonProps> = (props) => {
Button.defaultProps = {
disabled: false,
btnType: ButtonType.Default,
round: false,
}

export default Button

0 comments on commit 7f11ef1

Please sign in to comment.