@hanzogui/stacks 2.0.0

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.
Files changed (97) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/NestingContext.cjs +38 -0
  3. package/dist/cjs/NestingContext.native.js +41 -0
  4. package/dist/cjs/NestingContext.native.js.map +1 -0
  5. package/dist/cjs/SizableStack.cjs +48 -0
  6. package/dist/cjs/SizableStack.native.js +53 -0
  7. package/dist/cjs/SizableStack.native.js.map +1 -0
  8. package/dist/cjs/Stacks.cjs +60 -0
  9. package/dist/cjs/Stacks.native.js +63 -0
  10. package/dist/cjs/Stacks.native.js.map +1 -0
  11. package/dist/cjs/ThemeableStack.cjs +61 -0
  12. package/dist/cjs/ThemeableStack.native.js +64 -0
  13. package/dist/cjs/ThemeableStack.native.js.map +1 -0
  14. package/dist/cjs/getElevation.cjs +59 -0
  15. package/dist/cjs/getElevation.native.js +66 -0
  16. package/dist/cjs/getElevation.native.js.map +1 -0
  17. package/dist/cjs/index.cjs +22 -0
  18. package/dist/cjs/index.native.js +25 -0
  19. package/dist/cjs/index.native.js.map +1 -0
  20. package/dist/cjs/variants.cjs +60 -0
  21. package/dist/cjs/variants.native.js +69 -0
  22. package/dist/cjs/variants.native.js.map +1 -0
  23. package/dist/esm/NestingContext.mjs +4 -0
  24. package/dist/esm/NestingContext.mjs.map +1 -0
  25. package/dist/esm/NestingContext.native.js +4 -0
  26. package/dist/esm/NestingContext.native.js.map +1 -0
  27. package/dist/esm/SizableStack.mjs +25 -0
  28. package/dist/esm/SizableStack.mjs.map +1 -0
  29. package/dist/esm/SizableStack.native.js +27 -0
  30. package/dist/esm/SizableStack.native.js.map +1 -0
  31. package/dist/esm/Stacks.mjs +34 -0
  32. package/dist/esm/Stacks.mjs.map +1 -0
  33. package/dist/esm/Stacks.native.js +34 -0
  34. package/dist/esm/Stacks.native.js.map +1 -0
  35. package/dist/esm/ThemeableStack.mjs +37 -0
  36. package/dist/esm/ThemeableStack.mjs.map +1 -0
  37. package/dist/esm/ThemeableStack.native.js +37 -0
  38. package/dist/esm/ThemeableStack.native.js.map +1 -0
  39. package/dist/esm/getElevation.mjs +35 -0
  40. package/dist/esm/getElevation.mjs.map +1 -0
  41. package/dist/esm/getElevation.native.js +39 -0
  42. package/dist/esm/getElevation.native.js.map +1 -0
  43. package/dist/esm/index.js +6 -0
  44. package/dist/esm/index.js.map +1 -0
  45. package/dist/esm/index.mjs +6 -0
  46. package/dist/esm/index.mjs.map +1 -0
  47. package/dist/esm/index.native.js +6 -0
  48. package/dist/esm/index.native.js.map +1 -0
  49. package/dist/esm/variants.mjs +35 -0
  50. package/dist/esm/variants.mjs.map +1 -0
  51. package/dist/esm/variants.native.js +41 -0
  52. package/dist/esm/variants.native.js.map +1 -0
  53. package/dist/jsx/NestingContext.mjs +4 -0
  54. package/dist/jsx/NestingContext.mjs.map +1 -0
  55. package/dist/jsx/NestingContext.native.js +41 -0
  56. package/dist/jsx/NestingContext.native.js.map +1 -0
  57. package/dist/jsx/SizableStack.mjs +25 -0
  58. package/dist/jsx/SizableStack.mjs.map +1 -0
  59. package/dist/jsx/SizableStack.native.js +53 -0
  60. package/dist/jsx/SizableStack.native.js.map +1 -0
  61. package/dist/jsx/Stacks.mjs +34 -0
  62. package/dist/jsx/Stacks.mjs.map +1 -0
  63. package/dist/jsx/Stacks.native.js +63 -0
  64. package/dist/jsx/Stacks.native.js.map +1 -0
  65. package/dist/jsx/ThemeableStack.mjs +37 -0
  66. package/dist/jsx/ThemeableStack.mjs.map +1 -0
  67. package/dist/jsx/ThemeableStack.native.js +64 -0
  68. package/dist/jsx/ThemeableStack.native.js.map +1 -0
  69. package/dist/jsx/getElevation.mjs +35 -0
  70. package/dist/jsx/getElevation.mjs.map +1 -0
  71. package/dist/jsx/getElevation.native.js +66 -0
  72. package/dist/jsx/getElevation.native.js.map +1 -0
  73. package/dist/jsx/index.js +6 -0
  74. package/dist/jsx/index.js.map +1 -0
  75. package/dist/jsx/index.mjs +6 -0
  76. package/dist/jsx/index.mjs.map +1 -0
  77. package/dist/jsx/index.native.js +25 -0
  78. package/dist/jsx/index.native.js.map +1 -0
  79. package/dist/jsx/variants.mjs +35 -0
  80. package/dist/jsx/variants.mjs.map +1 -0
  81. package/dist/jsx/variants.native.js +69 -0
  82. package/dist/jsx/variants.native.js.map +1 -0
  83. package/package.json +52 -0
  84. package/src/NestingContext.tsx +3 -0
  85. package/src/SizableStack.tsx +33 -0
  86. package/src/Stacks.tsx +74 -0
  87. package/src/ThemeableStack.tsx +47 -0
  88. package/src/getElevation.tsx +47 -0
  89. package/src/index.ts +5 -0
  90. package/src/variants.tsx +38 -0
  91. package/types/NestingContext.d.ts +3 -0
  92. package/types/SizableStack.d.ts +14 -0
  93. package/types/Stacks.d.ts +43 -0
  94. package/types/ThemeableStack.d.ts +87 -0
  95. package/types/getElevation.d.ts +12 -0
  96. package/types/index.d.ts +6 -0
  97. package/types/variants.d.ts +28 -0
@@ -0,0 +1,33 @@
1
+ import { styled } from '@hanzogui/core'
2
+ import { getButtonSized } from '@hanzogui/get-button-sized'
3
+ import type { GetProps } from '@hanzogui/web'
4
+ import { ThemeableStack } from './ThemeableStack'
5
+ import { bordered, circular, elevate } from './variants'
6
+
7
+ export const SizableStack = styled(ThemeableStack, {
8
+ name: 'SizableStack',
9
+
10
+ variants: {
11
+ unstyled: {
12
+ true: {
13
+ elevate: false,
14
+ bordered: false,
15
+ },
16
+ },
17
+
18
+ circular,
19
+ elevate,
20
+
21
+ bordered: {
22
+ true: bordered,
23
+ },
24
+
25
+ size: {
26
+ '...size': (val, extras) => {
27
+ return getButtonSized(val, extras)
28
+ },
29
+ },
30
+ } as const,
31
+ })
32
+
33
+ export type SizableStackProps = GetProps<typeof SizableStack>
package/src/Stacks.tsx ADDED
@@ -0,0 +1,74 @@
1
+ import type { GetProps, SizeTokens } from '@hanzogui/core'
2
+ import { View, styled } from '@hanzogui/core'
3
+
4
+ import { getElevation } from './getElevation'
5
+
6
+ export interface StackVariants {
7
+ /**
8
+ * @deprecated use `inset: 0, position: 'absolute'` instead
9
+ */
10
+ fullscreen?: boolean
11
+
12
+ elevation?: number | SizeTokens
13
+ }
14
+
15
+ export type YStackProps = Omit<GetProps<typeof YStack>, keyof StackVariants> &
16
+ StackVariants
17
+
18
+ export type XStackProps = YStackProps
19
+ export type ZStackProps = YStackProps
20
+
21
+ export const fullscreenStyle = {
22
+ position: 'absolute',
23
+ inset: 0,
24
+ } as const
25
+
26
+ const variants = {
27
+ fullscreen: {
28
+ true: fullscreenStyle,
29
+ },
30
+
31
+ elevation: {
32
+ '...size': getElevation,
33
+ ':number': getElevation,
34
+ },
35
+ } as const
36
+
37
+ /**
38
+ * @summary A view that arranges its children in a vertical line.
39
+ * @see — Docs https://gui.dev/ui/stacks#xstack-ystack-zstack
40
+ */
41
+ export const YStack = styled(View, {
42
+ flexDirection: 'column',
43
+ variants,
44
+ })
45
+
46
+ YStack['displayName'] = 'YStack'
47
+
48
+ /**
49
+ * @summary A view that arranges its children in a horizontal line.
50
+ * @see — Docs https://gui.dev/ui/stacks#xstack-ystack-zstack
51
+ */
52
+ export const XStack = styled(View, {
53
+ flexDirection: 'row',
54
+ variants,
55
+ })
56
+
57
+ XStack['displayName'] = 'XStack'
58
+
59
+ /**
60
+ * @summary A view that stacks its children on top of each other.
61
+ * @see — Docs https://gui.dev/ui/stacks#xstack-ystack-zstack
62
+ */
63
+ export const ZStack = styled(
64
+ YStack,
65
+ {
66
+ position: 'relative',
67
+ },
68
+ {
69
+ neverFlatten: true,
70
+ isZStack: true,
71
+ }
72
+ )
73
+
74
+ ZStack['displayName'] = 'ZStack'
@@ -0,0 +1,47 @@
1
+ import type { GetProps } from '@hanzogui/core'
2
+ import { styled } from '@hanzogui/core'
3
+
4
+ import { YStack } from './Stacks'
5
+
6
+ import { bordered, circular, elevate } from './variants'
7
+
8
+ const chromelessStyle = {
9
+ backgroundColor: 'transparent',
10
+ borderColor: 'transparent',
11
+ shadowColor: 'transparent',
12
+
13
+ hoverStyle: {
14
+ borderColor: 'transparent',
15
+ },
16
+ }
17
+
18
+ export const themeableVariants = {
19
+ circular,
20
+ elevate,
21
+
22
+ bordered: {
23
+ true: bordered,
24
+ },
25
+
26
+ transparent: {
27
+ true: {
28
+ backgroundColor: 'transparent',
29
+ },
30
+ },
31
+
32
+ chromeless: {
33
+ true: chromelessStyle,
34
+ all: {
35
+ ...chromelessStyle,
36
+ hoverStyle: chromelessStyle,
37
+ pressStyle: chromelessStyle,
38
+ focusStyle: chromelessStyle,
39
+ },
40
+ },
41
+ } as const
42
+
43
+ export const ThemeableStack = styled(YStack, {
44
+ variants: themeableVariants,
45
+ })
46
+
47
+ export type ThemeableStackProps = GetProps<typeof ThemeableStack>
@@ -0,0 +1,47 @@
1
+ import type {
2
+ SizeTokens,
3
+ SizeVariantSpreadFunction,
4
+ ViewProps,
5
+ VariantSpreadExtras,
6
+ } from '@hanzogui/core'
7
+ import { getVariableValue, isAndroid, isVariable } from '@hanzogui/core'
8
+
9
+ export const getElevation: SizeVariantSpreadFunction<ViewProps> = (size, extras) => {
10
+ if (!size) return
11
+ const { tokens } = extras
12
+ const token = tokens.size[size]
13
+ const sizeNum = (isVariable(token) ? +token.val : size) as number
14
+ return getSizedElevation(sizeNum, extras)
15
+ }
16
+
17
+ export const getSizedElevation = (
18
+ val: SizeTokens | number | boolean,
19
+ { theme, tokens }: VariantSpreadExtras<any>
20
+ ) => {
21
+ let num = 0
22
+ if (val === true) {
23
+ const val = getVariableValue(tokens.size['true'])
24
+ if (typeof val === 'number') {
25
+ num = val
26
+ } else {
27
+ num = 10
28
+ }
29
+ } else {
30
+ num = +val
31
+ }
32
+ if (num === 0) {
33
+ return
34
+ }
35
+ const [height, shadowRadius] = [Math.round(num / 4 + 1), Math.round(num / 2 + 2)]
36
+ const shadow = {
37
+ shadowColor: theme.shadowColor,
38
+ shadowRadius,
39
+ shadowOffset: { height, width: 0 },
40
+ ...(isAndroid
41
+ ? {
42
+ elevationAndroid: 2 * height,
43
+ }
44
+ : {}),
45
+ }
46
+ return shadow
47
+ }
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from './Stacks'
2
+ export * from './ThemeableStack'
3
+ export * from './SizableStack'
4
+ export * from './NestingContext'
5
+ export * from './getElevation'
@@ -0,0 +1,38 @@
1
+ import { getElevation } from './getElevation'
2
+
3
+ export const elevate = {
4
+ true: (_: boolean, extras: any) => {
5
+ return getElevation(extras.props['size'], extras) as any
6
+ },
7
+ }
8
+
9
+ export const bordered = (val: boolean | number, { props }) => {
10
+ return {
11
+ // TODO size it with size in '...size'
12
+ borderWidth: typeof val === 'number' ? val : 1,
13
+ borderColor: '$borderColor',
14
+ }
15
+ }
16
+
17
+ const circularStyle = {
18
+ borderRadius: 100_000,
19
+ padding: 0,
20
+ }
21
+
22
+ export const circular = {
23
+ true: (_, { props, tokens }) => {
24
+ if (!('size' in props)) {
25
+ return circularStyle
26
+ }
27
+ const size = typeof props.size === 'number' ? props.size : tokens.size[props.size]
28
+ return {
29
+ ...circularStyle,
30
+ width: size,
31
+ height: size,
32
+ maxWidth: size,
33
+ maxHeight: size,
34
+ minWidth: size,
35
+ minHeight: size,
36
+ }
37
+ },
38
+ }
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ export declare const ButtonNestingContext: React.Context<boolean>;
3
+ //# sourceMappingURL=NestingContext.d.ts.map
@@ -0,0 +1,14 @@
1
+ import type { GetProps } from '@gui/web';
2
+ export declare const SizableStack: import("@gui/core").GuiComponent<import("@gui/core").TamaDefer, import("@gui/core").GuiElement, import("@gui/core").RNGuiViewNonStyleProps, import("@gui/core").StackStyleBase, {
3
+ size?: import("@gui/core").SizeTokens | undefined;
4
+ unstyled?: boolean | undefined;
5
+ elevation?: number | import("@gui/core").SizeTokens | undefined;
6
+ transparent?: boolean | undefined;
7
+ fullscreen?: boolean | undefined;
8
+ circular?: boolean | undefined;
9
+ elevate?: boolean | undefined;
10
+ bordered?: boolean | undefined;
11
+ chromeless?: boolean | "all" | undefined;
12
+ }, import("@gui/core").StaticConfigPublic>;
13
+ export type SizableStackProps = GetProps<typeof SizableStack>;
14
+ //# sourceMappingURL=SizableStack.d.ts.map
@@ -0,0 +1,43 @@
1
+ import type { GetProps, SizeTokens } from '@gui/core';
2
+ export interface StackVariants {
3
+ /**
4
+ * @deprecated use `inset: 0, position: 'absolute'` instead
5
+ */
6
+ fullscreen?: boolean;
7
+ elevation?: number | SizeTokens;
8
+ }
9
+ export type YStackProps = Omit<GetProps<typeof YStack>, keyof StackVariants> & StackVariants;
10
+ export type XStackProps = YStackProps;
11
+ export type ZStackProps = YStackProps;
12
+ export declare const fullscreenStyle: {
13
+ readonly position: "absolute";
14
+ readonly inset: 0;
15
+ };
16
+ /**
17
+ * @summary A view that arranges its children in a vertical line.
18
+ * @see — Docs https://gui.dev/ui/stacks#xstack-ystack-zstack
19
+ */
20
+ export declare const YStack: import("@gui/core").GuiComponent<import("@gui/core").TamaDefer, import("@gui/core").GuiElement, import("@gui/core").RNGuiViewNonStyleProps, import("@gui/core").StackStyleBase, {
21
+ elevation?: number | SizeTokens | undefined;
22
+ fullscreen?: boolean | undefined;
23
+ }, import("@gui/core").StaticConfigPublic>;
24
+ /**
25
+ * @summary A view that arranges its children in a horizontal line.
26
+ * @see — Docs https://gui.dev/ui/stacks#xstack-ystack-zstack
27
+ */
28
+ export declare const XStack: import("@gui/core").GuiComponent<import("@gui/core").TamaDefer, import("@gui/core").GuiElement, import("@gui/core").RNGuiViewNonStyleProps, import("@gui/core").StackStyleBase, {
29
+ elevation?: number | SizeTokens | undefined;
30
+ fullscreen?: boolean | undefined;
31
+ }, import("@gui/core").StaticConfigPublic>;
32
+ /**
33
+ * @summary A view that stacks its children on top of each other.
34
+ * @see — Docs https://gui.dev/ui/stacks#xstack-ystack-zstack
35
+ */
36
+ export declare const ZStack: import("@gui/core").GuiComponent<import("@gui/core").TamaDefer, import("@gui/core").GuiElement, import("@gui/core").RNGuiViewNonStyleProps, import("@gui/core").StackStyleBase, {
37
+ elevation?: number | SizeTokens | undefined;
38
+ fullscreen?: boolean | undefined;
39
+ }, import("@gui/core").StaticConfigPublic & {
40
+ neverFlatten: true;
41
+ isZStack: true;
42
+ }>;
43
+ //# sourceMappingURL=Stacks.d.ts.map
@@ -0,0 +1,87 @@
1
+ import type { GetProps } from '@gui/core';
2
+ export declare const themeableVariants: {
3
+ readonly circular: {
4
+ true: (_: any, { props, tokens }: {
5
+ props: any;
6
+ tokens: any;
7
+ }) => {
8
+ borderRadius: number;
9
+ padding: number;
10
+ } | {
11
+ width: any;
12
+ height: any;
13
+ maxWidth: any;
14
+ maxHeight: any;
15
+ minWidth: any;
16
+ minHeight: any;
17
+ borderRadius: number;
18
+ padding: number;
19
+ };
20
+ };
21
+ readonly elevate: {
22
+ true: (_: boolean, extras: any) => any;
23
+ };
24
+ readonly bordered: {
25
+ readonly true: (val: boolean | number, { props }: {
26
+ props: any;
27
+ }) => {
28
+ borderWidth: number;
29
+ borderColor: string;
30
+ };
31
+ };
32
+ readonly transparent: {
33
+ readonly true: {
34
+ readonly backgroundColor: "transparent";
35
+ };
36
+ };
37
+ readonly chromeless: {
38
+ readonly true: {
39
+ backgroundColor: string;
40
+ borderColor: string;
41
+ shadowColor: string;
42
+ hoverStyle: {
43
+ borderColor: string;
44
+ };
45
+ };
46
+ readonly all: {
47
+ readonly hoverStyle: {
48
+ backgroundColor: string;
49
+ borderColor: string;
50
+ shadowColor: string;
51
+ hoverStyle: {
52
+ borderColor: string;
53
+ };
54
+ };
55
+ readonly pressStyle: {
56
+ backgroundColor: string;
57
+ borderColor: string;
58
+ shadowColor: string;
59
+ hoverStyle: {
60
+ borderColor: string;
61
+ };
62
+ };
63
+ readonly focusStyle: {
64
+ backgroundColor: string;
65
+ borderColor: string;
66
+ shadowColor: string;
67
+ hoverStyle: {
68
+ borderColor: string;
69
+ };
70
+ };
71
+ readonly backgroundColor: string;
72
+ readonly borderColor: string;
73
+ readonly shadowColor: string;
74
+ };
75
+ };
76
+ };
77
+ export declare const ThemeableStack: import("@gui/core").GuiComponent<import("@gui/core").TamaDefer, import("@gui/core").GuiElement, import("@gui/core").RNGuiViewNonStyleProps, import("@gui/core").StackStyleBase, {
78
+ elevation?: number | import("@gui/core").SizeTokens | undefined;
79
+ transparent?: boolean | undefined;
80
+ fullscreen?: boolean | undefined;
81
+ circular?: boolean | undefined;
82
+ elevate?: boolean | undefined;
83
+ bordered?: boolean | undefined;
84
+ chromeless?: boolean | "all" | undefined;
85
+ }, import("@gui/core").StaticConfigPublic>;
86
+ export type ThemeableStackProps = GetProps<typeof ThemeableStack>;
87
+ //# sourceMappingURL=ThemeableStack.d.ts.map
@@ -0,0 +1,12 @@
1
+ import type { SizeTokens, SizeVariantSpreadFunction, ViewProps, VariantSpreadExtras } from '@gui/core';
2
+ export declare const getElevation: SizeVariantSpreadFunction<ViewProps>;
3
+ export declare const getSizedElevation: (val: SizeTokens | number | boolean, { theme, tokens }: VariantSpreadExtras<any>) => {
4
+ elevationAndroid?: number | undefined;
5
+ shadowColor: import("@gui/core").Variable<string> | import("@gui/core").Variable<any> | import("@gui/core").Variable<undefined> | undefined;
6
+ shadowRadius: number;
7
+ shadowOffset: {
8
+ height: number;
9
+ width: number;
10
+ };
11
+ } | undefined;
12
+ //# sourceMappingURL=getElevation.d.ts.map
@@ -0,0 +1,6 @@
1
+ export * from './Stacks';
2
+ export * from './ThemeableStack';
3
+ export * from './SizableStack';
4
+ export * from './NestingContext';
5
+ export * from './getElevation';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,28 @@
1
+ export declare const elevate: {
2
+ true: (_: boolean, extras: any) => any;
3
+ };
4
+ export declare const bordered: (val: boolean | number, { props }: {
5
+ props: any;
6
+ }) => {
7
+ borderWidth: number;
8
+ borderColor: string;
9
+ };
10
+ export declare const circular: {
11
+ true: (_: any, { props, tokens }: {
12
+ props: any;
13
+ tokens: any;
14
+ }) => {
15
+ borderRadius: number;
16
+ padding: number;
17
+ } | {
18
+ width: any;
19
+ height: any;
20
+ maxWidth: any;
21
+ maxHeight: any;
22
+ minWidth: any;
23
+ minHeight: any;
24
+ borderRadius: number;
25
+ padding: number;
26
+ };
27
+ };
28
+ //# sourceMappingURL=variants.d.ts.map