@codecademy/styleguide 79.0.1-alpha.2b3284.0 → 79.0.1-alpha.b3f84e.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
@@ -3,7 +3,7 @@
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)
6
+ ### [79.0.1-alpha.b3f84e.0](https://github.com/Codecademy/gamut/compare/@codecademy/styleguide@79.0.0...@codecademy/styleguide@79.0.1-alpha.b3f84e.0) (2026-01-29)
7
7
 
8
8
  **Note:** Version bump only for package @codecademy/styleguide
9
9
 
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@codecademy/styleguide",
3
3
  "description": "Styleguide & Component library for codecademy.com",
4
- "version": "79.0.1-alpha.2b3284.0",
4
+ "version": "79.0.1-alpha.b3f84e.0",
5
5
  "author": "Codecademy Engineering",
6
6
  "license": "MIT",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
10
10
  "repository": "git@github.com:Codecademy/gamut.git",
11
- "gitHead": "2bd3d11c403cc6a30e8b861e343f08b7c87e100f"
11
+ "gitHead": "3d98d84d938c1cc17ecb832b2ac9310c4b0e9188"
12
12
  }
@@ -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 { useCallback, useEffect, useRef, useState } from 'react';
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 POPOVER_HEIGHT_ESTIMATE = 200; // Estimate for flip calculation
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
- Apply maxHeight and overflow to the content wrapper.
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>
@@ -203,6 +80,7 @@ export const Above: Story = {
203
80
  export const Below: Story = {
204
81
  render: (args) => <PopoverExample {...args} beak="center" position="below" />,
205
82
  };
83
+
206
84
  export const CenterLeft: Story = {
207
85
  render: (args) => (
208
86
  <PopoverExample
@@ -236,6 +114,7 @@ export const PopoverCheckerDense: Story = {
236
114
  />
237
115
  ),
238
116
  };
117
+
239
118
  export const PopoverCheckerLoose: Story = {
240
119
  render: (args) => (
241
120
  <PopoverExample
@@ -245,6 +124,7 @@ export const PopoverCheckerLoose: Story = {
245
124
  />
246
125
  ),
247
126
  };
127
+
248
128
  export const PopoverCheckerRegular: Story = {
249
129
  render: (args) => (
250
130
  <PopoverExample
@@ -254,6 +134,7 @@ export const PopoverCheckerRegular: Story = {
254
134
  />
255
135
  ),
256
136
  };
137
+
257
138
  export const PopoverDiagonalADense: Story = {
258
139
  render: (args) => (
259
140
  <PopoverExample
@@ -263,6 +144,7 @@ export const PopoverDiagonalADense: Story = {
263
144
  />
264
145
  ),
265
146
  };
147
+
266
148
  export const PopoverDiagonalALoose: Story = {
267
149
  render: (args) => (
268
150
  <PopoverExample
@@ -272,6 +154,7 @@ export const PopoverDiagonalALoose: Story = {
272
154
  />
273
155
  ),
274
156
  };
157
+
275
158
  export const PopoverDiagonalARegular: Story = {
276
159
  render: (args) => (
277
160
  <PopoverExample