@khanacademy/wonder-blocks-layout 3.2.2 → 4.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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # @khanacademy/wonder-blocks-layout
2
2
 
3
+ ## 4.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - 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.
8
+
9
+ ## 3.2.3
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [d4df210]
14
+ - @khanacademy/wonder-blocks-tokens@18.2.1
15
+ - @khanacademy/wonder-blocks-styles@0.4.3
16
+
3
17
  ## 3.2.2
4
18
 
5
19
  ### Patch Changes
package/dist/es/index.js CHANGED
@@ -1,16 +1,10 @@
1
1
  import { jsx } from 'react/jsx-runtime';
2
2
  import * as React from 'react';
3
- import { InitialFallback, View } from '@khanacademy/wonder-blocks-core';
4
- import { remToPx, tokenValue, sizing, semanticColor } from '@khanacademy/wonder-blocks-tokens';
5
3
  import { StyleSheet } from 'aphrodite';
4
+ import { View } from '@khanacademy/wonder-blocks-core';
5
+ import { semanticColor, sizing } from '@khanacademy/wonder-blocks-tokens';
6
6
  import { focusStyles } from '@khanacademy/wonder-blocks-styles';
7
7
 
8
- const VALID_MEDIA_SIZES=["small","medium","large"];const SIZE_160_PX=parseInt(remToPx(tokenValue(sizing.size_160)));const SIZE_240_PX=parseInt(remToPx(tokenValue(sizing.size_240)));const SIZE_320_PX=parseInt(remToPx(tokenValue(sizing.size_320)));const SIZE_480_PX=parseInt(remToPx(tokenValue(sizing.size_480)));const mediaDefaultSpecLargeMarginWidth=SIZE_240_PX;const MEDIA_DEFAULT_SPEC={small:{query:"(max-width: 767px)",totalColumns:4,gutterWidth:SIZE_160_PX,marginWidth:SIZE_160_PX},medium:{query:"(min-width: 768px) and (max-width: 1023px)",totalColumns:8,gutterWidth:SIZE_320_PX,marginWidth:SIZE_240_PX},large:{query:"(min-width: 1024px)",totalColumns:12,gutterWidth:SIZE_320_PX,marginWidth:mediaDefaultSpecLargeMarginWidth,maxWidth:1120+mediaDefaultSpecLargeMarginWidth*2}};const MEDIA_INTERNAL_SPEC={large:{query:"(min-width: 1px)",totalColumns:12,gutterWidth:SIZE_320_PX,marginWidth:SIZE_160_PX}};const MEDIA_MODAL_SPEC={small:{query:"(max-width: 767px)",totalColumns:4,gutterWidth:SIZE_160_PX,marginWidth:SIZE_160_PX},large:{query:"(min-width: 768px)",totalColumns:12,gutterWidth:SIZE_320_PX,marginWidth:SIZE_480_PX}};
9
-
10
- const defaultContext={ssrSize:"large",mediaSpec:MEDIA_DEFAULT_SPEC};const MediaLayoutContext=React.createContext(defaultContext);MediaLayoutContext.displayName="MediaLayoutContext";
11
-
12
- const mediaQueryLists={};const DEFAULT_SIZE="large";class MediaLayoutInternal extends React.Component{componentDidMount(){const entries=Object.entries(this.props.mediaSpec);for(const[size,spec]of entries){const mql=mediaQueryLists[spec.query];if(!mql){continue}const listener=e=>{if(e.matches){this.setState({size});}};mql.addListener(listener);this.cleanupThunks.push(()=>mql.removeListener(listener));}}componentWillUnmount(){this.cleanupThunks.forEach(cleaup=>cleaup());}getCurrentSize(spec){if(this.state.size){return this.state.size}else {const entries=Object.entries(this.props.mediaSpec);for(const[size,spec]of entries){const mql=mediaQueryLists[spec.query];if(mql.matches){return size}}}return DEFAULT_SIZE}isUnsupportedEnvironment(){return typeof window==="undefined"||!window.matchMedia}getMockStyleSheet(mediaSize){const{styleSheets}=this.props;const mockStyleSheet={};if(!styleSheets){return mockStyleSheet}for(const styleSize of Object.keys(styleSheets)){const styleSheet=styleSheets[styleSize];if(!styleSheet){continue}for(const name of Object.keys(styleSheet)){if(Object.prototype.hasOwnProperty.call(mockStyleSheet,name)){continue}mockStyleSheet[name]=[styleSheets.all&&styleSheets.all[name],mediaSize==="small"&&[styleSheets.mdOrSmaller&&styleSheets.mdOrSmaller[name],styleSheets.small&&styleSheets.small[name]],mediaSize==="medium"&&[styleSheets.mdOrSmaller&&styleSheets.mdOrSmaller[name],styleSheets.mdOrLarger&&styleSheets.mdOrLarger[name],styleSheets.medium&&styleSheets.medium[name]],mediaSize==="large"&&[styleSheets.mdOrLarger&&styleSheets.mdOrLarger[name],styleSheets.large&&styleSheets.large[name]]];}}return mockStyleSheet}renderContent(initialRender){const{children,mediaSpec,ssrSize,overrideSize}=this.props;const queries=[...Object.values(MEDIA_DEFAULT_SPEC).map(spec=>spec.query),...Object.values(MEDIA_INTERNAL_SPEC).map(spec=>spec.query),...Object.values(MEDIA_MODAL_SPEC).map(spec=>spec.query),...Object.values(mediaSpec).map(spec=>spec.query)];if(!initialRender){for(const query of queries.filter(query=>!mediaQueryLists[query])){mediaQueryLists[query]=window.matchMedia(query);}}const mediaSize=overrideSize||initialRender&&ssrSize||this.getCurrentSize(mediaSpec);const styles=this.getMockStyleSheet(mediaSize);return children({mediaSize,mediaSpec,styles})}render(){return jsx(InitialFallback,{fallback:()=>this.renderContent(true),children:()=>this.renderContent(this.isUnsupportedEnvironment())})}constructor(props){super(props);this.state={size:undefined};this.cleanupThunks=[];}}class MediaLayout extends React.Component{render(){return jsx(MediaLayoutContext.Consumer,{children:({overrideSize,ssrSize,mediaSpec})=>jsx(MediaLayoutInternal,{...this.props,overrideSize:overrideSize,ssrSize:ssrSize,mediaSpec:mediaSpec})})}}
13
-
14
8
  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}
15
9
 
16
10
  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:[styles$1.scrollableView,isOverflowingVertically&&styles$1.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";const FADE_TOP_OPACITY="--wb-scrollable-view-fade-top-opacity";const FADE_BOTTOM_OPACITY="--wb-scrollable-view-fade-bottom-opacity";const fadeColor=semanticColor.core.background.base.default;const fadeSize=sizing.size_480;const fadeOverlay={content:"''",display:"block",position:"sticky",flexShrink:0,blockSize:fadeSize,pointerEvents:"none",zIndex:1};const styles$1=StyleSheet.create({scrollableView:{overflowY:"auto",overflowAnchor:"none",scrollPaddingBlock:fadeSize,...focusStyles.focus},fades:{"::before":{...fadeOverlay,insetBlockStart:0,marginBlockEnd:`calc(-1 * ${fadeSize})`,background:`linear-gradient(to bottom, ${fadeColor}, transparent)`,borderStartStartRadius:"inherit",borderStartEndRadius:"inherit",opacity:`var(${FADE_TOP_OPACITY}, 0)`},"::after":{...fadeOverlay,insetBlockEnd:0,marginBlockStart:`calc(-1 * ${fadeSize})`,background:`linear-gradient(to top, ${fadeColor}, transparent)`,borderEndStartRadius:"inherit",borderEndEndRadius:"inherit",opacity:`var(${FADE_BOTTOM_OPACITY}, 0)`}}});
@@ -19,6 +13,4 @@ class Spring extends React.Component{render(){const{style}=this.props;return jsx
19
13
 
20
14
  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
15
 
22
- const queryMatchesSize=(mediaQuery,mediaSize)=>{switch(mediaQuery){case"all":return true;case"small":return mediaSize==="small";case"mdOrSmaller":return mediaSize==="medium"||mediaSize==="small";case"medium":return mediaSize==="medium";case"mdOrLarger":return mediaSize==="medium"||mediaSize==="large";case"large":return mediaSize==="large";default:throw new Error(`Unsupported mediaSize: ${mediaSize}`)}};
23
-
24
- export { MEDIA_DEFAULT_SPEC, MEDIA_INTERNAL_SPEC, MEDIA_MODAL_SPEC, MediaLayout, MediaLayoutContext, ScrollableView, Spring, Strut, VALID_MEDIA_SIZES, queryMatchesSize };
16
+ export { ScrollableView, Spring, Strut };
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
@@ -4,9 +4,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var jsxRuntime = require('react/jsx-runtime');
6
6
  var React = require('react');
7
+ var aphrodite = require('aphrodite');
7
8
  var wonderBlocksCore = require('@khanacademy/wonder-blocks-core');
8
9
  var wonderBlocksTokens = require('@khanacademy/wonder-blocks-tokens');
9
- var aphrodite = require('aphrodite');
10
10
  var wonderBlocksStyles = require('@khanacademy/wonder-blocks-styles');
11
11
 
12
12
  function _interopNamespace(e) {
@@ -29,12 +29,6 @@ function _interopNamespace(e) {
29
29
 
30
30
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
31
31
 
32
- const VALID_MEDIA_SIZES=["small","medium","large"];const SIZE_160_PX=parseInt(wonderBlocksTokens.remToPx(wonderBlocksTokens.tokenValue(wonderBlocksTokens.sizing.size_160)));const SIZE_240_PX=parseInt(wonderBlocksTokens.remToPx(wonderBlocksTokens.tokenValue(wonderBlocksTokens.sizing.size_240)));const SIZE_320_PX=parseInt(wonderBlocksTokens.remToPx(wonderBlocksTokens.tokenValue(wonderBlocksTokens.sizing.size_320)));const SIZE_480_PX=parseInt(wonderBlocksTokens.remToPx(wonderBlocksTokens.tokenValue(wonderBlocksTokens.sizing.size_480)));const mediaDefaultSpecLargeMarginWidth=SIZE_240_PX;const MEDIA_DEFAULT_SPEC={small:{query:"(max-width: 767px)",totalColumns:4,gutterWidth:SIZE_160_PX,marginWidth:SIZE_160_PX},medium:{query:"(min-width: 768px) and (max-width: 1023px)",totalColumns:8,gutterWidth:SIZE_320_PX,marginWidth:SIZE_240_PX},large:{query:"(min-width: 1024px)",totalColumns:12,gutterWidth:SIZE_320_PX,marginWidth:mediaDefaultSpecLargeMarginWidth,maxWidth:1120+mediaDefaultSpecLargeMarginWidth*2}};const MEDIA_INTERNAL_SPEC={large:{query:"(min-width: 1px)",totalColumns:12,gutterWidth:SIZE_320_PX,marginWidth:SIZE_160_PX}};const MEDIA_MODAL_SPEC={small:{query:"(max-width: 767px)",totalColumns:4,gutterWidth:SIZE_160_PX,marginWidth:SIZE_160_PX},large:{query:"(min-width: 768px)",totalColumns:12,gutterWidth:SIZE_320_PX,marginWidth:SIZE_480_PX}};
33
-
34
- const defaultContext={ssrSize:"large",mediaSpec:MEDIA_DEFAULT_SPEC};const MediaLayoutContext=React__namespace.createContext(defaultContext);MediaLayoutContext.displayName="MediaLayoutContext";
35
-
36
- const mediaQueryLists={};const DEFAULT_SIZE="large";class MediaLayoutInternal extends React__namespace.Component{componentDidMount(){const entries=Object.entries(this.props.mediaSpec);for(const[size,spec]of entries){const mql=mediaQueryLists[spec.query];if(!mql){continue}const listener=e=>{if(e.matches){this.setState({size});}};mql.addListener(listener);this.cleanupThunks.push(()=>mql.removeListener(listener));}}componentWillUnmount(){this.cleanupThunks.forEach(cleaup=>cleaup());}getCurrentSize(spec){if(this.state.size){return this.state.size}else {const entries=Object.entries(this.props.mediaSpec);for(const[size,spec]of entries){const mql=mediaQueryLists[spec.query];if(mql.matches){return size}}}return DEFAULT_SIZE}isUnsupportedEnvironment(){return typeof window==="undefined"||!window.matchMedia}getMockStyleSheet(mediaSize){const{styleSheets}=this.props;const mockStyleSheet={};if(!styleSheets){return mockStyleSheet}for(const styleSize of Object.keys(styleSheets)){const styleSheet=styleSheets[styleSize];if(!styleSheet){continue}for(const name of Object.keys(styleSheet)){if(Object.prototype.hasOwnProperty.call(mockStyleSheet,name)){continue}mockStyleSheet[name]=[styleSheets.all&&styleSheets.all[name],mediaSize==="small"&&[styleSheets.mdOrSmaller&&styleSheets.mdOrSmaller[name],styleSheets.small&&styleSheets.small[name]],mediaSize==="medium"&&[styleSheets.mdOrSmaller&&styleSheets.mdOrSmaller[name],styleSheets.mdOrLarger&&styleSheets.mdOrLarger[name],styleSheets.medium&&styleSheets.medium[name]],mediaSize==="large"&&[styleSheets.mdOrLarger&&styleSheets.mdOrLarger[name],styleSheets.large&&styleSheets.large[name]]];}}return mockStyleSheet}renderContent(initialRender){const{children,mediaSpec,ssrSize,overrideSize}=this.props;const queries=[...Object.values(MEDIA_DEFAULT_SPEC).map(spec=>spec.query),...Object.values(MEDIA_INTERNAL_SPEC).map(spec=>spec.query),...Object.values(MEDIA_MODAL_SPEC).map(spec=>spec.query),...Object.values(mediaSpec).map(spec=>spec.query)];if(!initialRender){for(const query of queries.filter(query=>!mediaQueryLists[query])){mediaQueryLists[query]=window.matchMedia(query);}}const mediaSize=overrideSize||initialRender&&ssrSize||this.getCurrentSize(mediaSpec);const styles=this.getMockStyleSheet(mediaSize);return children({mediaSize,mediaSpec,styles})}render(){return jsxRuntime.jsx(wonderBlocksCore.InitialFallback,{fallback:()=>this.renderContent(true),children:()=>this.renderContent(this.isUnsupportedEnvironment())})}constructor(props){super(props);this.state={size:undefined};this.cleanupThunks=[];}}class MediaLayout extends React__namespace.Component{render(){return jsxRuntime.jsx(MediaLayoutContext.Consumer,{children:({overrideSize,ssrSize,mediaSpec})=>jsxRuntime.jsx(MediaLayoutInternal,{...this.props,overrideSize:overrideSize,ssrSize:ssrSize,mediaSpec:mediaSpec})})}}
37
-
38
32
  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}
39
33
 
40
34
  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:[styles$1.scrollableView,isOverflowingVertically&&styles$1.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";const FADE_TOP_OPACITY="--wb-scrollable-view-fade-top-opacity";const FADE_BOTTOM_OPACITY="--wb-scrollable-view-fade-bottom-opacity";const fadeColor=wonderBlocksTokens.semanticColor.core.background.base.default;const fadeSize=wonderBlocksTokens.sizing.size_480;const fadeOverlay={content:"''",display:"block",position:"sticky",flexShrink:0,blockSize:fadeSize,pointerEvents:"none",zIndex:1};const styles$1=aphrodite.StyleSheet.create({scrollableView:{overflowY:"auto",overflowAnchor:"none",scrollPaddingBlock:fadeSize,...wonderBlocksStyles.focusStyles.focus},fades:{"::before":{...fadeOverlay,insetBlockStart:0,marginBlockEnd:`calc(-1 * ${fadeSize})`,background:`linear-gradient(to bottom, ${fadeColor}, transparent)`,borderStartStartRadius:"inherit",borderStartEndRadius:"inherit",opacity:`var(${FADE_TOP_OPACITY}, 0)`},"::after":{...fadeOverlay,insetBlockEnd:0,marginBlockStart:`calc(-1 * ${fadeSize})`,background:`linear-gradient(to top, ${fadeColor}, transparent)`,borderEndStartRadius:"inherit",borderEndEndRadius:"inherit",opacity:`var(${FADE_BOTTOM_OPACITY}, 0)`}}});
@@ -43,15 +37,6 @@ class Spring extends React__namespace.Component{render(){const{style}=this.props
43
37
 
44
38
  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
39
 
46
- const queryMatchesSize=(mediaQuery,mediaSize)=>{switch(mediaQuery){case"all":return true;case"small":return mediaSize==="small";case"mdOrSmaller":return mediaSize==="medium"||mediaSize==="small";case"medium":return mediaSize==="medium";case"mdOrLarger":return mediaSize==="medium"||mediaSize==="large";case"large":return mediaSize==="large";default:throw new Error(`Unsupported mediaSize: ${mediaSize}`)}};
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
40
  exports.ScrollableView = ScrollableView;
54
41
  exports.Spring = Spring;
55
42
  exports.Strut = Strut;
56
- exports.VALID_MEDIA_SIZES = VALID_MEDIA_SIZES;
57
- exports.queryMatchesSize = queryMatchesSize;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "",
4
4
  "author": "Khan Academy",
5
5
  "license": "MIT",
6
- "version": "3.2.2",
6
+ "version": "4.0.0",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -21,8 +21,8 @@
21
21
  "types": "dist/index.d.ts",
22
22
  "dependencies": {
23
23
  "@khanacademy/wonder-blocks-core": "12.5.0",
24
- "@khanacademy/wonder-blocks-styles": "0.4.2",
25
- "@khanacademy/wonder-blocks-tokens": "18.2.0"
24
+ "@khanacademy/wonder-blocks-styles": "0.4.3",
25
+ "@khanacademy/wonder-blocks-tokens": "18.2.1"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "aphrodite": "^1.2.5",
@@ -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 {};
@@ -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;
@@ -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 {};
@@ -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 {};
@@ -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;