Skip to content

Commit

Permalink
feat(vue): update nuxt template
Browse files Browse the repository at this point in the history
  • Loading branch information
cschroeter committed Jul 14, 2024
1 parent 7b6ac0e commit 1b47f6a
Show file tree
Hide file tree
Showing 18 changed files with 436 additions and 13,239 deletions.
4 changes: 2 additions & 2 deletions components/vue/src/lib/create-style-context.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { styled } from 'styled-system/jsx'
import type { ElementType } from 'styled-system/types'
import { type ComputedRef, computed, defineComponent, inject, provide } from 'vue'
import { styled } from '../../styled-system/jsx'
import type { ElementType } from '../../styled-system/types'

type Props = Record<string, unknown>
type Recipe = {
Expand Down
25 changes: 23 additions & 2 deletions templates/vue/nuxt/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
node_modules
# Nuxt dev/build outputs
.output
.data
.nuxt
styled-system
.nitro
.cache
dist

# Node dependencies
node_modules

# Logs
logs
*.log

# Misc
.DS_Store
.fleet
.idea

# Local env files
.env
.env.*
!.env.example
12 changes: 12 additions & 0 deletions templates/vue/nuxt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ pnpm install

# yarn
yarn install

# bun
bun install
```

## Development Server
Expand All @@ -30,6 +33,9 @@ pnpm run dev

# yarn
yarn dev

# bun
bun run dev
```

## Production
Expand All @@ -45,6 +51,9 @@ pnpm run build

# yarn
yarn build

# bun
bun run build
```

Locally preview production build:
Expand All @@ -58,6 +67,9 @@ pnpm run preview

# yarn
yarn preview

# bun
bun run preview
```

Check out the [deployment documentation](https://nuxt.com/docs/getting-started/deployment) for more information.
48 changes: 4 additions & 44 deletions templates/vue/nuxt/app.vue
Original file line number Diff line number Diff line change
@@ -1,50 +1,10 @@
<script setup lang="ts">
import { Divider, HStack, Stack, styled } from 'styled-system/jsx'
import { container } from 'styled-system/patterns'
import { card } from 'styled-system/recipes'
import { Button } from '~/components/ui/button'
import { Input } from '~/components/ui/input'
import { Label } from '~/components/ui/label'
const { body, description, footer, header, root, title } = card()
const Typography = styled('p')
import { Button } from '~/components/ui'
</script>

<template>
<div :class="container({ py: '8', maxW: 'md' })">
<div :class="root">
<div :class="header">
<h2 :class="title">Sign Up</h2>
<p :class="description">
Create an account and discover the worlds' best UI component framework.
</p>
</div>
<div :class="body">
<Stack gap="4">
<Stack gap="3" direction="row">
<Button variant="outline" width="full">Google</Button>
<Button variant="outline" width="full">GitHub</Button>
</Stack>
<HStack gap="2">
<Divider />
<Typography color="fg.subtle" textStyle="sm" whiteSpace="nowrap">
or sign up with
</Typography>
<Divider />
</HStack>
<Stack gap="1.5">
<Label htmlFor="name">E-Mail</Label>
<Input id="name" placeholder="Your E-Mail" />
</Stack>
<Stack gap="1.5">
<Label htmlFor="password">Password</Label>
<Input id="password" type="password" placeholder="Your Password" />
</Stack>
</Stack>
</div>
<div :class="footer">
<Button width="full">Create Account</Button>
</div>
</div>
<div>
<NuxtRouteAnnouncer />
<Button>Park UI</Button>
</div>
</template>
4 changes: 0 additions & 4 deletions templates/vue/nuxt/components/ui/button.tsx

This file was deleted.

1 change: 1 addition & 0 deletions templates/vue/nuxt/components/ui/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './primitives'
4 changes: 0 additions & 4 deletions templates/vue/nuxt/components/ui/input.tsx

This file was deleted.

4 changes: 0 additions & 4 deletions templates/vue/nuxt/components/ui/label.tsx

This file was deleted.

6 changes: 6 additions & 0 deletions templates/vue/nuxt/components/ui/primitives/button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { styled } from 'styled-system/jsx'
import { button } from 'styled-system/recipes'
import type { ComponentProps } from 'styled-system/types'

export type ButtonProps = ComponentProps<typeof Button>
export const Button = styled('button', button)
1 change: 1 addition & 0 deletions templates/vue/nuxt/components/ui/primitives/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Button, type ButtonProps } from './button'
61 changes: 0 additions & 61 deletions templates/vue/nuxt/lib/create-style-context.ts

This file was deleted.

55 changes: 55 additions & 0 deletions templates/vue/nuxt/lib/create-style-context.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { styled } from 'styled-system/jsx'
import type { ElementType } from 'styled-system/types'
import { type ComputedRef, computed, defineComponent, inject, provide } from 'vue'

type Props = Record<string, unknown>
type Recipe = {
(props?: Props): Props
splitVariantProps: (props: Props) => [Props, Props]
}
type Slot<R extends Recipe> = keyof ReturnType<R>
type StyleContext<R extends Recipe> = Record<Slot<R>, string>

export const createStyleContext = <R extends Recipe>(recipe: R) => {
const withProvider = <P,>(Component: ElementType, slot: Slot<R>) => {
const StyledComponent = styled(Component)

return defineComponent<P>({
setup(props, { slots }) {
const splittedProps = computed(() => {
return recipe.splitVariantProps(props)
})

const styles = computed(() => {
const [variantProps] = splittedProps.value
return recipe(variantProps) as StyleContext<R>
})

provide('styles', styles)
return () => (
<StyledComponent {...splittedProps.value[1]} class={styles.value[slot]}>
{slots.default?.()}
</StyledComponent>
)
},
})
}

const withContext = <P,>(Component: ElementType, slot: Slot<R>) => {
const StyledComponent = styled(Component)

return defineComponent<P>({
setup(props, { slots }) {
const slotStyles = inject<ComputedRef<StyleContext<R>>>('styles')

return () => (
<StyledComponent {...props} class={slotStyles?.value?.[slot]}>
{slots.default?.()}
</StyledComponent>
)
},
})
}

return { withProvider, withContext }
}
4 changes: 2 additions & 2 deletions templates/vue/nuxt/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { createResolver } from '@nuxt/kit'
const { resolve } = createResolver(import.meta.url)

export default defineNuxtConfig({
compatibilityDate: '2024-04-03',
devtools: { enabled: true },
alias: {
'styled-system': resolve('./styled-system'),
},

css: ['@/assets/css/global.css'],

postcss: {
plugins: {
'@pandacss/dev/postcss': {},
Expand Down
Loading

0 comments on commit 1b47f6a

Please sign in to comment.