Skip to content

Commit

Permalink
feat(core): package direction (#263)
Browse files Browse the repository at this point in the history
* core package direction (#243)

* fix: lint issues

* fix
  • Loading branch information
wramzo authored Aug 3, 2023
1 parent d098e4c commit c3792a3
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 6 deletions.
7 changes: 7 additions & 0 deletions packages/components/direction/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# `@oku-ui/direction`

## Installation

```sh
$ pnpm add @oku-ui/direction
```
12 changes: 12 additions & 0 deletions packages/components/direction/build.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineBuildConfig } from 'unbuild'

export default defineBuildConfig({
entries: [
{
builder: 'mkdist',
input: './src/',
pattern: ['**/!(*.test|*.stories).ts'],
},
],
declaration: true,
})
44 changes: 44 additions & 0 deletions packages/components/direction/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "@oku-ui/direction",
"type": "module",
"version": "0.2.3",
"license": "MIT",
"source": "src/index.ts",
"funding": "https://github.com/sponsors/productdevbook",
"homepage": "https://oku-ui.com/primitives",
"repository": {
"type": "git",
"url": "git+https://github.com/oku-ui/primitives.git",
"directory": "packages/components/direction"
},
"bugs": {
"url": "https://github.com/oku-ui/primitives/issues"
},
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs"
}
},
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"engines": {
"node": ">=18"
},
"scripts": {
"build": "tsup",
"dev": "tsup --watch"
},
"peerDependencies": {
"vue": "^3.3.0"
},
"devDependencies": {
"tsconfig": "workspace:^"
},
"publishConfig": {
"access": "public"
}
}
35 changes: 35 additions & 0 deletions packages/components/direction/src/Direction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { type PropType, defineComponent, inject, provide } from 'vue'

type Direction = 'ltr' | 'rtl'
const DirectionContextSymbol = Symbol('DirectionContext')

/* -------------------------------------------------------------------------------------------------
* Direction
* ----------------------------------------------------------------------------------------------- */

const DirectionProvider = defineComponent({
name: 'DirectionProvider',
props: {
dir: { type: String as PropType<Direction>, required: true },
},
setup(props, { slots }) {
// Direction context
provide(DirectionContextSymbol, props.dir)
return () => slots.default?.()
},
})

/* ----------------------------------------------------------------------------------------------- */

function useDirection(localDir?: Direction) {
const globalDir = inject(DirectionContextSymbol, null)
return localDir || globalDir || 'ltr'
}

const Provider = DirectionProvider

export {
useDirection,
Provider,
DirectionProvider,
}
7 changes: 7 additions & 0 deletions packages/components/direction/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export {
useDirection,
//
Provider,
//
DirectionProvider,
} from './Direction'
10 changes: 10 additions & 0 deletions packages/components/direction/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "tsconfig/node16.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "dist"
},
"include": [
"src"
]
}
21 changes: 21 additions & 0 deletions packages/components/direction/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { defineConfig } from 'tsup'
import pkg from './package.json'

const external = [
...Object.keys(pkg.peerDependencies || {}),
]

export default defineConfig((options) => {
return [
{
...options,
entryPoints: ['src/index.ts'],
external,
dts: true,
clean: true,
target: 'node16',
format: ['esm'],
outExtension: () => ({ js: '.mjs' }),
},
]
})
17 changes: 11 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c3792a3

Please sign in to comment.