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

Commit aa0a7d1

Browse files
Merge pull request #59 from devivekw/feat/c-code
feat: c-code component
2 parents ce02d1c + 675a8a1 commit aa0a7d1

File tree

16 files changed

+273
-2
lines changed

16 files changed

+273
-2
lines changed

.changeset/khaki-hounds-hunt.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
'@chakra-ui/c-accordion': patch
3+
'@chakra-ui/c-alert': patch
4+
'@chakra-ui/c-badge': patch
5+
'@chakra-ui/c-button': patch
6+
'@chakra-ui/c-close-button': patch
7+
'@chakra-ui/c-code': patch
8+
'@chakra-ui/c-color-mode': patch
9+
'@chakra-ui/c-flex': patch
10+
'@chakra-ui/c-icon': patch
11+
'@chakra-ui/c-modal': patch
12+
'@chakra-ui/c-popper': patch
13+
'@chakra-ui/c-portal': patch
14+
'@chakra-ui/c-reset': patch
15+
'@chakra-ui/c-spinner': patch
16+
'@chakra-ui/c-theme-provider': patch
17+
'@chakra-ui/c-visually-hidden': patch
18+
'@chakra-ui/vue-next': patch
19+
'@chakra-ui/nuxt-next': patch
20+
'@chakra-ui/vue-system': patch
21+
'@chakra-ui/vue-test-utils': patch
22+
'@chakra-ui/vue-theme': patch
23+
'@chakra-ui/vue-theme-tools': patch
24+
'@chakra-ui/vue-utils': patch
25+
'@chakra-ui/vue-auto-import': patch
26+
'@chakra-ui/vue-docs': patch
27+
---
28+
29+
Created code component

docs/.vitepress/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ function getSetupSidebar() {
5555
{ text: 'Alert', link: '/components/alert' },
5656
{ text: 'Badge', link: '/components/badge' },
5757
{ text: 'Button', link: '/components/button' },
58+
{ text: 'Code', link: '/components/code' },
5859
{ text: 'Icon', link: '/components/icon' },
5960
{ text: 'Spinner', link: '/components/spinner' },
6061
{ text: 'CSS reset', link: '/components/css-reset' },

docs/components/code.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Code
2+
3+
Code is a component used to display inline code. It is composed from the Box component with a font family of `mono` for displaying code.
4+
5+
## Import
6+
7+
```js
8+
import { CCode } from "@chakra-ui/vue-next"
9+
```
10+
11+
## Usage
12+
```vue
13+
<c-code>hello world</c-code>
14+
```
15+
16+
### Code Color
17+
18+
Pass the `colorScheme` prop to customize the color of the Badge. `colorScheme` can be any **color key** that exists in `theme.colors`.
19+
20+
TODO: Link to theming page
21+
22+
```vue
23+
<c-code>hello world, default</c-code>
24+
<c-code color-scheme="green">hello world, green</c-code>
25+
<c-code color-scheme="red">hello world, red</c-code>
26+
<c-code color-scheme="purple">hello world, purple</c-code>
27+
```
28+
29+
## Props
30+
31+
| Name | Type | Description | Default |
32+
| :---: | :---: | :---: | :---: |
33+
|`colorScheme`|`string`|Color Scheme to be applied|"cyan" | "gray" | "green" | "orange" | "pink" | "purple" | "red" | "teal" | "yellow" | "whiteAlpha" | "blackAlpha" | "linkedin" | "facebook" | "messenger" | "whatsapp" | "twitter" | "telegram"`|`"gray"`|

packages/c-close-button/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
},
3939
"dependencies": {
4040
"@chakra-ui/c-icon": "1.0.0-alpha.1",
41-
"@chakra-ui/styled-system": "1.10.0",
41+
"@chakra-ui/styled-system": "^1.10.0",
4242
"@chakra-ui/vue-system": "0.1.0-alpha.1",
4343
"@chakra-ui/vue-utils": "0.1.0-alpha.1"
4444
},

packages/c-code/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# @chakra-ui/c-code
2+
3+
Code is a component used to display inline code. It is composed from the Box component with a font family of mono for displaying code
4+
5+
## Installation
6+
7+
```sh
8+
yarn add @chakra-ui/c-code
9+
# or
10+
npm i @chakra-ui/c-code
11+
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<c-code> hello world! </c-code>
3+
</template>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<template>
2+
<chakra.div>
3+
<c-code
4+
v-for="(color, i) in colorSchemes"
5+
:key="i"
6+
:color-scheme="color"
7+
ml="2"
8+
>
9+
{{ color }}
10+
</c-code>
11+
</chakra.div>
12+
</template>
13+
14+
<script setup lang="ts">
15+
import { ref } from 'vue'
16+
17+
const colorSchemes = ref([
18+
'gray',
19+
'green',
20+
'red',
21+
'yellow',
22+
'orange',
23+
'purple',
24+
'teal',
25+
])
26+
</script>

packages/c-code/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './src'

packages/c-code/package.json

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"name": "@chakra-ui/c-code",
3+
"description": "Chakra UI Vue | Code is a component used to display inline code. It is composed from the Box component with a font family of mono for displaying code",
4+
"version": "0.0.1-alpha.0",
5+
"main": "dist/cjs/index.js",
6+
"module": "dist/esm/index.js",
7+
"types": "dist/types/index.d.ts",
8+
"typings": "dist/types/index.d.ts",
9+
"author": "Jonathan Bakebwa <[email protected]>",
10+
"homepage": "https://github.com/chakra-ui/chakra-ui-vue-next#readme",
11+
"license": "MIT",
12+
"files": [
13+
"dist"
14+
],
15+
"exports": {
16+
".": {
17+
"require": "./dist/cjs/index.js",
18+
"default": "./dist/esm/index.js"
19+
}
20+
},
21+
"publishConfig": {
22+
"access": "public"
23+
},
24+
"repository": "https://github.com/chakra-ui/chakra-ui-vue-next/tree/master/packages/c-code",
25+
"bugs": {
26+
"url": "https://github.com/chakra-ui/chakra-ui-vue-next/issues"
27+
},
28+
"sideEffects": false,
29+
"scripts": {
30+
"build": "rimraf ./dist && concurrently yarn:build:*",
31+
"build:esm": "cross-env BABEL_ENV=esm babel src --root-mode upward --extensions .ts,.tsx -d dist/esm --source-maps",
32+
"build:cjs": "cross-env BABEL_ENV=cjs babel src --root-mode upward --extensions .ts,.tsx -d dist/cjs --source-maps",
33+
"build:types": "cross-env tsc --emitDeclarationOnly --declaration --declarationDir dist/types",
34+
"watch": "concurrently yarn:watch:*",
35+
"watch:esm": "cross-env BABEL_ENV=esm babel src --root-mode upward --extensions .ts,.tsx -d dist/esm --source-maps --watch",
36+
"watch:cjs": "cross-env BABEL_ENV=cjs babel src --root-mode upward --extensions .ts,.tsx -d dist/cjs --source-maps --watch",
37+
"watch:types": "cross-env tsc --emitDeclarationOnly --declaration --declarationDir dist/types --watch --incremental"
38+
},
39+
"dependencies": {
40+
"@chakra-ui/utils": "^1.5.0",
41+
"@chakra-ui/vue-system": "0.1.0-alpha.1"
42+
},
43+
"devDependencies": {
44+
"vue": ">=3.0.5"
45+
},
46+
"peerDependencies": {
47+
"@chakra-ui/vue-system": "0.1.0-alpha.1",
48+
"vue": "^3.0.5"
49+
},
50+
"contributors": [
51+
"Vivek Wadhwani <[email protected]>"
52+
]
53+
}

packages/c-code/src/code.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { h, defineComponent, PropType, computed } from 'vue'
2+
import {
3+
chakra,
4+
DOMElements,
5+
ThemingProps,
6+
useStyleConfig,
7+
} from '@chakra-ui/vue-system'
8+
import { filterUndefined } from '@chakra-ui/utils'
9+
10+
const CCode = defineComponent({
11+
props: {
12+
as: {
13+
type: [Object, String] as PropType<DOMElements>,
14+
default: 'code',
15+
},
16+
colorScheme: String as PropType<ThemingProps['colorScheme']>,
17+
styleConfig: String as PropType<ThemingProps['styleConfig']>,
18+
},
19+
setup(props, { slots, attrs }) {
20+
return () => {
21+
const themingProps = computed<ThemingProps>(() =>
22+
filterUndefined({
23+
colorScheme: props.colorScheme,
24+
styleConfig: props.styleConfig,
25+
})
26+
)
27+
const styles = useStyleConfig('Code', themingProps.value)
28+
29+
return h(
30+
chakra(props.as),
31+
{
32+
__css: {
33+
display: 'inline-block',
34+
verticalAlign: 'middle',
35+
fontSize: 'sm',
36+
px: '0.2em',
37+
fontFamily: 'mono',
38+
rounded: 'sm',
39+
...styles.value,
40+
},
41+
...attrs,
42+
},
43+
slots
44+
)
45+
}
46+
},
47+
})
48+
49+
export default CCode

0 commit comments

Comments
 (0)