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

Commit ab083d4

Browse files
committed
feat(layout): add Text component, test, examples
1 parent df6d7aa commit ab083d4

File tree

5 files changed

+169
-0
lines changed

5 files changed

+169
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<template>
2+
<c-stack spacing="{3}">
3+
<c-text fontSize="6xl">(6xl) In love with React & Next</c-text>
4+
<c-text fontSize="5xl">(5xl) In love with React & Next</c-text>
5+
<c-text fontSize="4xl">(4xl) In love with React & Next</c-text>
6+
<c-text fontSize="3xl">(3xl) In love with React & Next</c-text>
7+
<c-text fontSize="2xl">(2xl) In love with React & Next</c-text>
8+
<c-text fontSize="xl">(xl) In love with React & Next</c-text>
9+
<c-text fontSize="lg">(lg) In love with React & Next</c-text>
10+
<c-text fontSize="md">(md) In love with React & Next</c-text>
11+
<c-text fontSize="sm">(sm) In love with React & Next</c-text>
12+
<c-text fontSize="xs">(xs) In love with React & Next</c-text>
13+
</c-stack>
14+
<c-divider my="4" />
15+
<c-text>truncated:</c-text>
16+
<c-text maxW="sm" isTruncated>
17+
Lorem ipsum is placeholder text commonly used in the graphic, print, and
18+
publishing industries for previewing layouts and visual mockups.
19+
</c-text>
20+
<c-divider my="4" />
21+
<c-text>line clamp:</c-text>
22+
<c-text :noOfLines="[1, 2, 3]" maxW="sm">
23+
"The quick brown fox jumps over the lazy dog" is an English-language
24+
pangram—a sentence that contains all of the letters of the English alphabet.
25+
Owing to its existence, Chakra was created.
26+
</c-text>
27+
</template>

packages/layout/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ export * from './kbd'
1313
export * from './simple-grid'
1414
export * from './spacer'
1515
export * from './stack'
16+
export * from './text'

packages/layout/src/text.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { filterUndefined } from '@chakra-ui/utils'
2+
import {
3+
chakra,
4+
HTMLChakraProps,
5+
ThemingProps,
6+
SystemProps,
7+
useStyleConfig,
8+
DOMElements,
9+
} from '@chakra-ui/vue-system'
10+
import { SNAO, vueThemingProps } from '@chakra-ui/vue-utils'
11+
import {
12+
computed,
13+
defineComponent,
14+
h,
15+
PropType,
16+
ComponentOptionsWithObjectProps,
17+
ComponentPropsOptions,
18+
} from '@vue/runtime-core'
19+
20+
export interface TextProps extends HTMLChakraProps<'p'>, ThemingProps<'Text'> {
21+
/**
22+
* The CSS `text-align` property
23+
* @type SystemProps["textAlign"]
24+
*/
25+
align?: SystemProps['textAlign']
26+
/**
27+
* The CSS `text-decoration` property
28+
* @type SystemProps["textDecoration"]
29+
*/
30+
decoration?: SystemProps['textDecoration']
31+
/**
32+
* The CSS `text-transform` property
33+
* @type SystemProps["textTransform"]
34+
*/
35+
casing?: SystemProps['textTransform']
36+
}
37+
38+
/**
39+
* Used to render texts or paragraphs.
40+
*
41+
* @see Docs https://vue.chakra-ui.com/docs/typography/text
42+
*/
43+
export const CText = defineComponent({
44+
props: {
45+
as: {
46+
type: [Object, String] as PropType<DOMElements>,
47+
default: 'p',
48+
},
49+
align: SNAO as PropType<TextProps['textAlign']>,
50+
decoration: SNAO as PropType<TextProps['textDecoration']>,
51+
casing: SNAO as PropType<TextProps['textTransform']>,
52+
...vueThemingProps,
53+
},
54+
setup(props, { slots, attrs }) {
55+
const styles = useStyleConfig('Text', props)
56+
57+
const aliasedProps = computed(() =>
58+
filterUndefined({
59+
textAlign: props.align,
60+
textDecoration: props.decoration,
61+
textTransform: props.casing,
62+
})
63+
)
64+
65+
return () => {
66+
return h(
67+
chakra(props.as, {
68+
label: 'text',
69+
...aliasedProps.value,
70+
__css: styles.value,
71+
...attrs,
72+
}),
73+
{},
74+
slots
75+
)
76+
}
77+
},
78+
})

packages/layout/tests/__snapshots__/layout.test.ts.snap

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,3 +468,38 @@ exports[`<CStack /> should render properly 1`] = `
468468
</div>
469469
</DocumentFragment>
470470
`;
471+
472+
exports[`<CText /> should render properly 1`] = `
473+
<DocumentFragment>
474+
<p
475+
class="chakra-text css-0"
476+
>
477+
normal:
478+
</p>
479+
<p
480+
class="chakra-text css-n2bes8"
481+
>
482+
(6xl) In love with Vue & Vite & Nuxt
483+
</p>
484+
<p
485+
class="chakra-text css-0"
486+
>
487+
truncated:
488+
</p>
489+
<p
490+
class="chakra-text css-3urtkt"
491+
>
492+
Lorem ipsum is placeholder text commonly used in the graphic, print, and publishing industries for previewing layouts and visual mockups.
493+
</p>
494+
<p
495+
class="chakra-text css-0"
496+
>
497+
line clamp:
498+
</p>
499+
<p
500+
class="chakra-text css-3jijpv"
501+
>
502+
"The quick brown fox jumps over the lazy dog" is an English-language pangram—a sentence that contains all of the letters of the English alphabet. Owing to its existence, Chakra was created.
503+
</p>
504+
</DocumentFragment>
505+
`;

packages/layout/tests/layout.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
COrderedList,
2525
CUnorderedList,
2626
CListIcon,
27+
CText,
2728
} from '../src'
2829
import { CFlex } from '@chakra-ui/vue-next'
2930
import { render, testA11y } from '../../test-utils/src'
@@ -376,3 +377,30 @@ describe('<CSpacer />', () => {
376377
expect(asFragment()).toMatchSnapshot()
377378
})
378379
})
380+
381+
describe('<CText />', () => {
382+
const renderComponent = () =>
383+
render({
384+
components: { CText },
385+
template: `
386+
<c-text>normal:</c-text>
387+
<c-text fontSize="6xl">(6xl) In love with Vue & Vite & Nuxt</c-text>
388+
<c-text>truncated:</c-text>
389+
<c-text maxW="sm" isTruncated>
390+
Lorem ipsum is placeholder text commonly used in the graphic, print, and
391+
publishing industries for previewing layouts and visual mockups.
392+
</c-text>
393+
<c-text>line clamp:</c-text>
394+
<c-text :noOfLines="[1, 2, 3]" maxW="sm">
395+
"The quick brown fox jumps over the lazy dog" is an English-language
396+
pangram—a sentence that contains all of the letters of the English alphabet.
397+
Owing to its existence, Chakra was created.
398+
</c-text>
399+
`,
400+
})
401+
402+
it('should render properly', async () => {
403+
const { asFragment } = renderComponent()
404+
expect(asFragment()).toMatchSnapshot()
405+
})
406+
})

0 commit comments

Comments
 (0)