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

Commit e138754

Browse files
Merge pull request #5 from chakra-ui/component/alert
feat: Component/c-alert
2 parents ed8ed38 + a8a1339 commit e138754

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+429
-2619
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"typescript.tsdk": "node_modules/typescript/lib"
3+
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
],
1111
"scripts": {
1212
"postinstall": "yarn run lerna bootstrap",
13-
"build": "lerna run build",
13+
"build": "lerna run build --no-private --stream",
1414
"lint": "eslint '*/**/*.{js,ts,tsx}' --quiet --fix",
1515
"scaffold": "hygen",
1616
"playground:routes": "ts-node ./scripts/parse-routes.ts",
@@ -22,6 +22,7 @@
2222
"c-box": "yarn workspace @chakra-ui/c-box",
2323
"c-button": "yarn workspace @chakra-ui/c-button",
2424
"system": "yarn workspace @chakra-ui/system-vue",
25+
"theme": "yarn workspace @chakra-ui/vue-theme",
2526
"nuxt": "yarn workspace @chakra-ui/nuxt-next"
2627
},
2728
"license": "MIT",

packages/c-alert/examples/base-alert.vue

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
11
<template>
2-
<c-alert
3-
font-weight="bold"
4-
px="4"
5-
py="3"
6-
:bg="['yellow.300', 'blue.200']"
7-
aria-role="alert"
8-
rounded="md"
9-
>
10-
HELLO ALERT
11-
</c-alert>
12-
<p>Alert paragraph</p>
2+
<c-alert> HELLO ALERT </c-alert>
133
</template>
144

155
<script lang="ts">
16-
import CAlert from '@chakra-ui/c-alert/src'
6+
import { CAlert } from '@chakra-ui/c-alert/src'
177
import { defineComponent } from 'vue'
188
199
export default defineComponent({
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<template>
2+
<c-alert status="success" mb="3">
3+
<c-alert-title> Info alert </c-alert-title>
4+
<c-alert-description> Something just happened </c-alert-description>
5+
</c-alert>
6+
<c-alert variant="subtle" status="success" mb="3">
7+
<c-alert-title> Info alert </c-alert-title>
8+
<c-alert-description> Something just happened </c-alert-description>
9+
</c-alert>
10+
<c-alert variant="left-accent" status="success" mb="3">
11+
<c-alert-title> Info alert </c-alert-title>
12+
<c-alert-description> Something just happened </c-alert-description>
13+
</c-alert>
14+
<c-alert variant="top-accent" status="success" mb="3">
15+
<c-alert-title> Info alert </c-alert-title>
16+
<c-alert-description> Something just happened </c-alert-description>
17+
</c-alert>
18+
</template>
19+
20+
<script lang="ts">
21+
import { CAlert, CAlertTitle, CAlertDescription } from '@chakra-ui/c-alert/src'
22+
import { defineComponent } from 'vue'
23+
24+
export default defineComponent({
25+
name: 'WithAccentExample',
26+
components: { CAlert, CAlertTitle, CAlertDescription },
27+
})
28+
</script>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<template>
2+
<c-alert status="info" mb="3"> Info alert </c-alert>
3+
<c-alert status="success" mb="3"> Success alert </c-alert>
4+
<c-alert status="warning" mb="3"> Warning alert </c-alert>
5+
<c-alert status="error" mb="3"> Error alert </c-alert>
6+
</template>
7+
8+
<script lang="ts">
9+
import { CAlert } from '@chakra-ui/c-alert/src'
10+
import { defineComponent } from 'vue'
11+
12+
export default defineComponent({
13+
name: 'WithStatusAlertExample',
14+
components: { CAlert },
15+
})
16+
</script>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<template>
2+
<c-alert status="info" mb="3">
3+
<c-alert-title> Info alert </c-alert-title>
4+
<c-alert-description> Something just happened </c-alert-description>
5+
</c-alert>
6+
</template>
7+
8+
<script lang="ts">
9+
import { CAlert, CAlertTitle, CAlertDescription } from '@chakra-ui/c-alert/src'
10+
import { defineComponent } from 'vue'
11+
12+
export default defineComponent({
13+
name: 'WithTitleExample',
14+
components: { CAlert, CAlertTitle, CAlertDescription },
15+
})
16+
</script>

packages/c-alert/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"watch:types": "tsc --emitDeclarationOnly --declaration --declarationDir dist/types --watch"
2424
},
2525
"dependencies": {
26-
"@chakra-ui/vue-styled-system": "1.0.0",
26+
"@chakra-ui/styled-system": "^1.4.1",
2727
"@chakra-ui/system-vue": "1.0.0",
2828
"@chakra-ui/vue-theme": "^1.0.0"
2929
}

packages/c-alert/src/alert.ts

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
import { h, defineComponent, PropType, provide } from 'vue'
2+
import {
3+
chakra,
4+
ColorScheme,
5+
DeepComponentThemeConfig,
6+
ThemingProps,
7+
useMultiStyleConfig,
8+
provideComponentStyles,
9+
useComponentStyles,
10+
DOMElements,
11+
} from '@chakra-ui/system-vue'
12+
import { SystemStyleObject } from '@chakra-ui/styled-system'
13+
14+
const STATUSES = {
15+
info: {
16+
colorScheme: 'blue' as ColorScheme,
17+
},
18+
success: {
19+
colorScheme: 'green' as ColorScheme,
20+
},
21+
warning: {
22+
colorScheme: 'orange' as ColorScheme,
23+
},
24+
error: {
25+
colorScheme: 'red' as ColorScheme,
26+
},
27+
}
28+
29+
type AlertStatus = keyof typeof STATUSES
30+
export type AlertVariant = 'solid' | 'subtle' | 'left-accent' | 'top-accent'
31+
32+
interface AlertState {
33+
status: AlertStatus
34+
}
35+
36+
/**
37+
* CAlert component
38+
*
39+
* This is the container component for all Alert components.
40+
* It also provides state and context to it's compound components
41+
*/
42+
export const CAlert = defineComponent({
43+
name: 'CAlert',
44+
props: {
45+
as: {
46+
type: [String, Object] as PropType<DOMElements>,
47+
default: 'div',
48+
},
49+
status: {
50+
type: [String] as PropType<AlertStatus>,
51+
default: 'info',
52+
},
53+
colorScheme: {
54+
type: [String] as PropType<ColorScheme>,
55+
},
56+
styleConfig: {
57+
type: [Object] as PropType<DeepComponentThemeConfig>,
58+
},
59+
variant: {
60+
type: [String] as PropType<AlertVariant>,
61+
default: 'solid',
62+
},
63+
},
64+
setup(props, { slots, attrs }) {
65+
const colorScheme: ColorScheme =
66+
props.colorScheme || STATUSES[props.status].colorScheme
67+
68+
const themingProps: ThemingProps = {
69+
colorScheme,
70+
variant: props.variant,
71+
}
72+
const styles = useMultiStyleConfig('Alert', themingProps)
73+
const alertStyles: SystemStyleObject = {
74+
width: '100%',
75+
display: 'flex',
76+
alignItems: 'center',
77+
position: 'relative',
78+
overflow: 'hidden',
79+
...styles.value.container,
80+
}
81+
82+
provideComponentStyles('Alert', styles.value)
83+
provide('$AlertState', { status: props.status } as AlertState)
84+
85+
return () =>
86+
h(
87+
chakra(props.as, 'alert'),
88+
{
89+
role: 'alert',
90+
...alertStyles,
91+
...attrs,
92+
},
93+
slots
94+
)
95+
},
96+
})
97+
98+
/**
99+
* CAlertTitle component
100+
*
101+
* The title component for alerts
102+
*/
103+
export const CAlertTitle = defineComponent({
104+
name: 'CAlertTitle',
105+
setup(_, { attrs, slots }) {
106+
const styles = useComponentStyles('Alert')
107+
108+
return () =>
109+
h(
110+
chakra('div', 'alert__title'),
111+
{
112+
...styles.title,
113+
...attrs,
114+
},
115+
slots
116+
)
117+
},
118+
})
119+
120+
/**
121+
* CAlertDescription component
122+
*
123+
* The description component for alerts
124+
*/
125+
export const CAlertDescription = defineComponent({
126+
name: 'CAlertDescription',
127+
setup(_, { attrs, slots }) {
128+
const styles = useComponentStyles('Alert')
129+
130+
return () =>
131+
h(
132+
chakra('div', 'alert__description'),
133+
{
134+
...styles.description,
135+
...attrs,
136+
},
137+
slots
138+
)
139+
},
140+
})
141+
142+
// TODO: Add CAlertIcon component.
143+
// This should ne done after the icon component is created.

packages/c-alert/src/index.ts

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1 @@
1-
import { h, defineComponent, PropType } from 'vue'
2-
import { chakra } from '@chakra-ui/system-vue'
3-
import { DOMElements } from '@chakra-ui/system-vue/dist/types/system.utils'
4-
5-
const CAlert = defineComponent({
6-
name: 'CAlert',
7-
props: {
8-
as: {
9-
type: [String, Object] as PropType<DOMElements>,
10-
default: 'div',
11-
},
12-
},
13-
setup(props, { slots, attrs }) {
14-
return () =>
15-
h(
16-
chakra(props.as, 'alert'),
17-
{
18-
...attrs,
19-
role: 'alert',
20-
},
21-
slots
22-
)
23-
},
24-
})
25-
26-
export default CAlert
1+
export * from './alert'

packages/c-theme-provider/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,3 @@ const CThemeProvider = defineComponent({
2626
})
2727

2828
export default CThemeProvider
29-
export * from './theme.hooks'

0 commit comments

Comments
 (0)