@khanacademy/wonder-blocks-layout 4.0.0 → 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 +57 -0
- package/dist/es/index.css +109 -0
- package/dist/es/index.css.map +1 -0
- package/dist/es/index.js +9 -6
- package/dist/index.css +109 -0
- package/dist/index.css.map +1 -0
- package/dist/index.js +9 -6
- package/package.json +19 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,62 @@
|
|
|
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
|
+
|
|
3
60
|
## 4.0.0
|
|
4
61
|
|
|
5
62
|
### Major 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,16 +1,19 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import { StyleSheet } from 'aphrodite';
|
|
4
3
|
import { View } from '@khanacademy/wonder-blocks-core';
|
|
5
|
-
import { semanticColor, sizing } from '@khanacademy/wonder-blocks-tokens';
|
|
6
|
-
import { focusStyles } from '@khanacademy/wonder-blocks-styles';
|
|
7
4
|
|
|
8
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}
|
|
9
6
|
|
|
10
|
-
|
|
7
|
+
var modules_8756c08b={"scrollableView":"wb-scrollable-view-scrollableView-3bb17cf2","fades":"wb-scrollable-view-fades-3bb17cf2"};
|
|
11
8
|
|
|
12
|
-
|
|
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";
|
|
10
|
+
|
|
11
|
+
var modules_aa6886da={"spring":"wb-spring-spring-2867d1c9"};
|
|
12
|
+
|
|
13
|
+
class Spring extends React.Component{render(){const{style}=this.props;return jsx(View,{"aria-hidden":"true",style:[modules_aa6886da.spring,style]})}}
|
|
13
14
|
|
|
14
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}};
|
|
15
16
|
|
|
16
|
-
export { ScrollableView, Spring, Strut };
|
|
17
|
+
export { ScrollableView$1 as ScrollableView, Spring, Strut };
|
|
18
|
+
|
|
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.js
CHANGED
|
@@ -4,10 +4,7 @@ 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');
|
|
8
7
|
var wonderBlocksCore = require('@khanacademy/wonder-blocks-core');
|
|
9
|
-
var wonderBlocksTokens = require('@khanacademy/wonder-blocks-tokens');
|
|
10
|
-
var wonderBlocksStyles = require('@khanacademy/wonder-blocks-styles');
|
|
11
8
|
|
|
12
9
|
function _interopNamespace(e) {
|
|
13
10
|
if (e && e.__esModule) return e;
|
|
@@ -31,12 +28,18 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
|
31
28
|
|
|
32
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}
|
|
33
30
|
|
|
34
|
-
|
|
31
|
+
var modules_8756c08b={"scrollableView":"wb-scrollable-view-scrollableView-3bb17cf2","fades":"wb-scrollable-view-fades-3bb17cf2"};
|
|
35
32
|
|
|
36
|
-
|
|
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";
|
|
34
|
+
|
|
35
|
+
var modules_aa6886da={"spring":"wb-spring-spring-2867d1c9"};
|
|
36
|
+
|
|
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]})}}
|
|
37
38
|
|
|
38
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}};
|
|
39
40
|
|
|
40
|
-
exports.ScrollableView = ScrollableView;
|
|
41
|
+
exports.ScrollableView = ScrollableView$1;
|
|
41
42
|
exports.Spring = Spring;
|
|
42
43
|
exports.Strut = Strut;
|
|
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-
|
|
24
|
-
"@khanacademy/wonder-blocks-
|
|
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": {
|