@khanacademy/wonder-blocks-core 4.6.2 → 4.8.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 (101) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/components/id-provider.d.ts +58 -0
  3. package/dist/components/id-provider.js.flow +67 -0
  4. package/{src/components/render-state-context.js → dist/components/render-state-context.d.ts} +6 -10
  5. package/dist/components/render-state-context.js.flow +32 -0
  6. package/dist/components/render-state-root.d.ts +10 -0
  7. package/dist/components/render-state-root.js.flow +19 -0
  8. package/dist/components/text.d.ts +25 -0
  9. package/dist/components/text.js.flow +36 -0
  10. package/dist/components/unique-id-provider.d.ts +69 -0
  11. package/dist/components/unique-id-provider.js.flow +78 -0
  12. package/dist/components/view.d.ts +43 -0
  13. package/dist/components/view.js.flow +54 -0
  14. package/dist/components/with-ssr-placeholder.d.ts +63 -0
  15. package/dist/components/with-ssr-placeholder.js.flow +77 -0
  16. package/dist/es/index.js +143 -137
  17. package/dist/hooks/use-force-update.d.ts +13 -0
  18. package/dist/hooks/use-force-update.js.flow +19 -0
  19. package/dist/hooks/use-is-mounted.d.ts +8 -0
  20. package/dist/hooks/use-is-mounted.js.flow +14 -0
  21. package/dist/hooks/use-on-mount-effect.d.ts +21 -0
  22. package/dist/hooks/use-on-mount-effect.js.flow +29 -0
  23. package/dist/hooks/use-online.d.ts +9 -0
  24. package/dist/hooks/use-online.js.flow +15 -0
  25. package/dist/hooks/use-render-state.d.ts +2 -0
  26. package/dist/hooks/use-render-state.js.flow +12 -0
  27. package/dist/hooks/use-unique-id.d.ts +18 -0
  28. package/dist/hooks/use-unique-id.js.flow +26 -0
  29. package/dist/index.d.ts +17 -0
  30. package/dist/index.js +160 -158
  31. package/dist/index.js.flow +27 -2
  32. package/dist/util/add-style.d.ts +5 -0
  33. package/dist/util/add-style.js.flow +23 -0
  34. package/dist/util/add-styles.flowtest.d.ts +1 -0
  35. package/dist/util/add-styles.flowtest.js.flow +6 -0
  36. package/dist/util/server.d.ts +14 -0
  37. package/dist/util/server.js.flow +22 -0
  38. package/dist/util/ssr-id-factory.d.ts +3 -0
  39. package/dist/util/ssr-id-factory.js.flow +10 -0
  40. package/dist/util/types.d.ts +116 -0
  41. package/dist/util/types.js.flow +219 -0
  42. package/dist/util/unique-id-factory.d.ts +37 -0
  43. package/dist/util/unique-id-factory.js.flow +45 -0
  44. package/dist/util/util.d.ts +8 -0
  45. package/dist/util/util.js.flow +15 -0
  46. package/package.json +3 -4
  47. package/src/components/__tests__/{id-provider.test.js → id-provider.test.tsx} +2 -3
  48. package/src/components/__tests__/{render-state-root.test.js → render-state-root.test.tsx} +4 -9
  49. package/src/components/__tests__/{unique-id-provider.test.js → unique-id-provider.test.tsx} +24 -10
  50. package/src/components/__tests__/view.test.js +2 -2
  51. package/src/components/__tests__/{with-ssr-placeholder.test.js → with-ssr-placeholder.test.tsx} +20 -8
  52. package/src/components/{id-provider.js → id-provider.tsx} +13 -15
  53. package/src/components/render-state-context.ts +28 -0
  54. package/src/components/{render-state-root.js → render-state-root.tsx} +11 -13
  55. package/src/components/{text.js → text.tsx} +9 -14
  56. package/src/components/{unique-id-provider.js → unique-id-provider.tsx} +13 -14
  57. package/src/components/{view.js → view.tsx} +10 -15
  58. package/src/components/{with-ssr-placeholder.js → with-ssr-placeholder.tsx} +15 -21
  59. package/src/hooks/__tests__/{use-force-update.test.js → use-force-update.test.tsx} +3 -3
  60. package/src/hooks/__tests__/{use-is-mounted.test.js → use-is-mounted.test.ts} +4 -2
  61. package/src/hooks/__tests__/{use-on-mount-effect.test.js → use-on-mount-effect.test.ts} +1 -2
  62. package/src/hooks/__tests__/{use-online.test.js → use-online.test.tsx} +3 -2
  63. package/src/hooks/__tests__/{use-render-state.test.js → use-render-state.test.tsx} +6 -11
  64. package/src/hooks/__tests__/{use-unique-id.test.js → use-unique-id.test.tsx} +24 -25
  65. package/src/hooks/{use-force-update.js → use-force-update.ts} +0 -1
  66. package/src/hooks/{use-is-mounted.js → use-is-mounted.ts} +1 -2
  67. package/src/hooks/{use-on-mount-effect.js → use-on-mount-effect.ts} +3 -2
  68. package/src/hooks/{use-online.js → use-online.ts} +1 -2
  69. package/src/hooks/use-render-state.ts +10 -0
  70. package/src/hooks/{use-unique-id.js → use-unique-id.ts} +10 -15
  71. package/src/index.ts +22 -0
  72. package/src/util/__docs__/add-style.stories.mdx +7 -8
  73. package/src/util/__tests__/{add-style.test.js → add-style.test.tsx} +5 -3
  74. package/src/util/__tests__/{server.test.js → server.test.ts} +1 -2
  75. package/src/util/__tests__/{ssr-id-factory.test.js → ssr-id-factory.test.ts} +1 -2
  76. package/src/util/__tests__/{unique-id-factory.test.js → unique-id-factory.test.ts} +1 -2
  77. package/src/util/{add-style.js → add-style.tsx} +16 -24
  78. package/src/util/{add-styles.flowtest.js → add-styles.flowtest.tsx} +3 -4
  79. package/src/util/{server.js → server.ts} +0 -1
  80. package/src/util/{ssr-id-factory.js → ssr-id-factory.ts} +1 -2
  81. package/src/util/types.ts +227 -0
  82. package/src/util/{unique-id-factory.js → unique-id-factory.ts} +3 -4
  83. package/src/util/{util.js → util.ts} +12 -10
  84. package/tsconfig.json +9 -0
  85. package/tsconfig.tsbuildinfo +1 -0
  86. package/src/__docs__/_overview_.stories.mdx +0 -16
  87. package/src/__docs__/exports.use-force-update.stories.mdx +0 -18
  88. package/src/__docs__/exports.use-is-mounted.stories.mdx +0 -19
  89. package/src/__docs__/exports.use-on-mount-effect.stories.mdx +0 -50
  90. package/src/__docs__/exports.use-online.stories.mdx +0 -20
  91. package/src/__docs__/exports.use-render-state.stories.mdx +0 -25
  92. package/src/components/__docs__/id-provider.stories.js +0 -83
  93. package/src/components/__docs__/unique-id-provider.stories.js +0 -125
  94. package/src/components/__docs__/view.argtypes.js +0 -54
  95. package/src/components/__docs__/view.stories.js +0 -145
  96. package/src/components/__docs__/with-ssr-placeholder.stories.js +0 -245
  97. package/src/hooks/use-render-state.js +0 -8
  98. package/src/hooks/use-unique-id.stories.mdx +0 -158
  99. package/src/index.js +0 -27
  100. package/src/util/types.js +0 -239
  101. /package/src/util/__tests__/__snapshots__/{unique-id-factory.test.js.snap → unique-id-factory.test.ts.snap} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # @khanacademy/wonder-blocks-core
2
2
 
3
+ ## 4.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 873f4a14: Update aphrodite lib def and StyleType
8
+
9
+ ### Patch Changes
10
+
11
+ - d816af08: Update build and test configs use TypeScript
12
+ - 3891f544: Update babel config to include plugins that Storybook needed
13
+ - 0d28bb1c: Configured TypeScript
14
+ - 3d05f764: Fix HOCs and other type errors
15
+ - c2ec4902: Update eslint configuration, fix lint
16
+ - 2983c05b: Include 'types' field in package.json
17
+ - 77ff6a66: Generate Flow types from TypeScript types
18
+ - ec8d4b7f: Fix miscellaneous TypeScript errors
19
+
20
+ ## 4.7.0
21
+
22
+ ### Minor Changes
23
+
24
+ - 91cb727c: Convert enums to POJOs
25
+
26
+ ### Patch Changes
27
+
28
+ - 91cb727c: Remove file extensions from imports
29
+
3
30
  ## 4.6.2
4
31
 
5
32
  ### Patch Changes
@@ -0,0 +1,58 @@
1
+ import * as React from "react";
2
+ import type { IIdentifierFactory } from "../util/types";
3
+ type Props = {
4
+ /**
5
+ * Use the children-as-function pattern to pass a uniqueId string for
6
+ * use anywhere within children. This provides a way of adding a unique identifier
7
+ * to a given component for a11y purposes.
8
+ */
9
+ children: (uniqueId: string) => React.ReactElement;
10
+ /**
11
+ * Scope for the unique identifier
12
+ */
13
+ scope: string;
14
+ /**
15
+ * An optional id parameter for the title. If one is
16
+ * not provided, a unique id will be generated.
17
+ */
18
+ id?: string;
19
+ /**
20
+ * Test ID used for e2e testing.
21
+ */
22
+ testId?: string;
23
+ };
24
+ /**
25
+ * This is a wrapper that returns an identifier. If the `id` prop is set, the
26
+ * component will return the same id to be consumed by its children. Otherwise,
27
+ * a unique id will be provided. This is beneficial for accessibility purposes,
28
+ * among other things.
29
+ *
30
+ * The main difference with `UniqueIDProvider` is that `IDProvider` has a single
31
+ * responsibility, to return an identifier that can by used by the children that
32
+ * are rendered internally.
33
+ *
34
+ * This way, the wrapped component will receive this custom ID and will use it
35
+ * to connect different elements.
36
+ *
37
+ * e.g. It uses the same generated id to connect a Dialog with its main title,
38
+ * or form label with the associated input element, etc.
39
+ *
40
+ * ## Usage
41
+ *
42
+ * ```jsx
43
+ * import {IDProvider} from "@khanacademy/wonder-blocks-core";
44
+ *
45
+ * <IDProvider scope="field">
46
+ * {(uniqueId) => (
47
+ * Unique ID: {uniqueId}
48
+ * )}
49
+ * </IDProvider>
50
+ * ```
51
+ *
52
+ */
53
+ export default class IDProvider extends React.Component<Props> {
54
+ static defaultId: string;
55
+ renderChildren(ids?: IIdentifierFactory): React.ReactNode;
56
+ render(): React.ReactElement;
57
+ }
58
+ export {};
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Flowtype definitions for id-provider
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
7
+
8
+ import * as React from "react";
9
+ import type { IIdentifierFactory } from "../util/types";
10
+ declare type Props = {
11
+ /**
12
+ * Use the children-as-function pattern to pass a uniqueId string for
13
+ * use anywhere within children. This provides a way of adding a unique identifier
14
+ * to a given component for a11y purposes.
15
+ */
16
+ children: (uniqueId: string) => React.Element<>,
17
+
18
+ /**
19
+ * Scope for the unique identifier
20
+ */
21
+ scope: string,
22
+
23
+ /**
24
+ * An optional id parameter for the title. If one is
25
+ * not provided, a unique id will be generated.
26
+ */
27
+ id?: string,
28
+
29
+ /**
30
+ * Test ID used for e2e testing.
31
+ */
32
+ testId?: string,
33
+ ...
34
+ };
35
+ /**
36
+ * This is a wrapper that returns an identifier. If the `id` prop is set, the
37
+ * component will return the same id to be consumed by its children. Otherwise,
38
+ * a unique id will be provided. This is beneficial for accessibility purposes,
39
+ * among other things.
40
+ *
41
+ * The main difference with `UniqueIDProvider` is that `IDProvider` has a single
42
+ * responsibility, to return an identifier that can by used by the children that
43
+ * are rendered internally.
44
+ *
45
+ * This way, the wrapped component will receive this custom ID and will use it
46
+ * to connect different elements.
47
+ *
48
+ * e.g. It uses the same generated id to connect a Dialog with its main title,
49
+ * or form label with the associated input element, etc.
50
+ *
51
+ * ## Usage
52
+ *
53
+ * ```jsx
54
+ * import {IDProvider} from "@khanacademy/wonder-blocks-core";
55
+ *
56
+ * <IDProvider scope="field">
57
+ * {(uniqueId) => (
58
+ * Unique ID: {uniqueId}
59
+ * )}
60
+ * </IDProvider>
61
+ * ```
62
+ */
63
+ declare export default class IDProvider mixins React.Component<Props> {
64
+ static defaultId: string;
65
+ renderChildren(ids?: IIdentifierFactory): React.Node;
66
+ render(): React.Element<>;
67
+ }
@@ -1,12 +1,9 @@
1
- // @flow
2
1
  import * as React from "react";
3
-
4
- export enum RenderState {
5
- Root = "root",
6
- Initial = "initial",
7
- Standard = "standard",
8
- }
9
-
2
+ export declare const RenderState: {
3
+ readonly Root: "root";
4
+ readonly Initial: "initial";
5
+ readonly Standard: "standard";
6
+ };
10
7
  /**
11
8
  * This is the context that tracks who is doing what in our SSR component tree.
12
9
  *
@@ -22,5 +19,4 @@ export enum RenderState {
22
19
  * standard:
23
20
  * means that we're all now doing non-SSR rendering
24
21
  */
25
- export const RenderStateContext: React.Context<RenderState> =
26
- React.createContext(RenderState.Root);
22
+ export declare const RenderStateContext: React.Context<typeof RenderState[keyof typeof RenderState]>;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Flowtype definitions for render-state-context
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
7
+
8
+ import * as React from "react";
9
+ declare export var RenderState: {
10
+ +Root: "root",
11
+ +Initial: "initial",
12
+ +Standard: "standard",
13
+ ...
14
+ };
15
+ /**
16
+ * This is the context that tracks who is doing what in our SSR component tree.
17
+ *
18
+ * root:
19
+ * no one has instigated an initial SSR render so the component that sees
20
+ * this "root" state is responsible for controlling initial versus standard
21
+ * rendering semantics
22
+ *
23
+ * initial:
24
+ * this means the SSR render has started, and all SSR components should act
25
+ * as though they are on the server
26
+ *
27
+ * standard:
28
+ * means that we're all now doing non-SSR rendering
29
+ */
30
+ declare export var RenderStateContext: React.Context<
31
+ $ElementType<typeof RenderState, $Keys<typeof RenderState>>
32
+ >;
@@ -0,0 +1,10 @@
1
+ import * as React from "react";
2
+ type Props = {
3
+ children: React.ReactNode;
4
+ /**
5
+ * Whether the component should throw when nested. Defaults to `true`.
6
+ */
7
+ throwIfNested?: boolean;
8
+ };
9
+ declare const RenderStateRoot: React.FC<Props>;
10
+ export { RenderStateRoot };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Flowtype definitions for render-state-root
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
7
+
8
+ import * as React from "react";
9
+ declare type Props = {
10
+ children: React.Node,
11
+
12
+ /**
13
+ * Whether the component should throw when nested. Defaults to `true`.
14
+ */
15
+ throwIfNested?: boolean,
16
+ ...
17
+ };
18
+ declare var RenderStateRoot: React.FC<Props>;
19
+ declare export { RenderStateRoot };
@@ -0,0 +1,25 @@
1
+ import * as React from "react";
2
+ import type { TextViewSharedProps } from "../util/types";
3
+ type Props = TextViewSharedProps & {
4
+ tag: string;
5
+ };
6
+ type DefaultProps = {
7
+ tag: Props["tag"];
8
+ };
9
+ /**
10
+ * Text is a building block for constructing other components. `Text` roughly
11
+ * maps to `span`. You can override which tag is used to render the component
12
+ * (for semantic purposes) by specifying the `tag` prop.
13
+ *
14
+ * These components can take styles (via the `style` prop) in a variety of
15
+ * manners:
16
+ *
17
+ * - An inline style object
18
+ * - An `aphrodite` StyleSheet style
19
+ * - An array combining the above
20
+ */
21
+ export default class Text extends React.Component<Props> {
22
+ static defaultProps: DefaultProps;
23
+ render(): React.ReactElement;
24
+ }
25
+ export {};
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Flowtype definitions for text
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
7
+
8
+ import * as React from "react";
9
+ import type { TextViewSharedProps } from "../util/types";
10
+ declare type Props = {
11
+ ...TextViewSharedProps,
12
+ ...{
13
+ tag: string,
14
+ ...
15
+ },
16
+ };
17
+ declare type DefaultProps = {
18
+ tag: $PropertyType<Props, "tag">,
19
+ ...
20
+ };
21
+ /**
22
+ * Text is a building block for constructing other components. `Text` roughly
23
+ * maps to `span`. You can override which tag is used to render the component
24
+ * (for semantic purposes) by specifying the `tag` prop.
25
+ *
26
+ * These components can take styles (via the `style` prop) in a variety of
27
+ * manners:
28
+ *
29
+ * - An inline style object
30
+ * - An `aphrodite` StyleSheet style
31
+ * - An array combining the above
32
+ */
33
+ declare export default class Text mixins React.Component<Props> {
34
+ static defaultProps: DefaultProps;
35
+ render(): React.Element<>;
36
+ }
@@ -0,0 +1,69 @@
1
+ import * as React from "react";
2
+ import type { IIdentifierFactory } from "../util/types";
3
+ type Props = {
4
+ /**
5
+ * A render prop that takes an instance of IIdentifierFactory and returns
6
+ * the content to be rendered.
7
+ *
8
+ * If mockOnFirstRender is false, this is only called after
9
+ * the initial render has occurred -- it will be blank for the
10
+ * the first render -- and will always be called with the same
11
+ * IIdentifierFactory instance.
12
+ *
13
+ * If mockOnFirstRender is true, this is called once with
14
+ * a mock IIdentifierFactory for the initial render, and then a unique ID
15
+ * factory thereafter.
16
+ *
17
+ * Full type with `IIdentifierFactory` definition inlined is:
18
+ *
19
+ * `{get(id: string): string} => React.Node`
20
+ */
21
+ children: (arg1: IIdentifierFactory) => React.ReactElement;
22
+ /**
23
+ * If mockOnFirstRender is false, children is only called
24
+ * after the initial render has occurred.
25
+ * If mockOnFirstRender is true, children is called once with
26
+ * a mock IIdentifierFactory for the initial render, and then a unique ID
27
+ * factory thereafter.
28
+ */
29
+ mockOnFirstRender: boolean;
30
+ /**
31
+ * If this prop is specified, any identifiers provided will contain the
32
+ * given scope. This can be useful for making easily readable identifiers.
33
+ */
34
+ readonly scope?: string;
35
+ };
36
+ /**
37
+ * The `UniqueIDProvider` component is how Wonder Blocks components obtain
38
+ * unique identifiers. This component ensures that server-side rendering and
39
+ * initial client rendering match while allowing the provision of unique
40
+ * identifiers for the client.
41
+ *
42
+ * In all but the first render, the children are rendered with the same
43
+ * `IIdentifierFactory` instance, ensuring that the same calls will return the
44
+ * same identifiers.
45
+ *
46
+ * The `get` method of the identifier factory ensures that the same identifier
47
+ * is returned for like requests, but also that all identifiers provided are
48
+ * unique. Therefore, `get("test")` will always equal `get("test")`, and
49
+ * `get("test2")` will always equal `get("test2")`, but `get("test")` will
50
+ * never equal `get("test2")`.
51
+ *
52
+ * ## Usage
53
+ *
54
+ * ```jsx
55
+ * import {UniqueIDProvider} from "@khanacademy/wonder-blocks-core";
56
+ *
57
+ * <UniqueIDProvider mockOnFirstRender={false} scope="field">
58
+ * {(ids) => (
59
+ * <>The id returned for "my-identifier": {ids.get("my-identifier")}</>
60
+ * )}
61
+ * </UniqueIDProvider>
62
+ * ```
63
+ */
64
+ export default class UniqueIDProvider extends React.Component<Props> {
65
+ _idFactory: IIdentifierFactory;
66
+ _performRender(firstRender: boolean): React.ReactNode;
67
+ render(): React.ReactElement;
68
+ }
69
+ export {};
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Flowtype definitions for unique-id-provider
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
7
+
8
+ import * as React from "react";
9
+ import type { IIdentifierFactory } from "../util/types";
10
+ declare type Props = {
11
+ /**
12
+ * A render prop that takes an instance of IIdentifierFactory and returns
13
+ * the content to be rendered.
14
+ *
15
+ * If mockOnFirstRender is false, this is only called after
16
+ * the initial render has occurred -- it will be blank for the
17
+ * the first render -- and will always be called with the same
18
+ * IIdentifierFactory instance.
19
+ *
20
+ * If mockOnFirstRender is true, this is called once with
21
+ * a mock IIdentifierFactory for the initial render, and then a unique ID
22
+ * factory thereafter.
23
+ *
24
+ * Full type with `IIdentifierFactory` definition inlined is:
25
+ *
26
+ * `{get(id: string): string} => React.Node`
27
+ */
28
+ children: (arg1: IIdentifierFactory) => React.Element<>,
29
+
30
+ /**
31
+ * If mockOnFirstRender is false, children is only called
32
+ * after the initial render has occurred.
33
+ * If mockOnFirstRender is true, children is called once with
34
+ * a mock IIdentifierFactory for the initial render, and then a unique ID
35
+ * factory thereafter.
36
+ */
37
+ mockOnFirstRender: boolean,
38
+
39
+ /**
40
+ * If this prop is specified, any identifiers provided will contain the
41
+ * given scope. This can be useful for making easily readable identifiers.
42
+ */
43
+ +scope?: string,
44
+ ...
45
+ };
46
+ /**
47
+ * The `UniqueIDProvider` component is how Wonder Blocks components obtain
48
+ * unique identifiers. This component ensures that server-side rendering and
49
+ * initial client rendering match while allowing the provision of unique
50
+ * identifiers for the client.
51
+ *
52
+ * In all but the first render, the children are rendered with the same
53
+ * `IIdentifierFactory` instance, ensuring that the same calls will return the
54
+ * same identifiers.
55
+ *
56
+ * The `get` method of the identifier factory ensures that the same identifier
57
+ * is returned for like requests, but also that all identifiers provided are
58
+ * unique. Therefore, `get("test")` will always equal `get("test")`, and
59
+ * `get("test2")` will always equal `get("test2")`, but `get("test")` will
60
+ * never equal `get("test2")`.
61
+ *
62
+ * ## Usage
63
+ *
64
+ * ```jsx
65
+ * import {UniqueIDProvider} from "@khanacademy/wonder-blocks-core";
66
+ *
67
+ * <UniqueIDProvider mockOnFirstRender={false} scope="field">
68
+ * {(ids) => (
69
+ * <>The id returned for "my-identifier": {ids.get("my-identifier")}</>
70
+ * )}
71
+ * </UniqueIDProvider>
72
+ * ```
73
+ */
74
+ declare export default class UniqueIDProvider mixins React.Component<Props> {
75
+ _idFactory: IIdentifierFactory;
76
+ _performRender(firstRender: boolean): React.Node;
77
+ render(): React.Element<>;
78
+ }
@@ -0,0 +1,43 @@
1
+ import * as React from "react";
2
+ import type { TextViewSharedProps } from "../util/types";
3
+ type ValidViewTags = "div" | "article" | "aside" | "nav" | "section";
4
+ type Props = TextViewSharedProps & {
5
+ /**
6
+ * The HTML tag to render.
7
+ */
8
+ tag: ValidViewTags;
9
+ };
10
+ type DefaultProps = {
11
+ tag: Props["tag"];
12
+ };
13
+ /**
14
+ * View is a building block for constructing other components. `View` roughly
15
+ * maps to `div`. You can override which tag is used to render the component
16
+ * (for semantic purposes) by specifying the `tag` prop.
17
+ *
18
+ * These components can take styles (via the `style` prop) in a variety of
19
+ * manners:
20
+ *
21
+ * - An inline style object
22
+ * - An `aphrodite` StyleSheet style
23
+ * - An array combining the above
24
+ *
25
+ * `View` sets the following defaults:
26
+ *
27
+ * - `display: "flex"`
28
+ * - `flexDirection: "column"`
29
+ * - they each get their own stacking context.
30
+ *
31
+ * ### Usage
32
+ *
33
+ * ```jsx
34
+ * import {View} from "@khanacademy/wonder-blocks-core";
35
+ *
36
+ * <View>This is a View!</View>
37
+ * ```
38
+ */
39
+ export default class View extends React.Component<Props> {
40
+ static defaultProps: DefaultProps;
41
+ render(): React.ReactElement;
42
+ }
43
+ export {};
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Flowtype definitions for view
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
7
+
8
+ import * as React from "react";
9
+ import type { TextViewSharedProps } from "../util/types";
10
+ declare type ValidViewTags = "div" | "article" | "aside" | "nav" | "section";
11
+ declare type Props = {
12
+ ...TextViewSharedProps,
13
+ ...{
14
+ /**
15
+ * The HTML tag to render.
16
+ */
17
+ tag: ValidViewTags,
18
+ ...
19
+ },
20
+ };
21
+ declare type DefaultProps = {
22
+ tag: $PropertyType<Props, "tag">,
23
+ ...
24
+ };
25
+ /**
26
+ * View is a building block for constructing other components. `View` roughly
27
+ * maps to `div`. You can override which tag is used to render the component
28
+ * (for semantic purposes) by specifying the `tag` prop.
29
+ *
30
+ * These components can take styles (via the `style` prop) in a variety of
31
+ * manners:
32
+ *
33
+ * - An inline style object
34
+ * - An `aphrodite` StyleSheet style
35
+ * - An array combining the above
36
+ *
37
+ * `View` sets the following defaults:
38
+ *
39
+ * - `display: "flex"`
40
+ * - `flexDirection: "column"`
41
+ * - they each get their own stacking context.
42
+ *
43
+ * ### Usage
44
+ *
45
+ * ```jsx
46
+ * import {View} from "@khanacademy/wonder-blocks-core";
47
+ *
48
+ * <View>This is a View!</View>
49
+ * ```
50
+ */
51
+ declare export default class View mixins React.Component<Props> {
52
+ static defaultProps: DefaultProps;
53
+ render(): React.Element<>;
54
+ }
@@ -0,0 +1,63 @@
1
+ import * as React from "react";
2
+ import { RenderState } from "./render-state-context";
3
+ /**
4
+ * We use render functions so that we don't do any work unless we need to.
5
+ * This avoids rendering but not mounting potentially complex component trees.
6
+ */
7
+ type Props = {
8
+ /**
9
+ * The content that is client-only. This is what is rendered when
10
+ * not server-side rendering, or (when server-side rendering) after
11
+ * the initial rehydration has finished.
12
+ */
13
+ children: () => React.ReactElement;
14
+ /**
15
+ * What to render during server-side rendering, or null not to
16
+ * render anything.
17
+ *
18
+ * NOTE: Make sure the placeholder will render the same for both
19
+ * client and server -- that is, it does the same thing for both
20
+ * the server-side renderer and the rehydration -- or it defeats
21
+ * the purpose of using the WithSSRPlaceholder component.
22
+ */
23
+ placeholder: () => React.ReactElement | null | undefined;
24
+ };
25
+ type State = {
26
+ mounted: boolean;
27
+ };
28
+ /**
29
+ * Defer or change rendering until the component did mount.
30
+ *
31
+ * The purpose of this component is to disable or modify server-side rendering
32
+ * of certain components. Disabling rendering on the server, by itself, would
33
+ * not be sufficient, since the initial render of the component must match what
34
+ * is rendered on the server. Therefore, this component also disables rendering
35
+ * the first time around on the client.
36
+ *
37
+ * If `WithSSRPlaceholder` components are nested within one another, the root
38
+ * `WithSSRPlaceholder` component will handle the initial render, but nested
39
+ * `WithSSRPlaceholder` components will delegate to the root one, meaning that
40
+ * we don't cascade delayed rendering down the component tree. This will also be
41
+ * the case across portal boundaries.
42
+ *
43
+ * ## Usage
44
+ *
45
+ * ```js
46
+ * import {WithSSRPlaceholder} from "@khanacademy/wonder-blocks-core";
47
+ *
48
+ * <WithSSRPlaceholder placeholder={() => <div>Renders on the server!</div>}>
49
+ * {() => (
50
+ * <div>This is rendered only by the client, for all renders after the rehydration render</div>
51
+ * )}
52
+ * </WithSSRPlaceholder>
53
+ * ```
54
+ */
55
+ export default class WithSSRPlaceholder extends React.Component<Props, State> {
56
+ state: State;
57
+ componentDidMount(): void;
58
+ _isTheRootComponent: boolean;
59
+ _renderAsRootComponent(): React.ReactNode;
60
+ _maybeRender(renderState: typeof RenderState[keyof typeof RenderState]): React.ReactNode;
61
+ render(): React.ReactElement;
62
+ }
63
+ export {};