@codecademy/styleguide 79.0.1-alpha.2b3284.0 → 79.0.1-alpha.897add.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 +0 -4
- package/package.json +2 -3
- package/src/lib/Molecules/Popover/Popover.stories.tsx +4 -127
- package/LICENSE +0 -21
package/CHANGELOG.md
CHANGED
|
@@ -3,10 +3,6 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
### [79.0.1-alpha.2b3284.0](https://github.com/Codecademy/gamut/compare/@codecademy/styleguide@79.0.0...@codecademy/styleguide@79.0.1-alpha.2b3284.0) (2026-01-29)
|
|
7
|
-
|
|
8
|
-
**Note:** Version bump only for package @codecademy/styleguide
|
|
9
|
-
|
|
10
6
|
## [79.0.0](https://github.com/Codecademy/gamut/compare/@codecademy/styleguide@78.5.5...@codecademy/styleguide@79.0.0) (2026-01-29)
|
|
11
7
|
|
|
12
8
|
### ⚠ BREAKING CHANGES
|
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codecademy/styleguide",
|
|
3
3
|
"description": "Styleguide & Component library for codecademy.com",
|
|
4
|
-
"version": "79.0.1-alpha.
|
|
4
|
+
"version": "79.0.1-alpha.897add.0",
|
|
5
5
|
"author": "Codecademy Engineering",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
10
|
-
"repository": "git@github.com:Codecademy/gamut.git"
|
|
11
|
-
"gitHead": "2bd3d11c403cc6a30e8b861e343f08b7c87e100f"
|
|
10
|
+
"repository": "git@github.com:Codecademy/gamut.git"
|
|
12
11
|
}
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from '@codecademy/gamut';
|
|
9
9
|
import * as patterns from '@codecademy/gamut-patterns';
|
|
10
10
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
11
|
-
import {
|
|
11
|
+
import { useRef, useState } from 'react';
|
|
12
12
|
|
|
13
13
|
const meta: Meta<typeof Popover> = {
|
|
14
14
|
component: Popover,
|
|
@@ -27,91 +27,10 @@ type Story = StoryObj<typeof Popover>;
|
|
|
27
27
|
|
|
28
28
|
type PopoverExampleProps = PopoverProps & Pick<FlexBoxProps, 'p'>;
|
|
29
29
|
|
|
30
|
-
const
|
|
31
|
-
const VIEWPORT_PADDING = 16; // Padding from viewport edge
|
|
32
|
-
|
|
33
|
-
const PopoverExample = ({
|
|
34
|
-
p = 16,
|
|
35
|
-
position: preferredPosition = 'below',
|
|
36
|
-
...rest
|
|
37
|
-
}: PopoverExampleProps) => {
|
|
30
|
+
const PopoverExample = ({ p = 16, ...rest }: PopoverExampleProps) => {
|
|
38
31
|
const [open, setOpen] = useState(false);
|
|
39
|
-
const [computedPosition, setComputedPosition] = useState<
|
|
40
|
-
'above' | 'below' | 'center'
|
|
41
|
-
>(preferredPosition === 'center' ? 'center' : preferredPosition);
|
|
42
|
-
const [availableHeight, setAvailableHeight] = useState<number | undefined>(
|
|
43
|
-
undefined
|
|
44
|
-
);
|
|
45
32
|
const activeElRef = useRef<HTMLDivElement>(null);
|
|
46
|
-
const popoverRef = useRef<HTMLDivElement>(null);
|
|
47
|
-
const [popoverHeight, setPopoverHeight] = useState(POPOVER_HEIGHT_ESTIMATE);
|
|
48
|
-
|
|
49
|
-
const calculatePosition = useCallback(() => {
|
|
50
|
-
const target = activeElRef.current;
|
|
51
|
-
if (!target || preferredPosition === 'center') return;
|
|
52
|
-
|
|
53
|
-
const targetRect = target.getBoundingClientRect();
|
|
54
|
-
const viewportHeight = window.innerHeight;
|
|
55
|
-
|
|
56
|
-
const spaceBelow = viewportHeight - targetRect.bottom - VIEWPORT_PADDING;
|
|
57
|
-
const spaceAbove = targetRect.top - VIEWPORT_PADDING;
|
|
58
|
-
|
|
59
|
-
// Use measured height if available, otherwise estimate
|
|
60
|
-
const heightToFit = popoverHeight;
|
|
61
|
-
|
|
62
|
-
let newPosition: 'above' | 'below' =
|
|
63
|
-
preferredPosition === 'above' ? 'above' : 'below';
|
|
64
|
-
|
|
65
|
-
if (preferredPosition === 'below') {
|
|
66
|
-
// Prefer below, but flip to above if not enough space below and more space above
|
|
67
|
-
if (spaceBelow < heightToFit && spaceAbove > spaceBelow) {
|
|
68
|
-
newPosition = 'above';
|
|
69
|
-
} else {
|
|
70
|
-
newPosition = 'below';
|
|
71
|
-
}
|
|
72
|
-
} else if (preferredPosition === 'above') {
|
|
73
|
-
// Prefer above, but flip to below if not enough space above and more space below
|
|
74
|
-
if (spaceAbove < heightToFit && spaceBelow > spaceAbove) {
|
|
75
|
-
newPosition = 'below';
|
|
76
|
-
} else {
|
|
77
|
-
newPosition = 'above';
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
setComputedPosition(newPosition);
|
|
82
|
-
|
|
83
|
-
// Set max height based on the available space in the computed direction
|
|
84
|
-
const maxAvailableHeight = newPosition === 'below' ? spaceBelow : spaceAbove;
|
|
85
|
-
setAvailableHeight(Math.max(maxAvailableHeight, 100)); // Minimum 100px
|
|
86
|
-
}, [preferredPosition, popoverHeight]);
|
|
87
|
-
|
|
88
|
-
// Measure popover height when it opens
|
|
89
|
-
useEffect(() => {
|
|
90
|
-
if (open && popoverRef.current) {
|
|
91
|
-
const { height } = popoverRef.current.getBoundingClientRect();
|
|
92
|
-
if (height > 0) {
|
|
93
|
-
setPopoverHeight(height);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}, [open]);
|
|
97
|
-
|
|
98
|
-
// Recalculate position on open, scroll, or resize
|
|
99
|
-
useEffect(() => {
|
|
100
|
-
if (!open) return;
|
|
101
|
-
|
|
102
|
-
calculatePosition();
|
|
103
|
-
|
|
104
|
-
window.addEventListener('scroll', calculatePosition, true);
|
|
105
|
-
window.addEventListener('resize', calculatePosition);
|
|
106
|
-
|
|
107
|
-
return () => {
|
|
108
|
-
window.removeEventListener('scroll', calculatePosition, true);
|
|
109
|
-
window.removeEventListener('resize', calculatePosition);
|
|
110
|
-
};
|
|
111
|
-
}, [open, calculatePosition]);
|
|
112
|
-
|
|
113
33
|
const toggleOpen = () => setOpen(!open);
|
|
114
|
-
|
|
115
34
|
return (
|
|
116
35
|
<>
|
|
117
36
|
<Box ref={activeElRef} width="fit-content">
|
|
@@ -121,53 +40,11 @@ const PopoverExample = ({
|
|
|
121
40
|
<Popover
|
|
122
41
|
{...(rest as any)}
|
|
123
42
|
isOpen={open}
|
|
124
|
-
popoverContainerRef={popoverRef}
|
|
125
|
-
position={computedPosition}
|
|
126
43
|
targetRef={activeElRef}
|
|
127
44
|
onRequestClose={() => setOpen(false)}
|
|
128
45
|
>
|
|
129
|
-
{
|
|
130
|
-
|
|
131
|
-
This makes the popover contents scrollable when they exceed
|
|
132
|
-
the available viewport space.
|
|
133
|
-
*/}
|
|
134
|
-
<FlexBox
|
|
135
|
-
alignItems="flex-start"
|
|
136
|
-
flexDirection="column"
|
|
137
|
-
p={p}
|
|
138
|
-
maxHeight={availableHeight ? `${availableHeight}px` as any : undefined}
|
|
139
|
-
overflowY="auto"
|
|
140
|
-
>
|
|
141
|
-
<Box mb={8}>
|
|
142
|
-
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do
|
|
143
|
-
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
|
|
144
|
-
enim ad minim veniam, quis nostrud exercitation ullamco laboris
|
|
145
|
-
nisi ut aliquip ex ea commodo consequat.
|
|
146
|
-
</Box>
|
|
147
|
-
<Box mb={8}>
|
|
148
|
-
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do
|
|
149
|
-
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
|
|
150
|
-
enim ad minim veniam, quis nostrud exercitation ullamco laboris
|
|
151
|
-
nisi ut aliquip ex ea commodo consequat.
|
|
152
|
-
</Box>
|
|
153
|
-
<Box mb={8}>
|
|
154
|
-
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do
|
|
155
|
-
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
|
|
156
|
-
enim ad minim veniam, quis nostrud exercitation ullamco laboris
|
|
157
|
-
nisi ut aliquip ex ea commodo consequat.
|
|
158
|
-
</Box>
|
|
159
|
-
<Box mb={8}>
|
|
160
|
-
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do
|
|
161
|
-
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
|
|
162
|
-
enim ad minim veniam, quis nostrud exercitation ullamco laboris
|
|
163
|
-
nisi ut aliquip ex ea commodo consequat.
|
|
164
|
-
</Box>
|
|
165
|
-
<Box mb={8} opacity={0.7}>
|
|
166
|
-
Position: {computedPosition}
|
|
167
|
-
{computedPosition !== preferredPosition && ' (flipped!)'}
|
|
168
|
-
{' | '}
|
|
169
|
-
Max height: {availableHeight ? `${Math.round(availableHeight)}px` : 'auto'}
|
|
170
|
-
</Box>
|
|
46
|
+
<FlexBox alignItems="flex-start" flexDirection="column" p={p}>
|
|
47
|
+
<Box mb={8}>Hooray!</Box>
|
|
171
48
|
<FillButton size="small" onClick={() => setOpen(false)}>
|
|
172
49
|
Close Popover
|
|
173
50
|
</FillButton>
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2022 Codecademy LLC
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|