@tamagui/use-direction 1.0.1-beta.56 → 1.0.1-beta.60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@tamagui/use-direction",
3
- "version": "1.0.1-beta.56",
3
+ "version": "1.0.1-beta.60",
4
4
  "types": "./types/index.d.ts",
5
5
  "main": "dist/cjs",
6
6
  "module": "dist/esm",
7
7
  "module:jsx": "dist/jsx",
8
8
  "files": [
9
+ "src",
9
10
  "types",
10
11
  "dist"
11
12
  ],
@@ -16,7 +17,7 @@
16
17
  "clean:build": "tamagui-build clean:build"
17
18
  },
18
19
  "devDependencies": {
19
- "@tamagui/build": "^1.0.1-beta.56",
20
+ "@tamagui/build": "^1.0.1-beta.60",
20
21
  "react": "*"
21
22
  },
22
23
  "peerDependencies": {
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './useDirection'
@@ -0,0 +1,23 @@
1
+ // forked from https://github.com/radix-ui/primitives/blob/main/packages/react/direction/src/Direction.tsx
2
+
3
+ import * as React from 'react'
4
+
5
+ type Direction = 'ltr' | 'rtl'
6
+ const DirectionContext = React.createContext<Direction | undefined>(undefined)
7
+
8
+ interface DirectionProviderProps {
9
+ children?: React.ReactNode
10
+ dir: Direction
11
+ }
12
+
13
+ export const DirectionProvider: React.FC<DirectionProviderProps> = (props) => {
14
+ const { dir, children } = props
15
+ return <DirectionContext.Provider value={dir}>{children}</DirectionContext.Provider>
16
+ }
17
+
18
+ export function useDirection(localDir?: Direction) {
19
+ const globalDir = React.useContext(DirectionContext)
20
+ return localDir || globalDir || 'ltr'
21
+ }
22
+
23
+ export const Provider = DirectionProvider