-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
20c6bc3
commit 9568972
Showing
13 changed files
with
151 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { mount } from '@vue/test-utils'; | ||
import CLabel from './CLabel'; | ||
|
||
describe('CLabel', () => { | ||
it('renders with config class', () => { | ||
const wrapper = mount(CLabel, { | ||
global: { | ||
provide: { | ||
$chusho: { | ||
options: { | ||
components: { | ||
label: { | ||
class: 'label', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
expect(wrapper.classes()).toEqual(['label']); | ||
}); | ||
|
||
it('renders default slot and attributes', () => { | ||
const wrapper = mount(CLabel, { | ||
attrs: { | ||
for: 'the-field', | ||
}, | ||
slots: { | ||
default: 'Label', | ||
}, | ||
}); | ||
|
||
expect(wrapper.html()).toBe('<label for="the-field">Label</label>'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { defineComponent, h, inject, mergeProps } from 'vue'; | ||
|
||
import { DollarChusho } from '../../types'; | ||
import { generateConfigClass } from '../../utils/components'; | ||
import componentMixin from '../mixins/componentMixin'; | ||
|
||
export default defineComponent({ | ||
name: 'CLabel', | ||
|
||
mixins: [componentMixin], | ||
|
||
inheritAttrs: false, | ||
|
||
render() { | ||
const labelConfig = inject<DollarChusho | null>('$chusho', null)?.options | ||
?.components?.label; | ||
const attrs: Record<string, unknown> = { | ||
...generateConfigClass(labelConfig?.class, this.$props), | ||
}; | ||
|
||
return h('label', mergeProps(this.$attrs, attrs), this.$slots); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import CLabel from './CLabel'; | ||
|
||
export { CLabel }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/chusho/src/components/examples/components/label/Default.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<template> | ||
<CLabel>Label</CLabel> | ||
</template> |
5 changes: 5 additions & 0 deletions
5
packages/chusho/src/components/examples/components/label/WithCheckbox.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<template> | ||
<CLabel variant="inline" for="my-field"> | ||
<CCheckbox id="my-field" variant="inline" /> Label | ||
</CLabel> | ||
</template> |
4 changes: 4 additions & 0 deletions
4
packages/chusho/src/components/examples/components/label/WithTextField.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<template> | ||
<CLabel for="my-field">Label</CLabel> | ||
<CTextField id="my-field" /> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Label | ||
|
||
Just like a regular `<label />` | ||
|
||
<Showcase> | ||
<CLabel> | ||
I’m a label! | ||
</CLabel> | ||
</Showcase> | ||
|
||
## Config | ||
|
||
The options below are to be set in the [global configuration](/guide/config.html) at the following location: | ||
|
||
```js | ||
{ | ||
components: { | ||
label: { ... }, | ||
}, | ||
} | ||
``` | ||
|
||
### class | ||
|
||
Classes applied to the label element, except when the prop `bare` is set to `true`. See [styling components](/guide/styling-components/). | ||
|
||
- **type:** `Array<String | Object> | Object | String | (props: Object) => {}` | ||
- **default:** `null` | ||
|
||
#### Example | ||
|
||
```js | ||
class: 'label' | ||
``` | ||
|
||
## API | ||
|
||
<Docgen :components="['CLabel']" /> | ||
|
||
## Examples | ||
|
||
### Simplest | ||
|
||
```vue:no-line-numbers | ||
<CLabel>Label</CLabel> | ||
``` | ||
|
||
### Linked to a field | ||
|
||
```vue | ||
<CLabel for="the-field"> | ||
<CCheckbox id="the-field" /> Something labelling the checkbox | ||
</CLabel> | ||
``` |