Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit 2f35c65

Browse files
committed
feat(closebutton): added close button
1 parent 6d3a33c commit 2f35c65

File tree

7 files changed

+139
-7
lines changed

7 files changed

+139
-7
lines changed

src/App.vue

+3-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22
<theme-provider :theme="theme" :icons="$kiwi.icons">
33
<div class="root">
44
<div class="wrapper">
5-
<Badge mx="2">Default</Badge>
6-
<Badge mx="2" variant-color="green">Success</Badge>
7-
<Badge mx="2" variant-color="red">Removed</Badge>
8-
<Badge mx="2" variant-color="indigo">New</Badge>
5+
<CloseButton />
96
</div>
107
</div>
118
</theme-provider>
129
</template>
1310

1411
<script>
15-
import { ThemeProvider, Badge } from './lib/core/'
12+
import { ThemeProvider, CloseButton } from './lib/core/'
1613
import theme from './lib/theme'
1714
1815
export default {
@@ -26,7 +23,7 @@ export default {
2623
name: 'App',
2724
components: {
2825
ThemeProvider,
29-
Badge
26+
CloseButton
3027
},
3128
methods: {
3229
toggle () {

src/components/CloseButton/index.d.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import * as Vue from 'vue';
2+
3+
interface ICloseButton {
4+
/**
5+
* The size of the close button
6+
*/
7+
size?: "lg" | "md" | "sm";
8+
/**
9+
* If `true`, the close button will be disabled
10+
*/
11+
isDisabled?: boolean;
12+
/**
13+
* The color of the close icon
14+
*/
15+
color?: string;
16+
/**
17+
* An accessible label for the close button
18+
*/
19+
"aria-label"?: string;
20+
}
21+
22+
export type CloseButtonProps = ICloseButton;
23+
24+
/**
25+
* Close button component for UI interfaces
26+
*/
27+
declare const CloseButton: Vue.Component<CloseButtonProps>;
28+
29+
export default CloseButton;

src/components/CloseButton/index.js

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import Icon from '../Icon'
2+
import PseudoBox from '../PseudoBox'
3+
import styleProps from '../../lib/config/props'
4+
import { forwardProps } from '../../lib/utils'
5+
6+
const baseProps = {
7+
display: 'inline-flex',
8+
alignItems: 'center',
9+
justifyContent: 'center',
10+
rounded: 'md',
11+
transition: 'all 0.2s',
12+
flex: '0 0 auto',
13+
_hover: { bg: 'blackAlpha.100' },
14+
_active: { bg: 'blackAlpha.200' },
15+
_disabled: {
16+
cursor: 'not-allowed'
17+
},
18+
_focus: {
19+
boxShadow: 'outline'
20+
},
21+
border: 'none'
22+
}
23+
24+
const sizes = {
25+
lg: {
26+
button: '40px',
27+
icon: '16px'
28+
},
29+
md: {
30+
button: '32px',
31+
icon: '12px'
32+
},
33+
sm: {
34+
button: '24px',
35+
icon: '10px'
36+
}
37+
}
38+
39+
export default {
40+
name: 'CloseButton',
41+
inject: ['$theme', '$colorMode'],
42+
props: {
43+
size: {
44+
type: String,
45+
default: 'md',
46+
validator: value => value.match(/^(sm|md|lg)$/)
47+
},
48+
isDisabled: {
49+
type: Boolean,
50+
default: false
51+
},
52+
color: {
53+
type: String
54+
},
55+
_ariaLabel: {
56+
type: String,
57+
default: 'Close'
58+
},
59+
...styleProps
60+
},
61+
render (h) {
62+
// Pseudo styles
63+
const hoverColor = { light: 'blackAlpha.100', dark: 'whiteAlpha.100' }
64+
const activeColor = { light: 'blackAlpha.200', dark: 'whiteAlpha.200' }
65+
66+
// Size styles
67+
const buttonSize = sizes[this.size] && sizes[this.size]['button']
68+
const iconSize = sizes[this.size] && sizes[this.size]['icon']
69+
70+
return h(PseudoBox, {
71+
props: {
72+
as: 'button',
73+
outline: 'none',
74+
h: buttonSize,
75+
w: buttonSize,
76+
disabled: this.isDisabled,
77+
_hover: { bg: hoverColor[this.colorMode] },
78+
_active: { bg: activeColor[this.colorMode] },
79+
...baseProps,
80+
...forwardProps(this.$props)
81+
},
82+
attrs: {
83+
ariaLabel: this._ariaLabel,
84+
ariaDisabled: this.isDisabled
85+
}
86+
}, [h(Icon, {
87+
props: {
88+
color: this.color,
89+
name: 'close',
90+
size: iconSize
91+
},
92+
attrs: {
93+
focusable: false,
94+
ariaHidden: true
95+
}
96+
})])
97+
}
98+
}

src/components/Icon/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default {
3232
type: String,
3333
required: false,
3434
default: 'fas',
35-
validator: (value) => value.match(/^(fas|fal|fad)$/)
35+
validator: value => value.match(/^(fas|fal|fad)$/)
3636
},
3737
size: {
3838
type: [String, Number, Array],

src/components/Toast/index.js

Whitespace-only changes.

src/lib/core/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ export { default as TransitionExpand } from '../../components/TransitionExpand'
1010
export { default as Text } from '../../components/Text'
1111
export * from '../../components/Alert'
1212
export { default as Badge } from '../../components/Badge'
13+
export { default as CloseButton } from '../../components/CloseButton'

src/lib/plugin/iconsPaths.js

+7
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ const icons = {
7373
<circle fill="none" strokeMiterlimit="10" cx="12" cy="12" r="11.25" />
7474
</g>
7575
`
76+
},
77+
close: {
78+
path: `
79+
<path
80+
fill="currentColor"
81+
d="M.439,21.44a1.5,1.5,0,0,0,2.122,2.121L11.823,14.3a.25.25,0,0,1,.354,0l9.262,9.263a1.5,1.5,0,1,0,2.122-2.121L14.3,12.177a.25.25,0,0,1,0-.354l9.263-9.262A1.5,1.5,0,0,0,21.439.44L12.177,9.7a.25.25,0,0,1-.354,0L2.561.44A1.5,1.5,0,0,0,.439,2.561L9.7,11.823a.25.25,0,0,1,0,.354Z"
82+
/>`
7683
}
7784
}
7885

0 commit comments

Comments
 (0)