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

feat: c-code component #59

Merged
merged 4 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .changeset/khaki-hounds-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
'@chakra-ui/c-accordion': patch
'@chakra-ui/c-alert': patch
'@chakra-ui/c-badge': patch
'@chakra-ui/c-button': patch
'@chakra-ui/c-close-button': patch
'@chakra-ui/c-code': patch
'@chakra-ui/c-color-mode': patch
'@chakra-ui/c-flex': patch
'@chakra-ui/c-icon': patch
'@chakra-ui/c-modal': patch
'@chakra-ui/c-popper': patch
'@chakra-ui/c-portal': patch
'@chakra-ui/c-reset': patch
'@chakra-ui/c-spinner': patch
'@chakra-ui/c-theme-provider': patch
'@chakra-ui/c-visually-hidden': patch
'@chakra-ui/vue-next': patch
'@chakra-ui/nuxt-next': patch
'@chakra-ui/vue-system': patch
'@chakra-ui/vue-test-utils': patch
'@chakra-ui/vue-theme': patch
'@chakra-ui/vue-theme-tools': patch
'@chakra-ui/vue-utils': patch
'@chakra-ui/vue-auto-import': patch
'@chakra-ui/vue-docs': patch
---

Created code component
1 change: 1 addition & 0 deletions docs/.vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function getSetupSidebar() {
{ text: 'Alert', link: '/components/alert' },
{ text: 'Badge', link: '/components/badge' },
{ text: 'Button', link: '/components/button' },
{ text: 'Code', link: '/components/code' },
{ text: 'Icon', link: '/components/icon' },
{ text: 'Spinner', link: '/components/spinner' },
{ text: 'CSS reset', link: '/components/css-reset' },
Expand Down
33 changes: 33 additions & 0 deletions docs/components/code.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Code

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.

## Import

```js
import { CCode } from "@chakra-ui/vue-next"
```

## Usage
```vue
<c-code>hello world</c-code>
```

### Code Color

Pass the `colorScheme` prop to customize the color of the Badge. `colorScheme` can be any **color key** that exists in `theme.colors`.

TODO: Link to theming page

```vue
<c-code>hello world, default</c-code>
<c-code color-scheme="green">hello world, green</c-code>
<c-code color-scheme="red">hello world, red</c-code>
<c-code color-scheme="purple">hello world, purple</c-code>
```

## Props

| Name | Type | Description | Default |
| :---: | :---: | :---: | :---: |
|`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"`|
2 changes: 1 addition & 1 deletion packages/c-close-button/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"dependencies": {
"@chakra-ui/c-icon": "1.0.0-alpha.1",
"@chakra-ui/styled-system": "1.10.0",
"@chakra-ui/styled-system": "^1.10.0",
"@chakra-ui/vue-system": "0.1.0-alpha.1",
"@chakra-ui/vue-utils": "0.1.0-alpha.1"
},
Expand Down
11 changes: 11 additions & 0 deletions packages/c-code/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# @chakra-ui/c-code

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

## Installation

```sh
yarn add @chakra-ui/c-code
# or
npm i @chakra-ui/c-code
```
3 changes: 3 additions & 0 deletions packages/c-code/examples/base-code.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<c-code> hello world! </c-code>
</template>
26 changes: 26 additions & 0 deletions packages/c-code/examples/with-color.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<template>
<chakra.div>
<c-code
v-for="(color, i) in colorSchemes"
:key="i"
:color-scheme="color"
ml="2"
>
{{ color }}
</c-code>
</chakra.div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const colorSchemes = ref([
'gray',
'green',
'red',
'yellow',
'orange',
'purple',
'teal',
])
</script>
1 change: 1 addition & 0 deletions packages/c-code/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './src'
53 changes: 53 additions & 0 deletions packages/c-code/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"name": "@chakra-ui/c-code",
"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",
"version": "0.0.1-alpha.0",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "dist/types/index.d.ts",
"typings": "dist/types/index.d.ts",
"author": "Jonathan Bakebwa <[email protected]>",
"homepage": "https://github.com/chakra-ui/chakra-ui-vue-next#readme",
"license": "MIT",
"files": [
"dist"
],
"exports": {
".": {
"require": "./dist/cjs/index.js",
"default": "./dist/esm/index.js"
}
},
"publishConfig": {
"access": "public"
},
"repository": "https://github.com/chakra-ui/chakra-ui-vue-next/tree/master/packages/c-code",
"bugs": {
"url": "https://github.com/chakra-ui/chakra-ui-vue-next/issues"
},
"sideEffects": false,
"scripts": {
"build": "rimraf ./dist && concurrently yarn:build:*",
"build:esm": "cross-env BABEL_ENV=esm babel src --root-mode upward --extensions .ts,.tsx -d dist/esm --source-maps",
"build:cjs": "cross-env BABEL_ENV=cjs babel src --root-mode upward --extensions .ts,.tsx -d dist/cjs --source-maps",
"build:types": "cross-env tsc --emitDeclarationOnly --declaration --declarationDir dist/types",
"watch": "concurrently yarn:watch:*",
"watch:esm": "cross-env BABEL_ENV=esm babel src --root-mode upward --extensions .ts,.tsx -d dist/esm --source-maps --watch",
"watch:cjs": "cross-env BABEL_ENV=cjs babel src --root-mode upward --extensions .ts,.tsx -d dist/cjs --source-maps --watch",
"watch:types": "cross-env tsc --emitDeclarationOnly --declaration --declarationDir dist/types --watch --incremental"
},
"dependencies": {
"@chakra-ui/utils": "^1.5.0",
"@chakra-ui/vue-system": "0.1.0-alpha.1"
},
"devDependencies": {
"vue": ">=3.0.5"
},
"peerDependencies": {
"@chakra-ui/vue-system": "0.1.0-alpha.1",
"vue": "^3.0.5"
},
"contributors": [
"Vivek Wadhwani <[email protected]>"
]
}
49 changes: 49 additions & 0 deletions packages/c-code/src/code.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { h, defineComponent, PropType, computed } from 'vue'
import {
chakra,
DOMElements,
ThemingProps,
useStyleConfig,
} from '@chakra-ui/vue-system'
import { filterUndefined } from '@chakra-ui/utils'

const CCode = defineComponent({
props: {
as: {
type: [Object, String] as PropType<DOMElements>,
default: 'code',
},
colorScheme: String as PropType<ThemingProps['colorScheme']>,
styleConfig: String as PropType<ThemingProps['styleConfig']>,
},
setup(props, { slots, attrs }) {
return () => {
const themingProps = computed<ThemingProps>(() =>
filterUndefined({
colorScheme: props.colorScheme,
styleConfig: props.styleConfig,
})
)
const styles = useStyleConfig('Code', themingProps.value)

return h(
chakra(props.as),
{
__css: {
display: 'inline-block',
verticalAlign: 'middle',
fontSize: 'sm',
px: '0.2em',
fontFamily: 'mono',
rounded: 'sm',
...styles.value,
},
...attrs,
},
slots
)
}
},
})

export default CCode
1 change: 1 addition & 0 deletions packages/c-code/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as CCode } from './code'
31 changes: 31 additions & 0 deletions packages/c-code/tests/__snapshots__/c-code.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`should render properly 1`] = `
<DocumentFragment>
<code
class="css-1b9x1mh"
>
hello world
</code>
<code
class="css-1hzweom"
>
hello world, red
</code>
<code
class="css-bri9l4"
>
hello world, green
</code>
<code
class="css-1y46pxi"
>
hello world, yellow
</code>
<code
class="css-1kx42k1"
>
hello world, teal
</code>
</DocumentFragment>
`;
28 changes: 28 additions & 0 deletions packages/c-code/tests/c-code.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { CCode } from '../src'
import { render, testA11y } from '../../test-utils/src'

const renderComponent = (props?: any) => {
const base = {
components: {
CCode,
},
template: `
<c-code>hello world</c-code>
<c-code color-scheme="red"> hello world, red </c-code>
<c-code color-scheme="green"> hello world, green </c-code>
<c-code color-scheme="yellow"> hello world, yellow </c-code>
<c-code color-scheme="teal"> hello world, teal </c-code>
`,
...props,
}
return render(base)
}

it('should have no a11y violations', async () => {
await testA11y(renderComponent())
})

it('should render properly', () => {
const { asFragment } = renderComponent()
expect(asFragment()).toMatchSnapshot()
})
4 changes: 4 additions & 0 deletions packages/c-code/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["src"]
}
2 changes: 1 addition & 1 deletion packages/c-modal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"watch:types": "cross-env tsc --emitDeclarationOnly --declaration --declarationDir dist/types --watch --incremental"
},
"dependencies": {
"@chakra-ui/styled-system": "1.10.0",
"@chakra-ui/styled-system": "^1.10.0",
"@chakra-ui/vue-system": "0.1.0-alpha.1",
"@chakra-ui/vue-utils": "0.1.0-alpha.1"
},
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export * from '@chakra-ui/c-button'
// C
export * from '@chakra-ui/c-color-mode'
export * from '@chakra-ui/c-close-button'
export * from '@chakra-ui/c-code'

// F
export * from '@chakra-ui/c-flex'
Expand Down