mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 12:14:41 +01:00
chore(Container): add component
This commit is contained in:
36
src/runtime/components/Container.vue
Normal file
36
src/runtime/components/Container.vue
Normal file
@@ -0,0 +1,36 @@
|
||||
<script lang="ts">
|
||||
import { tv } from 'tailwind-variants'
|
||||
// import appConfig from '#build/app.config'
|
||||
import theme from '#ui/theme/container'
|
||||
|
||||
const appContainer = tv(theme)
|
||||
// const appContainer = tv({ extend: container, ...(appConfig.ui?.container || {}) })
|
||||
|
||||
export interface ContainerProps {
|
||||
as?: string
|
||||
class?: any
|
||||
ui?: Partial<typeof appContainer>
|
||||
}
|
||||
</script>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
|
||||
defineOptions({ inheritAttrs: false })
|
||||
|
||||
const props = withDefaults(defineProps<ContainerProps>(), {
|
||||
as: 'div',
|
||||
class: undefined,
|
||||
ui: undefined
|
||||
})
|
||||
|
||||
// Computed
|
||||
|
||||
const ui = computed(() => tv({ extend: appContainer, ...props.ui })({ class: props.class }))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<component :is="as" :class="ui" v-bind="$attrs">
|
||||
<slot />
|
||||
</component>
|
||||
</template>
|
||||
3
src/runtime/theme/container.ts
Normal file
3
src/runtime/theme/container.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export default {
|
||||
base: 'max-w-7xl mx-auto px-4 sm:px-6 lg:px-8'
|
||||
}
|
||||
15
test/components/Container.spec.ts
Normal file
15
test/components/Container.spec.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import Container, { type ContainerProps } from '../../src/runtime/components/Container.vue'
|
||||
import ComponentRender from '../component-render'
|
||||
|
||||
describe('Container', () => {
|
||||
it.each([
|
||||
['basic case', {}],
|
||||
['with as', { props: { as: 'article' } }],
|
||||
['with class', { props: { class: 'max-w-5xl' } }],
|
||||
['with default slot', { slots: { default: () => 'Default slot' } }]
|
||||
])('renders %s correctly', async (nameOrHtml: string, options: { props?: ContainerProps, slots?: any }) => {
|
||||
const html = await ComponentRender(nameOrHtml, options, Container)
|
||||
expect(html).toMatchSnapshot()
|
||||
})
|
||||
})
|
||||
9
test/components/__snapshots__/Container.spec.ts.snap
Normal file
9
test/components/__snapshots__/Container.spec.ts.snap
Normal file
@@ -0,0 +1,9 @@
|
||||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||
|
||||
exports[`Container > renders basic case correctly 1`] = `"<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8"></div>"`;
|
||||
|
||||
exports[`Container > renders with as correctly 1`] = `"<article class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8"></article>"`;
|
||||
|
||||
exports[`Container > renders with class correctly 1`] = `"<div class="mx-auto px-4 sm:px-6 lg:px-8 max-w-5xl"></div>"`;
|
||||
|
||||
exports[`Container > renders with default slot correctly 1`] = `"<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">Default slot</div>"`;
|
||||
Reference in New Issue
Block a user