@khanacademy/wonder-blocks-layout 3.2.3 → 5.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.
- package/CHANGELOG.md +63 -0
- package/dist/es/index.css +109 -0
- package/dist/es/index.css.map +1 -0
- package/dist/es/index.js +8 -13
- package/dist/index.css +109 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.ts +0 -8
- package/dist/index.js +8 -20
- package/package.json +19 -5
- package/dist/components/media-layout-context.d.ts +0 -45
- package/dist/components/media-layout.d.ts +0 -65
- package/dist/util/specs.d.ts +0 -5
- package/dist/util/test-util.d.ts +0 -26
- package/dist/util/types.d.ts +0 -20
- package/dist/util/util.d.ts +0 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,68 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-layout
|
|
2
2
|
|
|
3
|
+
## 5.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- f52e4cd: Add an `exports` map (`.` and `./css`) and `"sideEffects": ["**/*.css"]` to the package.json. `./css` is the component stylesheet. It's conditional: `import` resolves to `dist/es/index.css` and `require` to `dist/index.css`, the same copy each JS entry already loads, so importing `./css` too doesn't duplicate the CSS.
|
|
8
|
+
|
|
9
|
+
**Breaking:** the new `exports` map blocks deep imports such as `@khanacademy/wonder-blocks-core/dist/...`. Import from the package root instead. No deep imports of these packages were found in Khan/frontend or Khan/perseus.
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- bcc10a1: Migrate `Spring` and `ScrollableView` from Aphrodite to CSS Modules (WB-2486,
|
|
14
|
+
CSS Modules Phase 5 / Wave I). The public component API is unchanged: same
|
|
15
|
+
props, DOM structure and `style` override.
|
|
16
|
+
|
|
17
|
+
- `Spring`'s `flex-grow: 1` and `ScrollableView`'s scroll, focus and fade
|
|
18
|
+
styles now live in `spring.module.css` and `scrollable-view.module.css`.
|
|
19
|
+
`View` doesn't set any of these properties, so single classes are enough.
|
|
20
|
+
- The fades are still toggled through the
|
|
21
|
+
`--wb-scrollable-view-fade-{top,bottom}-opacity` custom properties set inline
|
|
22
|
+
on the element; their `0` defaults are now declared on the root class.
|
|
23
|
+
- `Strut` already didn't use Aphrodite. (`MediaLayout` was removed separately,
|
|
24
|
+
in WB-2401.)
|
|
25
|
+
- **Behavior change (edge case):** an `outline` or `box-shadow` passed to
|
|
26
|
+
`ScrollableView` through `style` (plain object or Aphrodite `StyleSheet`) now
|
|
27
|
+
also applies while the view has keyboard focus, replacing the focus ring.
|
|
28
|
+
Before, the focus ring won while focused.
|
|
29
|
+
- The package now ships `dist/index.css` (auto side-effect import) and marks
|
|
30
|
+
`**/*.css` as `sideEffects`. `aphrodite` is dropped from
|
|
31
|
+
`peerDependencies` (the package no longer imports it).
|
|
32
|
+
|
|
33
|
+
### Patch Changes
|
|
34
|
+
|
|
35
|
+
- 9652f57: Load each package's CSS after the CSS of the Wonder Blocks packages it depends
|
|
36
|
+
on. The published JS imported its own `index.css` before its dependencies, so
|
|
37
|
+
bundlers emitted, for example, Button's CSS before Typography's. Both sit in
|
|
38
|
+
`@layer shared` with single-class selectors, so the later `BodyText` rule won and
|
|
39
|
+
Button labels lost their own `font-weight`, `line-height` and `font-size`. The CSS
|
|
40
|
+
import now comes after the dependency imports, matching the source order that
|
|
41
|
+
Storybook already uses.
|
|
42
|
+
- aa5a8e1: Drop `aphrodite` from `peerDependencies`. These packages no longer import it
|
|
43
|
+
since their move to CSS Modules. Aphrodite styles passed through `style` props
|
|
44
|
+
still work: `@khanacademy/wonder-blocks-core`, which processes them, keeps
|
|
45
|
+
`aphrodite` as a peer dependency.
|
|
46
|
+
- Updated dependencies [0c6d97d]
|
|
47
|
+
- Updated dependencies [185dbbc]
|
|
48
|
+
- Updated dependencies [0b6c478]
|
|
49
|
+
- Updated dependencies [9652f57]
|
|
50
|
+
- Updated dependencies [f52e4cd]
|
|
51
|
+
- Updated dependencies [b66b7b7]
|
|
52
|
+
- Updated dependencies [dbb8f0f]
|
|
53
|
+
- Updated dependencies [ad52f4b]
|
|
54
|
+
- Updated dependencies [e4f0a12]
|
|
55
|
+
- Updated dependencies [415b002]
|
|
56
|
+
- @khanacademy/wonder-blocks-tokens@18.3.0
|
|
57
|
+
- @khanacademy/wonder-blocks-core@13.0.0
|
|
58
|
+
- @khanacademy/wonder-blocks-styles@1.0.0
|
|
59
|
+
|
|
60
|
+
## 4.0.0
|
|
61
|
+
|
|
62
|
+
### Major Changes
|
|
63
|
+
|
|
64
|
+
- 5d07224: Remove the deprecated `MediaLayout` component and `MediaLayoutContext`, along with their related exports: `MEDIA_DEFAULT_SPEC`, `MEDIA_INTERNAL_SPEC`, `MEDIA_MODAL_SPEC`, `VALID_MEDIA_SIZES`, `queryMatchesSize`, and the `MediaQuery`, `MediaSize`, `MediaSpec`, `MockStyleSheet` and `MediaLayoutContextValue` types. Use CSS media queries instead.
|
|
65
|
+
|
|
3
66
|
## 3.2.3
|
|
4
67
|
|
|
5
68
|
### Patch Changes
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
@layer shared {/**
|
|
2
|
+
* ScrollableView styles
|
|
3
|
+
*
|
|
4
|
+
* `.scrollableView` sits on the `View` itself. None of its properties are set
|
|
5
|
+
* by `View`'s own rule (`.default` in core), so nothing competes for them and
|
|
6
|
+
* single classes are enough, whichever package's CSS loads first. The same
|
|
7
|
+
* holds for the classes consumers pass through `style` today (Popover's
|
|
8
|
+
* `.root` only sets `border-radius`).
|
|
9
|
+
*
|
|
10
|
+
* The consumer's `style` still goes through Aphrodite (unlayered) or inline
|
|
11
|
+
* styles, so it wins over this module as it did before. The build wraps every
|
|
12
|
+
* rule in `@layer shared { … }`.
|
|
13
|
+
*//*
|
|
14
|
+
* Cross-package focus-visible mixin.
|
|
15
|
+
*
|
|
16
|
+
* Authors include the mixin via:
|
|
17
|
+
*
|
|
18
|
+
* @import "@khanacademy/wonder-blocks-styles/focus-styles.css";
|
|
19
|
+
*
|
|
20
|
+
* .my-component:focus-visible {
|
|
21
|
+
* @apply --wb-focus-visible;
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* postcss-import resolves the @import through the workspace and
|
|
25
|
+
* @csstools/postcss-mixins expands the @apply at build time
|
|
26
|
+
* (CSS Mixins Level 1 syntax — note the leading `--` on the name).
|
|
27
|
+
*/.wb-scrollable-view-scrollableView-3bb17cf2 {
|
|
28
|
+
/* Hide both fades by default. The component shows each one by setting
|
|
29
|
+
* its opacity inline (which wins over these defaults); keep the names in
|
|
30
|
+
* sync with the `FADE_*` constants in `scrollable-view.tsx`. */
|
|
31
|
+
--wb-scrollable-view-fade-top-opacity: 0;
|
|
32
|
+
--wb-scrollable-view-fade-bottom-opacity: 0;
|
|
33
|
+
|
|
34
|
+
/* Scroll the content when it doesn't fit in the available space
|
|
35
|
+
* (e.g. on small screens or at high zoom levels). */
|
|
36
|
+
overflow-y: auto;
|
|
37
|
+
|
|
38
|
+
/* Don't let the browser adjust the scroll position when the content
|
|
39
|
+
* changes (e.g. when the fades are rendered). */
|
|
40
|
+
overflow-anchor: none;
|
|
41
|
+
|
|
42
|
+
/* Keep focused elements (and anything scrolled into view) clear of the
|
|
43
|
+
* fades, so they aren't hidden under them. */
|
|
44
|
+
scroll-padding-block: var(--wb-sizing-size_480);
|
|
45
|
+
|
|
46
|
+
&:focus-visible {
|
|
47
|
+
box-shadow: 0 0 0 var(--wb-border-width-medium)
|
|
48
|
+
var(--wb-semanticColor-focus-inner);
|
|
49
|
+
outline: var(--wb-border-width-medium) solid
|
|
50
|
+
var(--wb-semanticColor-focus-outer);
|
|
51
|
+
outline-offset: var(--wb-border-width-medium);
|
|
52
|
+
}
|
|
53
|
+
}/**
|
|
54
|
+
* Fades at the top and bottom edges that hint that there's more content
|
|
55
|
+
* to scroll to. Each fade is only visible (via its opacity custom
|
|
56
|
+
* property) when there's content past that edge.
|
|
57
|
+
*
|
|
58
|
+
* Each fade is an overlay that sticks to the top or bottom edge of the
|
|
59
|
+
* scrollable view. It's drawn with a pseudo-element that doesn't take up
|
|
60
|
+
* space (its negative margin cancels out its size) and doesn't capture
|
|
61
|
+
* clicks. The fades blend the content into the default background color.
|
|
62
|
+
*/.wb-scrollable-view-fades-3bb17cf2::before,
|
|
63
|
+
.wb-scrollable-view-fades-3bb17cf2::after {
|
|
64
|
+
content: "";
|
|
65
|
+
display: block;
|
|
66
|
+
position: sticky;
|
|
67
|
+
flex-shrink: 0;
|
|
68
|
+
block-size: var(--wb-sizing-size_480);
|
|
69
|
+
pointer-events: none;
|
|
70
|
+
|
|
71
|
+
/* Render the fade above the content. */
|
|
72
|
+
z-index: 1;
|
|
73
|
+
}.wb-scrollable-view-fades-3bb17cf2::before {
|
|
74
|
+
inset-block-start: 0;
|
|
75
|
+
margin-block-end: calc(-1 * var(--wb-sizing-size_480));
|
|
76
|
+
background: linear-gradient(to bottom, var(--wb-semanticColor-core-background-base-default), transparent);
|
|
77
|
+
|
|
78
|
+
/* Match the view's rounded corners (if any). */
|
|
79
|
+
border-start-start-radius: inherit;
|
|
80
|
+
border-start-end-radius: inherit;
|
|
81
|
+
opacity: var(--wb-scrollable-view-fade-top-opacity);
|
|
82
|
+
}.wb-scrollable-view-fades-3bb17cf2::after {
|
|
83
|
+
inset-block-end: 0;
|
|
84
|
+
margin-block-start: calc(-1 * var(--wb-sizing-size_480));
|
|
85
|
+
background: linear-gradient(to top, var(--wb-semanticColor-core-background-base-default), transparent);
|
|
86
|
+
|
|
87
|
+
/* Match the view's rounded corners (if any). */
|
|
88
|
+
border-end-start-radius: inherit;
|
|
89
|
+
border-end-end-radius: inherit;
|
|
90
|
+
opacity: var(--wb-scrollable-view-fade-bottom-opacity);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
@layer shared {/**
|
|
95
|
+
* Spring styles
|
|
96
|
+
*
|
|
97
|
+
* `.spring` sits on the `View` itself. `View`'s own rule (`.default` in core)
|
|
98
|
+
* doesn't set `flex-grow`, so nothing competes for it and a single class is
|
|
99
|
+
* enough, whichever package's CSS loads first.
|
|
100
|
+
*
|
|
101
|
+
* The consumer's `style` still goes through Aphrodite (unlayered) or inline
|
|
102
|
+
* styles, so it wins over this module as it did before. The build wraps every
|
|
103
|
+
* rule in `@layer shared { … }`.
|
|
104
|
+
*/.wb-spring-spring-2867d1c9 {
|
|
105
|
+
flex-grow: 1;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/*# sourceMappingURL=index.css.map */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["<no source>","../../src/components/scrollable-view.module.css","../../../wonder-blocks-styles/src/styles/focus-styles.css","../../src/components/spring.module.css"],"names":[],"mappings":"AAAA,eCAA;;;;;;;;;;;;EAYE,CCZF;;;;;;;;;;;;;;EAcE,CDEF;IACI;;mEAE+D;IAC/D,wCAAwC;IACxC,2CAA2C;;IAE3C;wDACoD;IACpD,gBAAgB;;IAEhB;oDACgD;IAChD,qBAAqB;;IAErB;iDAC6C;IAC7C,+CAA+C;;IAE/C;ICnBA;2CACuC;IACvC;2CACuC;IACvC,6CAA6C;IDiB7C;AACJ,CAEA;;;;;;;;;EASE,CACF;;IAEI,WAAW;IACX,cAAc;IACd,gBAAgB;IAChB,cAAc;IACd,qCAAqC;IACrC,oBAAoB;;IAEpB,uCAAuC;IACvC,UAAU;AACd,CAEA;IACI,oBAAoB;IACpB,sDAAsD;IACtD,yGAAyG;;IAEzG,+CAA+C;IAC/C,kCAAkC;IAClC,gCAAgC;IAChC,mDAAmD;AACvD,CAEA;IACI,kBAAkB;IAClB,wDAAwD;IACxD,sGAAsG;;IAEtG,+CAA+C;IAC/C,gCAAgC;IAChC,8BAA8B;IAC9B,sDAAsD;AAC1D;CDnFA;;AAAA,eGAA;;;;;;;;;;EAUE,CAEF;IACI,YAAY;AAChB;CHdA","file":"index.css","sourcesContent":[null,"/**\n * ScrollableView styles\n *\n * `.scrollableView` sits on the `View` itself. None of its properties are set\n * by `View`'s own rule (`.default` in core), so nothing competes for them and\n * single classes are enough, whichever package's CSS loads first. The same\n * holds for the classes consumers pass through `style` today (Popover's\n * `.root` only sets `border-radius`).\n *\n * The consumer's `style` still goes through Aphrodite (unlayered) or inline\n * styles, so it wins over this module as it did before. The build wraps every\n * rule in `@layer shared { … }`.\n */\n\n@import \"@khanacademy/wonder-blocks-styles/focus-styles.css\";\n\n.scrollableView {\n /* Hide both fades by default. The component shows each one by setting\n * its opacity inline (which wins over these defaults); keep the names in\n * sync with the `FADE_*` constants in `scrollable-view.tsx`. */\n --wb-scrollable-view-fade-top-opacity: 0;\n --wb-scrollable-view-fade-bottom-opacity: 0;\n\n /* Scroll the content when it doesn't fit in the available space\n * (e.g. on small screens or at high zoom levels). */\n overflow-y: auto;\n\n /* Don't let the browser adjust the scroll position when the content\n * changes (e.g. when the fades are rendered). */\n overflow-anchor: none;\n\n /* Keep focused elements (and anything scrolled into view) clear of the\n * fades, so they aren't hidden under them. */\n scroll-padding-block: var(--wb-sizing-size_480);\n\n &:focus-visible {\n @apply --wb-focus-visible;\n }\n}\n\n/**\n * Fades at the top and bottom edges that hint that there's more content\n * to scroll to. Each fade is only visible (via its opacity custom\n * property) when there's content past that edge.\n *\n * Each fade is an overlay that sticks to the top or bottom edge of the\n * scrollable view. It's drawn with a pseudo-element that doesn't take up\n * space (its negative margin cancels out its size) and doesn't capture\n * clicks. The fades blend the content into the default background color.\n */\n.fades::before,\n.fades::after {\n content: \"\";\n display: block;\n position: sticky;\n flex-shrink: 0;\n block-size: var(--wb-sizing-size_480);\n pointer-events: none;\n\n /* Render the fade above the content. */\n z-index: 1;\n}\n\n.fades::before {\n inset-block-start: 0;\n margin-block-end: calc(-1 * var(--wb-sizing-size_480));\n background: linear-gradient(to bottom, var(--wb-semanticColor-core-background-base-default), transparent);\n\n /* Match the view's rounded corners (if any). */\n border-start-start-radius: inherit;\n border-start-end-radius: inherit;\n opacity: var(--wb-scrollable-view-fade-top-opacity);\n}\n\n.fades::after {\n inset-block-end: 0;\n margin-block-start: calc(-1 * var(--wb-sizing-size_480));\n background: linear-gradient(to top, var(--wb-semanticColor-core-background-base-default), transparent);\n\n /* Match the view's rounded corners (if any). */\n border-end-start-radius: inherit;\n border-end-end-radius: inherit;\n opacity: var(--wb-scrollable-view-fade-bottom-opacity);\n}\n","/*\n * Cross-package focus-visible mixin.\n *\n * Authors include the mixin via:\n *\n * @import \"@khanacademy/wonder-blocks-styles/focus-styles.css\";\n *\n * .my-component:focus-visible {\n * @apply --wb-focus-visible;\n * }\n *\n * postcss-import resolves the @import through the workspace and\n * @csstools/postcss-mixins expands the @apply at build time\n * (CSS Mixins Level 1 syntax — note the leading `--` on the name).\n */\n@mixin --wb-focus-visible() {\n box-shadow: 0 0 0 var(--wb-border-width-medium)\n var(--wb-semanticColor-focus-inner);\n outline: var(--wb-border-width-medium) solid\n var(--wb-semanticColor-focus-outer);\n outline-offset: var(--wb-border-width-medium);\n}\n","/**\n * Spring styles\n *\n * `.spring` sits on the `View` itself. `View`'s own rule (`.default` in core)\n * doesn't set `flex-grow`, so nothing competes for it and a single class is\n * enough, whichever package's CSS loads first.\n *\n * The consumer's `style` still goes through Aphrodite (unlayered) or inline\n * styles, so it wins over this module as it did before. The build wraps every\n * rule in `@layer shared { … }`.\n */\n\n.spring {\n flex-grow: 1;\n}\n"]}
|
package/dist/es/index.js
CHANGED
|
@@ -1,24 +1,19 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import {
|
|
4
|
-
import { remToPx, tokenValue, sizing, semanticColor } from '@khanacademy/wonder-blocks-tokens';
|
|
5
|
-
import { StyleSheet } from 'aphrodite';
|
|
6
|
-
import { focusStyles } from '@khanacademy/wonder-blocks-styles';
|
|
3
|
+
import { View } from '@khanacademy/wonder-blocks-core';
|
|
7
4
|
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
const defaultContext={ssrSize:"large",mediaSpec:MEDIA_DEFAULT_SPEC};const MediaLayoutContext=React.createContext(defaultContext);MediaLayoutContext.displayName="MediaLayoutContext";
|
|
5
|
+
const initialState={isOverflowingVertically:false,hasContentAbove:false,hasContentBelow:false};function useScrollOverflow(element){const[state,setState]=React.useState(initialState);React.useEffect(()=>{if(!element||!window.ResizeObserver){setState(initialState);return}const update=()=>{const{scrollTop,scrollHeight,clientHeight}=element;const next={isOverflowingVertically:scrollHeight-clientHeight>1,hasContentAbove:scrollTop>0,hasContentBelow:scrollTop+clientHeight<scrollHeight-1};setState(prev=>prev.isOverflowingVertically===next.isOverflowingVertically&&prev.hasContentAbove===next.hasContentAbove&&prev.hasContentBelow===next.hasContentBelow?prev:next);};const resizeObserver=new ResizeObserver(update);resizeObserver.observe(element);Array.from(element.children).forEach(child=>resizeObserver.observe(child));const mutationObserver=new MutationObserver(mutations=>{mutations.forEach(mutation=>mutation.addedNodes.forEach(node=>{if(node instanceof Element){resizeObserver.observe(node);}}));update();});mutationObserver.observe(element,{childList:true});element.addEventListener("scroll",update,{passive:true});update();return ()=>{resizeObserver.disconnect();mutationObserver.disconnect();element.removeEventListener("scroll",update);}},[element]);return state}
|
|
11
6
|
|
|
12
|
-
|
|
7
|
+
var modules_8756c08b={"scrollableView":"wb-scrollable-view-scrollableView-3bb17cf2","fades":"wb-scrollable-view-fades-3bb17cf2"};
|
|
13
8
|
|
|
14
|
-
const
|
|
9
|
+
const ScrollableView=React.forwardRef(function ScrollableView({children,role,style,testId,...ariaProps},forwardedRef){const[element,setElement]=React.useState(null);const{isOverflowingVertically,hasContentAbove,hasContentBelow}=useScrollOverflow(element);const[isFocused,setIsFocused]=React.useState(false);const handleRef=React.useCallback(node=>{setElement(node);if(typeof forwardedRef==="function"){forwardedRef(node);}else if(forwardedRef){forwardedRef.current=node;}},[forwardedRef]);const isFocusable=isOverflowingVertically||isFocused;React.useLayoutEffect(()=>{element?.style.setProperty(FADE_TOP_OPACITY,hasContentAbove?"1":"0");element?.style.setProperty(FADE_BOTTOM_OPACITY,hasContentBelow?"1":"0");},[element,hasContentAbove,hasContentBelow]);return jsx(View,{...ariaProps,role:role??(isFocusable&&(ariaProps["aria-label"]||ariaProps["aria-labelledby"])?"region":undefined),ref:handleRef,testId:testId,style:[modules_8756c08b.scrollableView,isOverflowingVertically&&modules_8756c08b.fades,style],tabIndex:isFocusable?0:undefined,onFocus:event=>{if(event.target===event.currentTarget){setIsFocused(true);}},onBlur:event=>{if(event.target===event.currentTarget){setIsFocused(false);}},children:children})});ScrollableView.displayName="ScrollableView";var ScrollableView$1 = ScrollableView;const FADE_TOP_OPACITY="--wb-scrollable-view-fade-top-opacity";const FADE_BOTTOM_OPACITY="--wb-scrollable-view-fade-bottom-opacity";
|
|
15
10
|
|
|
16
|
-
|
|
11
|
+
var modules_aa6886da={"spring":"wb-spring-spring-2867d1c9"};
|
|
17
12
|
|
|
18
|
-
class Spring extends React.Component{render(){const{style}=this.props;return jsx(View,{"aria-hidden":"true",style:[
|
|
13
|
+
class Spring extends React.Component{render(){const{style}=this.props;return jsx(View,{"aria-hidden":"true",style:[modules_aa6886da.spring,style]})}}
|
|
19
14
|
|
|
20
15
|
class Strut extends React.Component{render(){const{size,style}=this.props;return jsx(View,{"aria-hidden":"true",style:[strutStyle(size),style]})}}const strutStyle=size=>{return {width:size,MsFlexBasis:size,MsFlexPreferredSize:size,WebkitFlexBasis:size,flexBasis:size,flexShrink:0}};
|
|
21
16
|
|
|
22
|
-
|
|
17
|
+
export { ScrollableView$1 as ScrollableView, Spring, Strut };
|
|
23
18
|
|
|
24
|
-
|
|
19
|
+
import "./index.css";
|
package/dist/index.css
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
@layer shared {/**
|
|
2
|
+
* ScrollableView styles
|
|
3
|
+
*
|
|
4
|
+
* `.scrollableView` sits on the `View` itself. None of its properties are set
|
|
5
|
+
* by `View`'s own rule (`.default` in core), so nothing competes for them and
|
|
6
|
+
* single classes are enough, whichever package's CSS loads first. The same
|
|
7
|
+
* holds for the classes consumers pass through `style` today (Popover's
|
|
8
|
+
* `.root` only sets `border-radius`).
|
|
9
|
+
*
|
|
10
|
+
* The consumer's `style` still goes through Aphrodite (unlayered) or inline
|
|
11
|
+
* styles, so it wins over this module as it did before. The build wraps every
|
|
12
|
+
* rule in `@layer shared { … }`.
|
|
13
|
+
*//*
|
|
14
|
+
* Cross-package focus-visible mixin.
|
|
15
|
+
*
|
|
16
|
+
* Authors include the mixin via:
|
|
17
|
+
*
|
|
18
|
+
* @import "@khanacademy/wonder-blocks-styles/focus-styles.css";
|
|
19
|
+
*
|
|
20
|
+
* .my-component:focus-visible {
|
|
21
|
+
* @apply --wb-focus-visible;
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* postcss-import resolves the @import through the workspace and
|
|
25
|
+
* @csstools/postcss-mixins expands the @apply at build time
|
|
26
|
+
* (CSS Mixins Level 1 syntax — note the leading `--` on the name).
|
|
27
|
+
*/.wb-scrollable-view-scrollableView-3bb17cf2 {
|
|
28
|
+
/* Hide both fades by default. The component shows each one by setting
|
|
29
|
+
* its opacity inline (which wins over these defaults); keep the names in
|
|
30
|
+
* sync with the `FADE_*` constants in `scrollable-view.tsx`. */
|
|
31
|
+
--wb-scrollable-view-fade-top-opacity: 0;
|
|
32
|
+
--wb-scrollable-view-fade-bottom-opacity: 0;
|
|
33
|
+
|
|
34
|
+
/* Scroll the content when it doesn't fit in the available space
|
|
35
|
+
* (e.g. on small screens or at high zoom levels). */
|
|
36
|
+
overflow-y: auto;
|
|
37
|
+
|
|
38
|
+
/* Don't let the browser adjust the scroll position when the content
|
|
39
|
+
* changes (e.g. when the fades are rendered). */
|
|
40
|
+
overflow-anchor: none;
|
|
41
|
+
|
|
42
|
+
/* Keep focused elements (and anything scrolled into view) clear of the
|
|
43
|
+
* fades, so they aren't hidden under them. */
|
|
44
|
+
scroll-padding-block: var(--wb-sizing-size_480);
|
|
45
|
+
|
|
46
|
+
&:focus-visible {
|
|
47
|
+
box-shadow: 0 0 0 var(--wb-border-width-medium)
|
|
48
|
+
var(--wb-semanticColor-focus-inner);
|
|
49
|
+
outline: var(--wb-border-width-medium) solid
|
|
50
|
+
var(--wb-semanticColor-focus-outer);
|
|
51
|
+
outline-offset: var(--wb-border-width-medium);
|
|
52
|
+
}
|
|
53
|
+
}/**
|
|
54
|
+
* Fades at the top and bottom edges that hint that there's more content
|
|
55
|
+
* to scroll to. Each fade is only visible (via its opacity custom
|
|
56
|
+
* property) when there's content past that edge.
|
|
57
|
+
*
|
|
58
|
+
* Each fade is an overlay that sticks to the top or bottom edge of the
|
|
59
|
+
* scrollable view. It's drawn with a pseudo-element that doesn't take up
|
|
60
|
+
* space (its negative margin cancels out its size) and doesn't capture
|
|
61
|
+
* clicks. The fades blend the content into the default background color.
|
|
62
|
+
*/.wb-scrollable-view-fades-3bb17cf2::before,
|
|
63
|
+
.wb-scrollable-view-fades-3bb17cf2::after {
|
|
64
|
+
content: "";
|
|
65
|
+
display: block;
|
|
66
|
+
position: sticky;
|
|
67
|
+
flex-shrink: 0;
|
|
68
|
+
block-size: var(--wb-sizing-size_480);
|
|
69
|
+
pointer-events: none;
|
|
70
|
+
|
|
71
|
+
/* Render the fade above the content. */
|
|
72
|
+
z-index: 1;
|
|
73
|
+
}.wb-scrollable-view-fades-3bb17cf2::before {
|
|
74
|
+
inset-block-start: 0;
|
|
75
|
+
margin-block-end: calc(-1 * var(--wb-sizing-size_480));
|
|
76
|
+
background: linear-gradient(to bottom, var(--wb-semanticColor-core-background-base-default), transparent);
|
|
77
|
+
|
|
78
|
+
/* Match the view's rounded corners (if any). */
|
|
79
|
+
border-start-start-radius: inherit;
|
|
80
|
+
border-start-end-radius: inherit;
|
|
81
|
+
opacity: var(--wb-scrollable-view-fade-top-opacity);
|
|
82
|
+
}.wb-scrollable-view-fades-3bb17cf2::after {
|
|
83
|
+
inset-block-end: 0;
|
|
84
|
+
margin-block-start: calc(-1 * var(--wb-sizing-size_480));
|
|
85
|
+
background: linear-gradient(to top, var(--wb-semanticColor-core-background-base-default), transparent);
|
|
86
|
+
|
|
87
|
+
/* Match the view's rounded corners (if any). */
|
|
88
|
+
border-end-start-radius: inherit;
|
|
89
|
+
border-end-end-radius: inherit;
|
|
90
|
+
opacity: var(--wb-scrollable-view-fade-bottom-opacity);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
@layer shared {/**
|
|
95
|
+
* Spring styles
|
|
96
|
+
*
|
|
97
|
+
* `.spring` sits on the `View` itself. `View`'s own rule (`.default` in core)
|
|
98
|
+
* doesn't set `flex-grow`, so nothing competes for it and a single class is
|
|
99
|
+
* enough, whichever package's CSS loads first.
|
|
100
|
+
*
|
|
101
|
+
* The consumer's `style` still goes through Aphrodite (unlayered) or inline
|
|
102
|
+
* styles, so it wins over this module as it did before. The build wraps every
|
|
103
|
+
* rule in `@layer shared { … }`.
|
|
104
|
+
*/.wb-spring-spring-2867d1c9 {
|
|
105
|
+
flex-grow: 1;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/*# sourceMappingURL=index.css.map */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["<no source>","../src/components/scrollable-view.module.css","../../wonder-blocks-styles/src/styles/focus-styles.css","../src/components/spring.module.css"],"names":[],"mappings":"AAAA,eCAA;;;;;;;;;;;;EAYE,CCZF;;;;;;;;;;;;;;EAcE,CDEF;IACI;;mEAE+D;IAC/D,wCAAwC;IACxC,2CAA2C;;IAE3C;wDACoD;IACpD,gBAAgB;;IAEhB;oDACgD;IAChD,qBAAqB;;IAErB;iDAC6C;IAC7C,+CAA+C;;IAE/C;ICnBA;2CACuC;IACvC;2CACuC;IACvC,6CAA6C;IDiB7C;AACJ,CAEA;;;;;;;;;EASE,CACF;;IAEI,WAAW;IACX,cAAc;IACd,gBAAgB;IAChB,cAAc;IACd,qCAAqC;IACrC,oBAAoB;;IAEpB,uCAAuC;IACvC,UAAU;AACd,CAEA;IACI,oBAAoB;IACpB,sDAAsD;IACtD,yGAAyG;;IAEzG,+CAA+C;IAC/C,kCAAkC;IAClC,gCAAgC;IAChC,mDAAmD;AACvD,CAEA;IACI,kBAAkB;IAClB,wDAAwD;IACxD,sGAAsG;;IAEtG,+CAA+C;IAC/C,gCAAgC;IAChC,8BAA8B;IAC9B,sDAAsD;AAC1D;CDnFA;;AAAA,eGAA;;;;;;;;;;EAUE,CAEF;IACI,YAAY;AAChB;CHdA","file":"index.css","sourcesContent":[null,"/**\n * ScrollableView styles\n *\n * `.scrollableView` sits on the `View` itself. None of its properties are set\n * by `View`'s own rule (`.default` in core), so nothing competes for them and\n * single classes are enough, whichever package's CSS loads first. The same\n * holds for the classes consumers pass through `style` today (Popover's\n * `.root` only sets `border-radius`).\n *\n * The consumer's `style` still goes through Aphrodite (unlayered) or inline\n * styles, so it wins over this module as it did before. The build wraps every\n * rule in `@layer shared { … }`.\n */\n\n@import \"@khanacademy/wonder-blocks-styles/focus-styles.css\";\n\n.scrollableView {\n /* Hide both fades by default. The component shows each one by setting\n * its opacity inline (which wins over these defaults); keep the names in\n * sync with the `FADE_*` constants in `scrollable-view.tsx`. */\n --wb-scrollable-view-fade-top-opacity: 0;\n --wb-scrollable-view-fade-bottom-opacity: 0;\n\n /* Scroll the content when it doesn't fit in the available space\n * (e.g. on small screens or at high zoom levels). */\n overflow-y: auto;\n\n /* Don't let the browser adjust the scroll position when the content\n * changes (e.g. when the fades are rendered). */\n overflow-anchor: none;\n\n /* Keep focused elements (and anything scrolled into view) clear of the\n * fades, so they aren't hidden under them. */\n scroll-padding-block: var(--wb-sizing-size_480);\n\n &:focus-visible {\n @apply --wb-focus-visible;\n }\n}\n\n/**\n * Fades at the top and bottom edges that hint that there's more content\n * to scroll to. Each fade is only visible (via its opacity custom\n * property) when there's content past that edge.\n *\n * Each fade is an overlay that sticks to the top or bottom edge of the\n * scrollable view. It's drawn with a pseudo-element that doesn't take up\n * space (its negative margin cancels out its size) and doesn't capture\n * clicks. The fades blend the content into the default background color.\n */\n.fades::before,\n.fades::after {\n content: \"\";\n display: block;\n position: sticky;\n flex-shrink: 0;\n block-size: var(--wb-sizing-size_480);\n pointer-events: none;\n\n /* Render the fade above the content. */\n z-index: 1;\n}\n\n.fades::before {\n inset-block-start: 0;\n margin-block-end: calc(-1 * var(--wb-sizing-size_480));\n background: linear-gradient(to bottom, var(--wb-semanticColor-core-background-base-default), transparent);\n\n /* Match the view's rounded corners (if any). */\n border-start-start-radius: inherit;\n border-start-end-radius: inherit;\n opacity: var(--wb-scrollable-view-fade-top-opacity);\n}\n\n.fades::after {\n inset-block-end: 0;\n margin-block-start: calc(-1 * var(--wb-sizing-size_480));\n background: linear-gradient(to top, var(--wb-semanticColor-core-background-base-default), transparent);\n\n /* Match the view's rounded corners (if any). */\n border-end-start-radius: inherit;\n border-end-end-radius: inherit;\n opacity: var(--wb-scrollable-view-fade-bottom-opacity);\n}\n","/*\n * Cross-package focus-visible mixin.\n *\n * Authors include the mixin via:\n *\n * @import \"@khanacademy/wonder-blocks-styles/focus-styles.css\";\n *\n * .my-component:focus-visible {\n * @apply --wb-focus-visible;\n * }\n *\n * postcss-import resolves the @import through the workspace and\n * @csstools/postcss-mixins expands the @apply at build time\n * (CSS Mixins Level 1 syntax — note the leading `--` on the name).\n */\n@mixin --wb-focus-visible() {\n box-shadow: 0 0 0 var(--wb-border-width-medium)\n var(--wb-semanticColor-focus-inner);\n outline: var(--wb-border-width-medium) solid\n var(--wb-semanticColor-focus-outer);\n outline-offset: var(--wb-border-width-medium);\n}\n","/**\n * Spring styles\n *\n * `.spring` sits on the `View` itself. `View`'s own rule (`.default` in core)\n * doesn't set `flex-grow`, so nothing competes for it and a single class is\n * enough, whichever package's CSS loads first.\n *\n * The consumer's `style` still goes through Aphrodite (unlayered) or inline\n * styles, so it wins over this module as it did before. The build wraps every\n * rule in `@layer shared { … }`.\n */\n\n.spring {\n flex-grow: 1;\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
import type { MediaQuery, MediaSize, MediaSpec } from "./util/types";
|
|
2
|
-
import type { Context } from "./components/media-layout-context";
|
|
3
|
-
import type { MockStyleSheet } from "./components/media-layout";
|
|
4
|
-
export { default as MediaLayout } from "./components/media-layout";
|
|
5
|
-
export { default as MediaLayoutContext } from "./components/media-layout-context";
|
|
6
1
|
export { default as ScrollableView } from "./components/scrollable-view";
|
|
7
2
|
export { default as Spring } from "./components/spring";
|
|
8
3
|
export { default as Strut } from "./components/strut";
|
|
9
|
-
export * from "./util/specs";
|
|
10
|
-
export { queryMatchesSize } from "./util/util";
|
|
11
|
-
export type { MediaQuery, MediaSize, MediaSpec, MockStyleSheet, Context as MediaLayoutContextValue, };
|
package/dist/index.js
CHANGED
|
@@ -5,9 +5,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
var React = require('react');
|
|
7
7
|
var wonderBlocksCore = require('@khanacademy/wonder-blocks-core');
|
|
8
|
-
var wonderBlocksTokens = require('@khanacademy/wonder-blocks-tokens');
|
|
9
|
-
var aphrodite = require('aphrodite');
|
|
10
|
-
var wonderBlocksStyles = require('@khanacademy/wonder-blocks-styles');
|
|
11
8
|
|
|
12
9
|
function _interopNamespace(e) {
|
|
13
10
|
if (e && e.__esModule) return e;
|
|
@@ -29,29 +26,20 @@ function _interopNamespace(e) {
|
|
|
29
26
|
|
|
30
27
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
31
28
|
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
const defaultContext={ssrSize:"large",mediaSpec:MEDIA_DEFAULT_SPEC};const MediaLayoutContext=React__namespace.createContext(defaultContext);MediaLayoutContext.displayName="MediaLayoutContext";
|
|
29
|
+
const initialState={isOverflowingVertically:false,hasContentAbove:false,hasContentBelow:false};function useScrollOverflow(element){const[state,setState]=React__namespace.useState(initialState);React__namespace.useEffect(()=>{if(!element||!window.ResizeObserver){setState(initialState);return}const update=()=>{const{scrollTop,scrollHeight,clientHeight}=element;const next={isOverflowingVertically:scrollHeight-clientHeight>1,hasContentAbove:scrollTop>0,hasContentBelow:scrollTop+clientHeight<scrollHeight-1};setState(prev=>prev.isOverflowingVertically===next.isOverflowingVertically&&prev.hasContentAbove===next.hasContentAbove&&prev.hasContentBelow===next.hasContentBelow?prev:next);};const resizeObserver=new ResizeObserver(update);resizeObserver.observe(element);Array.from(element.children).forEach(child=>resizeObserver.observe(child));const mutationObserver=new MutationObserver(mutations=>{mutations.forEach(mutation=>mutation.addedNodes.forEach(node=>{if(node instanceof Element){resizeObserver.observe(node);}}));update();});mutationObserver.observe(element,{childList:true});element.addEventListener("scroll",update,{passive:true});update();return ()=>{resizeObserver.disconnect();mutationObserver.disconnect();element.removeEventListener("scroll",update);}},[element]);return state}
|
|
35
30
|
|
|
36
|
-
|
|
31
|
+
var modules_8756c08b={"scrollableView":"wb-scrollable-view-scrollableView-3bb17cf2","fades":"wb-scrollable-view-fades-3bb17cf2"};
|
|
37
32
|
|
|
38
|
-
const
|
|
33
|
+
const ScrollableView=React__namespace.forwardRef(function ScrollableView({children,role,style,testId,...ariaProps},forwardedRef){const[element,setElement]=React__namespace.useState(null);const{isOverflowingVertically,hasContentAbove,hasContentBelow}=useScrollOverflow(element);const[isFocused,setIsFocused]=React__namespace.useState(false);const handleRef=React__namespace.useCallback(node=>{setElement(node);if(typeof forwardedRef==="function"){forwardedRef(node);}else if(forwardedRef){forwardedRef.current=node;}},[forwardedRef]);const isFocusable=isOverflowingVertically||isFocused;React__namespace.useLayoutEffect(()=>{element?.style.setProperty(FADE_TOP_OPACITY,hasContentAbove?"1":"0");element?.style.setProperty(FADE_BOTTOM_OPACITY,hasContentBelow?"1":"0");},[element,hasContentAbove,hasContentBelow]);return jsxRuntime.jsx(wonderBlocksCore.View,{...ariaProps,role:role??(isFocusable&&(ariaProps["aria-label"]||ariaProps["aria-labelledby"])?"region":undefined),ref:handleRef,testId:testId,style:[modules_8756c08b.scrollableView,isOverflowingVertically&&modules_8756c08b.fades,style],tabIndex:isFocusable?0:undefined,onFocus:event=>{if(event.target===event.currentTarget){setIsFocused(true);}},onBlur:event=>{if(event.target===event.currentTarget){setIsFocused(false);}},children:children})});ScrollableView.displayName="ScrollableView";var ScrollableView$1 = ScrollableView;const FADE_TOP_OPACITY="--wb-scrollable-view-fade-top-opacity";const FADE_BOTTOM_OPACITY="--wb-scrollable-view-fade-bottom-opacity";
|
|
39
34
|
|
|
40
|
-
|
|
35
|
+
var modules_aa6886da={"spring":"wb-spring-spring-2867d1c9"};
|
|
41
36
|
|
|
42
|
-
class Spring extends React__namespace.Component{render(){const{style}=this.props;return jsxRuntime.jsx(wonderBlocksCore.View,{"aria-hidden":"true",style:[
|
|
37
|
+
class Spring extends React__namespace.Component{render(){const{style}=this.props;return jsxRuntime.jsx(wonderBlocksCore.View,{"aria-hidden":"true",style:[modules_aa6886da.spring,style]})}}
|
|
43
38
|
|
|
44
39
|
class Strut extends React__namespace.Component{render(){const{size,style}=this.props;return jsxRuntime.jsx(wonderBlocksCore.View,{"aria-hidden":"true",style:[strutStyle(size),style]})}}const strutStyle=size=>{return {width:size,MsFlexBasis:size,MsFlexPreferredSize:size,WebkitFlexBasis:size,flexBasis:size,flexShrink:0}};
|
|
45
40
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
exports.MEDIA_DEFAULT_SPEC = MEDIA_DEFAULT_SPEC;
|
|
49
|
-
exports.MEDIA_INTERNAL_SPEC = MEDIA_INTERNAL_SPEC;
|
|
50
|
-
exports.MEDIA_MODAL_SPEC = MEDIA_MODAL_SPEC;
|
|
51
|
-
exports.MediaLayout = MediaLayout;
|
|
52
|
-
exports.MediaLayoutContext = MediaLayoutContext;
|
|
53
|
-
exports.ScrollableView = ScrollableView;
|
|
41
|
+
exports.ScrollableView = ScrollableView$1;
|
|
54
42
|
exports.Spring = Spring;
|
|
55
43
|
exports.Strut = Strut;
|
|
56
|
-
|
|
57
|
-
|
|
44
|
+
|
|
45
|
+
require("./index.css");
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "",
|
|
4
4
|
"author": "Khan Academy",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "
|
|
6
|
+
"version": "5.0.0",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
@@ -19,13 +19,27 @@
|
|
|
19
19
|
"main": "dist/index.js",
|
|
20
20
|
"module": "dist/es/index.js",
|
|
21
21
|
"types": "dist/index.d.ts",
|
|
22
|
+
"sideEffects": [
|
|
23
|
+
"**/*.css"
|
|
24
|
+
],
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/es/index.js",
|
|
29
|
+
"require": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./css": {
|
|
32
|
+
"import": "./dist/es/index.css",
|
|
33
|
+
"require": "./dist/index.css",
|
|
34
|
+
"default": "./dist/index.css"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
22
37
|
"dependencies": {
|
|
23
|
-
"@khanacademy/wonder-blocks-styles": "0.
|
|
24
|
-
"@khanacademy/wonder-blocks-core": "
|
|
25
|
-
"@khanacademy/wonder-blocks-tokens": "18.
|
|
38
|
+
"@khanacademy/wonder-blocks-styles": "1.0.0",
|
|
39
|
+
"@khanacademy/wonder-blocks-core": "13.0.0",
|
|
40
|
+
"@khanacademy/wonder-blocks-tokens": "18.3.0"
|
|
26
41
|
},
|
|
27
42
|
"peerDependencies": {
|
|
28
|
-
"aphrodite": "^1.2.5",
|
|
29
43
|
"react": "18.2.0"
|
|
30
44
|
},
|
|
31
45
|
"devDependencies": {
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import type { MediaSize, MediaSpec } from "../util/types";
|
|
3
|
-
export type Context = {
|
|
4
|
-
/**
|
|
5
|
-
* Force the MediaLayout to be a particular size (ignoring the actual
|
|
6
|
-
* dimensions of the viewport).
|
|
7
|
-
*/
|
|
8
|
-
overrideSize?: MediaSize;
|
|
9
|
-
/**
|
|
10
|
-
* Set the size of the MediaLayout to be rendered when doing SSR
|
|
11
|
-
* (Server-Side Rendering) of the component. Defaults to "large".
|
|
12
|
-
*/
|
|
13
|
-
ssrSize: MediaSize;
|
|
14
|
-
/**
|
|
15
|
-
* If you wish to use a different set of layout sizes you can specify them as
|
|
16
|
-
* part of the `mediaSpec` property. The Core package exports a couple of the
|
|
17
|
-
* most commonly used ones:
|
|
18
|
-
*
|
|
19
|
-
* **Default Layout Spec (`MEDIA_DEFAULT_SPEC`)**
|
|
20
|
-
*
|
|
21
|
-
* | Size | Columns | Gutter | Margin | Breakpoint |
|
|
22
|
-
* | ------ | ------- | ------ | ------ | ---------------------------------------------------------------------------------------------------------------------------------- |
|
|
23
|
-
* | small | 4 | 16px | 16px | `max-width: 767px` |
|
|
24
|
-
* | medium | 8 | 32px | 24px | `min-width: 768px and max-width: 1023px` |
|
|
25
|
-
* | large | 12 | 32px | 24px | `min-width: 1024px` (maximum content width: `1120px`, after which the margins will continue to expand and content remain centered) |
|
|
26
|
-
*
|
|
27
|
-
* Additionally, the following layout size specs are also available:
|
|
28
|
-
*
|
|
29
|
-
* **Internal Tools (`MEDIA_INTERNAL_SPEC`)**
|
|
30
|
-
*
|
|
31
|
-
* | Size | Columns | Gutter | Margin | Breakpoint |
|
|
32
|
-
* | ----- | ------- | ------ | ------ | -------------------------------------------- |
|
|
33
|
-
* | large | 12 | 32px | 16px | `min-width: 1px` (No maximum content width.) |
|
|
34
|
-
*
|
|
35
|
-
* **12-Column Modal (`MEDIA_MODAL_SPEC`)**
|
|
36
|
-
*
|
|
37
|
-
* | Size | Columns | Gutter | Margin | Breakpoint |
|
|
38
|
-
* | ----- | ------- | ------ | ------ | ---------------------------------------------- |
|
|
39
|
-
* | small | 4 | 16px | 16px | `max-width: 767px` |
|
|
40
|
-
* | large | 12 | 32px | 64px | `min-width: 768px` (No maximum content width.) |
|
|
41
|
-
*/
|
|
42
|
-
mediaSpec: MediaSpec;
|
|
43
|
-
};
|
|
44
|
-
declare const MediaLayoutContext: React.Context<Context>;
|
|
45
|
-
export default MediaLayoutContext;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import type { StyleDeclaration } from "aphrodite";
|
|
3
|
-
import type { StyleType } from "@khanacademy/wonder-blocks-core";
|
|
4
|
-
import type { MediaSize, MediaSpec } from "../util/types";
|
|
5
|
-
export type MockStyleSheet = Record<string, StyleType>;
|
|
6
|
-
type Props = {
|
|
7
|
-
/**
|
|
8
|
-
* The contents to display. Alternatively, a function can be specified
|
|
9
|
-
* that takes three arguments and should return some nodes to display.
|
|
10
|
-
*
|
|
11
|
-
* - mediaSize: The current size of the viewport (small/medium/large)
|
|
12
|
-
* - mediaSpec: The current spec being used to manage the selection of
|
|
13
|
-
* the mediaSize.
|
|
14
|
-
* - styles: An Aphrodite stylesheet representing the current
|
|
15
|
-
* stylesheet for this mediaSize (as specified in the
|
|
16
|
-
* styleSheets prop).
|
|
17
|
-
*/
|
|
18
|
-
children: (arg1: {
|
|
19
|
-
mediaSize: MediaSize;
|
|
20
|
-
mediaSpec: MediaSpec;
|
|
21
|
-
styles: MockStyleSheet;
|
|
22
|
-
}) => React.ReactNode;
|
|
23
|
-
/**
|
|
24
|
-
* Aphrodite stylesheets to pass through to the styles prop. The
|
|
25
|
-
* stylesheets to render is based on the media size. "all" is always
|
|
26
|
-
* rendered.
|
|
27
|
-
*/
|
|
28
|
-
styleSheets?: {
|
|
29
|
-
all?: StyleDeclaration;
|
|
30
|
-
mdOrLarger?: StyleDeclaration;
|
|
31
|
-
mdOrSmaller?: StyleDeclaration;
|
|
32
|
-
small?: StyleDeclaration;
|
|
33
|
-
medium?: StyleDeclaration;
|
|
34
|
-
large?: StyleDeclaration;
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* ***NOTE: The MediaLayout component is being deprecated. Do not use this!!***
|
|
39
|
-
*
|
|
40
|
-
* MediaLayout is a container component that accepts a `styleSheets` object,
|
|
41
|
-
* whose keys are media sizes. It listens for changes to the current media
|
|
42
|
-
* size and passes the current `mediaSize`, `mediaSpec`, and `styles` to
|
|
43
|
-
* `children`, which is a render function taking those three values as an
|
|
44
|
-
* object.
|
|
45
|
-
*
|
|
46
|
-
* Valid keys for the `styleSheets` object are (in order of precedence):
|
|
47
|
-
* - `small`, `medium`, `large`
|
|
48
|
-
* - `mdOrSmaller`, `mdOrLarger`
|
|
49
|
-
* - `all`
|
|
50
|
-
*
|
|
51
|
-
* `MediaLayout` will merge style rules from multiple styles that match the
|
|
52
|
-
* current media query, e.g. `"(min-width: 1024px)"`.
|
|
53
|
-
*
|
|
54
|
-
* The `mediaSpec` is an object with one or more of the following keys:
|
|
55
|
-
* `small`, `medium`, or `large`. Each value contains the following data:
|
|
56
|
-
* - `query: string` e.g. "(min-width: 1024px)"
|
|
57
|
-
* - `totalColumns: number`
|
|
58
|
-
* - `gutterWidth: number`
|
|
59
|
-
* - `marginWidth: number`
|
|
60
|
-
* - `maxWidth: number`
|
|
61
|
-
*/
|
|
62
|
-
export default class MediaLayout extends React.Component<Props> {
|
|
63
|
-
render(): React.ReactNode;
|
|
64
|
-
}
|
|
65
|
-
export {};
|
package/dist/util/specs.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { MediaSize, MediaSpec } from "./types";
|
|
2
|
-
export declare const VALID_MEDIA_SIZES: Array<MediaSize>;
|
|
3
|
-
export declare const MEDIA_DEFAULT_SPEC: MediaSpec;
|
|
4
|
-
export declare const MEDIA_INTERNAL_SPEC: MediaSpec;
|
|
5
|
-
export declare const MEDIA_MODAL_SPEC: MediaSpec;
|
package/dist/util/test-util.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { MediaSize } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* Helper function for setting the window size, for use in tests.
|
|
4
|
-
* @param {MediaSize} size
|
|
5
|
-
*/
|
|
6
|
-
export declare function resizeWindow(size: MediaSize): void;
|
|
7
|
-
declare const queries: {
|
|
8
|
-
readonly small: "(max-width: 767px)";
|
|
9
|
-
readonly medium: "(min-width: 768px) and (max-width: 1023px)";
|
|
10
|
-
readonly large: "(min-width: 1024px)";
|
|
11
|
-
};
|
|
12
|
-
export declare function checkQuery(queryString: (typeof queries)[keyof typeof queries], width: number): boolean;
|
|
13
|
-
type Listener = (arg1: {
|
|
14
|
-
matches: boolean;
|
|
15
|
-
}) => void;
|
|
16
|
-
type MatchMedia = {
|
|
17
|
-
matches: boolean;
|
|
18
|
-
addListener: (listener: Listener) => void;
|
|
19
|
-
removeListener: (listener: Listener) => void;
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
*
|
|
23
|
-
* @param {MediaQuery} query
|
|
24
|
-
*/
|
|
25
|
-
export declare function matchMedia(query: (typeof queries)[keyof typeof queries]): MatchMedia;
|
|
26
|
-
export {};
|
package/dist/util/types.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export type MediaSize = "small" | "medium" | "large";
|
|
2
|
-
export type MediaQuery = "all" | "mdOrSmaller" | "mdOrLarger" | MediaSize;
|
|
3
|
-
type Spec = {
|
|
4
|
-
/** The query to use to match the viewport against. */
|
|
5
|
-
query: string;
|
|
6
|
-
/** The total number of columns to use for the layout. */
|
|
7
|
-
totalColumns: number;
|
|
8
|
-
/** The width of the gutter between columns, in pixels. */
|
|
9
|
-
gutterWidth: number;
|
|
10
|
-
/** The width of the margin, wrapping the row, in pixels. */
|
|
11
|
-
marginWidth: number;
|
|
12
|
-
/** A possible maximum width to have on the layout. */
|
|
13
|
-
maxWidth?: number;
|
|
14
|
-
};
|
|
15
|
-
export type MediaSpec = {
|
|
16
|
-
small?: Spec;
|
|
17
|
-
medium?: Spec;
|
|
18
|
-
large?: Spec;
|
|
19
|
-
};
|
|
20
|
-
export {};
|
package/dist/util/util.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { MediaQuery, MediaSize } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* Return where a media size matches a media query.
|
|
4
|
-
*
|
|
5
|
-
* examples:
|
|
6
|
-
* - `queryMatchesSize("all", "small")` returns `true`
|
|
7
|
-
* - `queryMatchesSize("mdOrLarger", "small")` returns `false`
|
|
8
|
-
*
|
|
9
|
-
* @param {MediaQuery} mediaQuery
|
|
10
|
-
* @param {MediaSize} mediaSize
|
|
11
|
-
*/
|
|
12
|
-
export declare const queryMatchesSize: (mediaQuery: MediaQuery, mediaSize: MediaSize) => boolean;
|