Skip to content

Commit 99ca259

Browse files
committed
feat: create form-control component and context
1 parent 874ce27 commit 99ca259

22 files changed

+336
-63
lines changed

.DS_Store

-6 KB
Binary file not shown.

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ dist
44
yarn-error.log
55
test-vite-project
66

7+
.DS_Store
8+
79
# Logs
810
logs
911
*.log
@@ -97,6 +99,12 @@ dist
9799

98100
# vscode history extension
99101
.history
102+
103+
# SSG
100104
website/.vite-ssg-temp
105+
106+
# npmrc
101107
.npmrc
108+
109+
# Cypress screenshots generated
102110
cypress/screenshots

README.md

+9-10
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,24 @@ The official working repository for V1 of Chakra UI Vue with Vue 3 support.
99
yarn install
1010
```
1111

12-
### Build components
12+
### Watch components
1313
```bash
14-
yarn build
15-
```
16-
17-
### Bootstrap and link packages
18-
```bash
19-
yarn bootstrap
14+
yarn start
2015
```
2116

2217
### Component playground (based on vite)
2318
```bash
24-
yarn dev
19+
# In one background terminal (Only needs to be run once)
20+
yarn start
21+
22+
# In another terminal
23+
yarn playground:dev
2524
```
2625

2726
## Development Guide
2827
### Major todos:
29-
- [ ] Documentation
30-
- [ ] Accessibility JS hooks (Documented in Roadmap)
28+
- [-] Documentation (WIP)
29+
- [-] Accessibility JS hooks (WIP, Documented in Roadmap)
3130

3231
### Creating a new commit message
3332
The commits follow the [conventional commit format](https://www.conventionalcommits.org/). Husky is setup to lint your commit messages to match this format.

_templates/generator/component/package.json.ejs.t

+15-21
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ to: packages/<%=h.changeCase.paramCase(name)%>/package.json
55
{
66
"name": "<%= '@chakra-ui/' + h.changeCase.paramCase(name)%>",
77
"description": "<%= 'Chakra UI Vue | ' + h.changeCase.sentence(description) + ' component'%>",
8-
"version": "1.0.0",
9-
"main": "dist/cjs/index.js",
10-
"module": "dist/esm/index.js",
8+
"version": "0.0.0-alpha.0",
9+
"main": "<%= 'dist/chakra-ui-' + h.changeCase.paramCase(name) + '.cjs.js' %>",
10+
"module": "<%= 'dist/chakra-ui-' + h.changeCase.paramCase(name) + '.esm.js' %>",
1111
"author": "Jonathan Bakebwa <codebender828@gmail.com>",
1212
"homepage": "https://github.com/chakra-ui/chakra-ui-vue-next#readme",
1313
"license": "MIT",
@@ -16,13 +16,10 @@ to: packages/<%=h.changeCase.paramCase(name)%>/package.json
1616
],
1717
"exports": {
1818
".": {
19-
"require": "./dist/cjs/index.js",
20-
"default": "./dist/esm/index.js"
19+
"require": "<%= './dist/chakra-ui-' + h.changeCase.paramCase(name) + '.cjs.js' %>",
20+
"default": "<%= './dist/chakra-ui-' + h.changeCase.paramCase(name) + '.esm.js' %>"
2121
}
2222
},
23-
"publishConfig": {
24-
"access": "public"
25-
},
2623
"repository": {
2724
"type": "git",
2825
"url": "git+https://github.com/chakra-ui/chakra-ui-vue-next.git"
@@ -31,22 +28,19 @@ to: packages/<%=h.changeCase.paramCase(name)%>/package.json
3128
"url": "https://github.com/chakra-ui/chakra-ui-vue-next/issues"
3229
},
3330
"sideEffects": false,
34-
"scripts": {
35-
"build": "rimraf ./dist && concurrently yarn:build:*",
36-
"build:esm": "cross-env BABEL_ENV=esm babel src --root-mode upward --extensions .ts,.tsx -d dist/esm --source-maps",
37-
"build:cjs": "cross-env BABEL_ENV=cjs babel src --root-mode upward --extensions .ts,.tsx -d dist/cjs --source-maps",
38-
"build:types": "cross-env tsc --emitDeclarationOnly --declaration --declarationDir dist/types",
39-
"watch": "concurrently yarn:watch:*",
40-
"watch:esm": "cross-env BABEL_ENV=esm babel src --root-mode upward --extensions .ts,.tsx -d dist/esm --source-maps --watch",
41-
"watch:cjs": "cross-env BABEL_ENV=cjs babel src --root-mode upward --extensions .ts,.tsx -d dist/cjs --source-maps --watch",
42-
"watch:types": "cross-env tsc --emitDeclarationOnly --declaration --declarationDir dist/types --watch --incremental"
31+
"scripts": {
32+
"clean": "rimraf dist"
4333
},
4434
"dependencies": {
45-
"@chakra-ui/styled-system": "^1.9.0",
46-
"@chakra-ui/vue-system": "*",
47-
"@chakra-ui/vue-utils": "*"
35+
"@chakra-ui/vue-system": "0.1.0-alpha.5"
36+
},
37+
"devDependencies": {
38+
"vue": "^3.1.4"
4839
},
4940
"peerDependencies": {
50-
"vue": ">=3.0.5"
41+
"vue": "^3.1.4"
42+
},
43+
"publishConfig": {
44+
"access": "public"
5145
}
5246
}

_templates/generator/module/package.json.ejs.t

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ to: packages/<%=h.changeCase.paramCase(name)%>/package.json
44

55
{
66
"name": "<%= '@chakra-ui/' + h.changeCase.paramCase(name)%>",
7-
"version": "1.0.0",
8-
"main": "dist/cjs/index.js",
9-
"module": "dist/esm/index.js",
7+
"version": "0.0.0-alpha.0",
8+
"main": "<%= 'dist/chakra-ui-' + h.changeCase.paramCase(name) + '.cjs.js' %>",
9+
"module": "<%= 'dist/chakra-ui-' + h.changeCase.paramCase(name) + '.esm.js' %>",
1010
"files": [
1111
"dist"
1212
],
1313
"exports": {
1414
".": {
15-
"require": "./dist/cjs/index.js",
16-
"default": "./dist/esm/index.js"
15+
"require": "<%= './dist/chakra-ui-' + h.changeCase.paramCase(name) + '.cjs.js' %>",
16+
"default": "<%= './dist/chakra-ui-' + h.changeCase.paramCase(name) + '.esm.js' %>"
1717
}
1818
},
1919
"description": "<%= 'Chakra UI Vue | ' + h.changeCase.pascalCase(name) + ' module'%>",

docs/guides/component-guide.md

+4-7
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,11 @@ start building, here's what you need to do:
7070
# 1. * Fixes all dependency resolutions in the respository*
7171
yarn pkgs:fix
7272
73-
# 2. * Build core package with export from new component
74-
yarn core build
73+
# 2. Watch packages
74+
yarn start
7575
76-
# 3. Start watching for changes in
77-
yarn pkg chakra-ui/COMPONENT_NAME watch
78-
79-
# 4. Starts development server
80-
yarn dev
76+
# 3. In second terminal, Starts development environment
77+
yarn playground:dev
8178
```
8279

8380

packages/c-form-control/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# @chakra-ui/c-form-control
2+
3+
Form control component is used to manage form controls such input fields checkbox and radio buttons it provides components and context that make your form fields accessible by default
4+
5+
## Installation
6+
7+
```sh
8+
yarn add @chakra-ui/c-form-control
9+
# or
10+
npm i @chakra-ui/c-form-control
11+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<c-form-control> HELLO CFormControl </c-form-control>
3+
</template>

packages/c-form-control/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './src'

packages/c-form-control/package.json

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "@chakra-ui/c-form-control",
3+
"description": "Chakra UI Vue | Form control component is used to manage form controls such input fields checkbox and radio buttons it provides components and context that make your form fields accessible by default component",
4+
"version": "0.0.0-alpha.0",
5+
"main": "dist/chakra-ui-c-form-control.cjs.js",
6+
"module": "dist/chakra-ui-c-form-control.esm.js",
7+
"author": "Jonathan Bakebwa <[email protected]>",
8+
"homepage": "https://github.com/chakra-ui/chakra-ui-vue-next#readme",
9+
"license": "MIT",
10+
"files": [
11+
"dist"
12+
],
13+
"exports": {
14+
".": {
15+
"require": "./dist/chakra-ui-c-form-control.cjs.js",
16+
"default": "./dist/chakra-ui-c-form-control.esm.js"
17+
}
18+
},
19+
"repository": "https://github.com/chakra-ui/chakra-ui-vue-next/tree/master/packages/c-form-control",
20+
"bugs": {
21+
"url": "https://github.com/chakra-ui/chakra-ui-vue-next/issues"
22+
},
23+
"sideEffects": false,
24+
"scripts": {
25+
"clean": "rimraf dist"
26+
},
27+
"dependencies": {
28+
"@chakra-ui/vue-composables": "^0.1.0-alpha.4",
29+
"@chakra-ui/vue-system": "0.1.0-alpha.5",
30+
"@chakra-ui/vue-utils": "^0.1.0-alpha.5",
31+
"@chakra-ui/utils": "^1.8.2"
32+
},
33+
"devDependencies": {
34+
"vue": "^3.1.4"
35+
},
36+
"peerDependencies": {
37+
"vue": "^3.1.4"
38+
},
39+
"publishConfig": {
40+
"access": "public"
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* Hey! Welcome to @chakra-ui/vue-next CFormControl
3+
*
4+
* Form control component is used to manage form controls such input fields checkbox and radio buttons it provides components and context that make your form fields accessible by default
5+
*
6+
* @see Docs https://next.vue.chakra-ui.com/c-form-control
7+
* @see Source https://github.com/chakra-ui/chakra-ui-vue-next/blob/master/packages/c-form-control/src/c-form-control/c-form-control.ts
8+
* @see WAI-ARIA https://www.w3.org/TR/wai-aria-practices-1.2
9+
*/
10+
11+
import { h, defineComponent, ComputedRef, computed, PropType, toRefs } from 'vue'
12+
import { chakra, ComponentWithProps, DeepPartial, DOMElements, useMultiStyleConfig, StylesProvider, omitThemingProps } from '@chakra-ui/vue-system'
13+
import { CFormControlProps, useFormControlProvider } from './use-form-control'
14+
import { mergeWith } from '@chakra-ui/utils'
15+
import { createContext } from '@chakra-ui/vue-utils'
16+
17+
type CFormControlProviderContext = ComputedRef<Omit<
18+
ReturnType<typeof useFormControlProvider>,
19+
"rootProps"
20+
>>
21+
22+
const [
23+
FormControlProvider,
24+
useFormControlContext
25+
] = createContext<CFormControlProviderContext>()
26+
27+
export { useFormControlContext }
28+
29+
/**
30+
* `CFormControl` provides context such as
31+
* `isInvalid`, `isDisabled`, and `isRequired` to form elements.
32+
*
33+
* This is commonly used in form elements such as `input`,
34+
* `select`, `textarea`, etc.
35+
*/
36+
37+
export const CFormControl: ComponentWithProps<
38+
DeepPartial<CFormControlProps>
39+
> = defineComponent({
40+
props: {
41+
as: {
42+
type: [Object, String] as PropType<DOMElements>,
43+
default: 'div',
44+
},
45+
},
46+
setup(_props, { slots, attrs }) {
47+
const { as, ...props } = toRefs(_props)
48+
const ownProps = computed(() => props)
49+
const styles = useMultiStyleConfig('Form', props)
50+
51+
const { rootProps, ..._context } = useFormControlProvider(ownProps.value)
52+
53+
const context: CFormControlProviderContext = computed(() => _context)
54+
55+
FormControlProvider(context)
56+
StylesProvider(styles)
57+
58+
return () => (
59+
<chakra.div as={as.value} {...rootProps.value} __css={styles.value.container} __label="form-control">
60+
{slots}
61+
</chakra.div>
62+
)
63+
},
64+
})

packages/c-form-control/src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './c-form-control'
2+
export * from './use-form-control'

0 commit comments

Comments
 (0)