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

Commit 203f7c5

Browse files
Merge pull request #473 from Pwuts/improve-types
feat(types): improve & add type declarations
2 parents 464a0ad + 1e37eb9 commit 203f7c5

File tree

10 files changed

+105
-23
lines changed

10 files changed

+105
-23
lines changed

packages/chakra-ui-core/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"vue": "^2.6.10"
5454
},
5555
"devDependencies": {
56+
"@fortawesome/fontawesome-common-types": "^0.2.36",
5657
"rimraf": "^3.0.2"
5758
},
5859
"keywords": [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
interface ChakraToastOptions {
2+
position?: 'bottom' | 'top' | 'right' | 'left'
3+
duration?: number
4+
render?: (options: { onClose?: VoidFunction, id: any }) => any
5+
title?: string
6+
description?: string
7+
status?: 'info' | 'warning' | 'success' | 'error'
8+
variant?: 'solid' | 'subtle' | 'top-accent' | 'left-accent'
9+
isClosable?: boolean
10+
}
11+
12+
function useToast(): (options: ChakraToastOptions) => void
13+
14+
export default useToast
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import CToast from './CToast'
2+
export default CToast
+11-21
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,24 @@
11
import { PluginObject } from "vue"
2+
import { IconPack } from "@fortawesome/fontawesome-common-types"
3+
import { Theme } from "../../chakra-ui-theme/types"
24

3-
export type Theme = {
4-
breakpoints: any
5-
zIndices: any
6-
radii: any
7-
opacity: any
8-
borders: any
9-
colors: any
10-
borderWidths: any
11-
sizes: any
12-
shadows: any
13-
space: any
14-
fontSizes: any
15-
fonts: any
16-
fontWeights: any
17-
lineHeights: any
18-
letterSpacings: any
5+
export type Icon = {
6+
path: string
7+
viewBox?: string
8+
attrs?: any
199
}
2010

2111
export type Options = {
2212
theme: Theme
2313
extendTheme: Theme
2414
icons: {
25-
extend: any
15+
extend: { [name: string]: Icon }
2616
iconPack: string
27-
iconSet: any
17+
iconSet: IconPack
2818
}
2919
}
3020

31-
export type Chakra = PluginObject<Options>
21+
export type ChakraPlugin = PluginObject<Options>
3222

33-
declare let chakra: Chakra
34-
export default chakra
23+
declare let chakra: ChakraPlugin
24+
export default chakra
+14-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
import Chakra from "./chakra"
1+
import Chakra, { Icon } from "./chakra"
2+
import { Theme } from "../../chakra-ui-theme/types"
3+
import useToast from "../src/CToast"
4+
5+
declare module 'vue/types/vue' {
6+
interface Vue {
7+
$toast: ReturnType<typeof useToast>
8+
$chakra: {
9+
theme: Theme
10+
icons: { [name: string]: Icon }
11+
}
12+
}
13+
}
214

315
export * from './component'
4-
export default Chakra
16+
export default Chakra

packages/chakra-ui-nuxt/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
],
1212
"files": ["lib"],
1313
"main": "lib/module.js",
14+
"types": "types/index.d.ts",
1415
"scripts": {
1516
"dev": "nuxt example/base",
1617
"lint": "eslint --ext .js,.vue .",
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import Chakra, { Icon } from "./chakra"
2+
import { Theme } from "../../chakra-ui-theme/types"
3+
import useToast from "../src/CToast"
4+
5+
declare module '@nuxt/types' {
6+
interface Context {
7+
$toast?: ReturnType<typeof useToast>
8+
$chakra: {
9+
theme: Theme
10+
icons: { [name: string]: Icon }
11+
}
12+
}
13+
14+
interface NuxtAppOptions {
15+
$toast?: ReturnType<typeof useToast>
16+
$chakra: {
17+
theme: Theme
18+
icons: { [name: string]: Icon }
19+
}
20+
}
21+
}
22+
23+
declare module 'vue/types/vue' {
24+
interface Vue {
25+
$toast: ReturnType<typeof useToast>
26+
$chakra: {
27+
theme: Theme
28+
icons: { [name: string]: Icon }
29+
}
30+
}
31+
}

packages/chakra-ui-theme/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"license": "MIT",
1818
"main": "dist/index.js",
1919
"module": "src/index.js",
20+
"types": "types/index.d.ts",
2021
"files": [
2122
"dist",
2223
"src"
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export type Theme = {
2+
breakpoints: { [key: string]: string }
3+
zIndices: { [key: string]: string | number }
4+
radii: { [key: string]: string }
5+
opacity: { [key: string]: string }
6+
borders: { [key: string]: string }
7+
colors: { [key: string]: string | { [opacity: string]: string }}
8+
fonts: {
9+
heading: string
10+
body: string
11+
mono: string
12+
}
13+
fontSizes: { [key: string]: string }
14+
fontWeights: { [key: string]: number }
15+
letterSpacings: { [key: string]: string }
16+
lineHeights: { [key: string]: string }
17+
borderWidths: { [key: string]: string }
18+
shadows: { [key: string]: string }
19+
sizes: { [key: string]: string }
20+
space: { [key: string]: string }
21+
}
22+
23+
declare const theme: Theme
24+
25+
export default theme

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -3061,6 +3061,11 @@
30613061
unique-filename "^1.1.1"
30623062
which "^1.3.1"
30633063

3064+
"@fortawesome/fontawesome-common-types@^0.2.36":
3065+
version "0.2.36"
3066+
resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-common-types/-/fontawesome-common-types-0.2.36.tgz#b44e52db3b6b20523e0c57ef8c42d315532cb903"
3067+
integrity sha512-a/7BiSgobHAgBWeN7N0w+lAhInrGxksn13uK7231n2m8EDPE3BMCl9NZLTGrj9ZXfCmC6LM0QLqXidIizVQ6yg==
3068+
30643069
"@gulp-sourcemaps/[email protected]":
30653070
version "1.0.0"
30663071
resolved "https://registry.yarnpkg.com/@gulp-sourcemaps/map-sources/-/map-sources-1.0.0.tgz#890ae7c5d8c877f6d384860215ace9d7ec945bda"

0 commit comments

Comments
 (0)