Skip to content

Commit f8c7d17

Browse files
chore(GamutProvider, Popover, PopoverContainer): RTL fixes (#3306)
* chore(GamutProvider): useLogicalProperties hook * feat(gamut-styles): add directionIsRtl utility Move DOM direction resolution (including JSDOM fallback) into @codecademy/gamut-styles utilities and export alongside useLogicalProperties. * fix(InfoTip): update rtl styles (#3319) * bug(InfoTip): update rtl styles Co-authored-by: Kenny Lin <kenny.lin.91@gmail.com> * fix(InfoTip): update rtl styles (#3319) * bug(InfoTip): update rtl styles Co-authored-by: Kenny Lin <kenny.lin.91@gmail.com> * Update packages/styleguide/src/lib/Meta/Logical and physical CSS properties.mdx Co-authored-by: Kenny Lin <kenny.lin.91@gmail.com> * fix(Pagination): Previous and Next Buttons to respect RTL (#3316) * chore: Update SelectDropdown Multi select to use logical properties (#3331) * fix: popover alignment for rtl / useLogicalProperties (#3326) * fix: popover, need to test invertAxis * fix: Address followups for ToolTip bugs RTL (#3330) * fix(Popover): addressing left/right beak (#3332) Co-authored-by: Kenny Lin <kenny.lin.91@gmail.com> * fix(PopoverContainer): working in RTL (#3333) * using physical properties for PopoverContainer positioning, mirroring is manual * fix tests --------- Co-authored-by: Kenny Lin <kenny.lin.91@gmail.com>
1 parent b98d3c7 commit f8c7d17

43 files changed

Lines changed: 1152 additions & 305 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.lintstagedrc.mjs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import micromatch from 'micromatch';
22

3+
/** Shell-safe argument for paths that may contain spaces (lint-staged runs commands via a shell). */
4+
const shellArg = (file) => JSON.stringify(file);
5+
36
export default {
47
// Use custom function to avoid overlaps that could cause race conditions
58
[`*`]: (allChanges) => {
@@ -22,14 +25,16 @@ export default {
2225

2326
if (eslintFiles.length) {
2427
commands.push(
25-
`node_modules/@codecademy/eslint-config/bin/eslint-fix.js ${eslintFiles.join(
26-
' '
27-
)}`
28+
`node_modules/@codecademy/eslint-config/bin/eslint-fix.js ${eslintFiles
29+
.map(shellArg)
30+
.join(' ')}`
2831
);
2932
}
3033

3134
// Run nx format, which will run prettier
32-
commands.push(`nx format:write --files ${allChanges}`);
35+
commands.push(
36+
`nx format:write --files ${allChanges.map(shellArg).join(' ')}`
37+
);
3338

3439
return commands;
3540
},
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
gamut-styles: minor
3+
gamut: minor
4+
---
5+
6+
Updates the Pagination component to have its Previous/Next buttons' icon reflect the correct dir
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
gamut-styles: minor
3+
gamut: minor
4+
---
5+
6+
feat: add useLogicalProperties + useElementDir hooks. fix: RTL left-center + right-center ToolTip and Pagination issues.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"react-test-renderer": "18.3.1",
8686
"start-server-and-test": "^2.1.5",
8787
"storybook": "^10.3.1",
88-
"storybook-addon-deep-controls": "^0.9.5",
88+
"storybook-addon-deep-controls": "^0.10.0",
8989
"style-loader": "^4.0.0",
9090
"svgo": "^1.3.2",
9191
"syncpack": "^10.9.3",

packages/gamut-styles/src/AssetProvider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as React from 'react';
33

44
import { webFonts } from './remoteAssets/fonts';
55
import { coreTheme } from './themes';
6-
import { FontConfig, getFonts } from './utils/fontUtils';
6+
import { FontConfig, getFonts } from './utilities/fontUtils';
77

88
/*
99
* Only preload woff2 fonts, since woff1 are only included as fallbacks.

packages/gamut-styles/src/__tests__/AssetProvider.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { setupRtl } from './testUtils';
88

99
const renderView = setupRtl(AssetProvider, {});
1010

11-
jest.mock('../utils/fontUtils', () => ({
11+
jest.mock('../utilities/fontUtils', () => ({
1212
getFonts: jest.fn(),
1313
}));
1414

@@ -43,7 +43,7 @@ jest.mock('../remoteAssets/fonts', () => ({
4343
},
4444
}));
4545

46-
const mockGetFonts = require('../utils/fontUtils').getFonts;
46+
const mockGetFonts = require('../utilities/fontUtils').getFonts;
4747

4848
describe('AssetProvider', () => {
4949
beforeEach(() => {

packages/gamut-styles/src/__tests__/fontLoading.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { coreTheme, percipioTheme } from '../themes';
66
// Type assertion to satisfy Theme interface in GamutProvider from theme.d.ts - this lib is typed to the CoreTheme interface
77
const typedPercipioTheme = percipioTheme as any;
88

9-
jest.mock('../utils/fontUtils', () => ({
9+
jest.mock('../utilities/fontUtils', () => ({
1010
getFonts: jest.fn(),
1111
}));
1212

@@ -29,7 +29,7 @@ jest.mock('../remoteAssets/fonts', () => ({
2929
},
3030
}));
3131

32-
const mockGetFonts = require('../utils/fontUtils').getFonts;
32+
const mockGetFonts = require('../utilities/fontUtils').getFonts;
3333

3434
const mockDocumentFonts = {
3535
load: jest.fn(),

packages/gamut-styles/src/globals/Typography.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { css, Global } from '@emotion/react';
22
import * as React from 'react';
33

44
import { coreTheme } from '../themes';
5-
import { FontConfig, getFonts } from '../utils/fontUtils';
5+
import { FontConfig, getFonts } from '../utilities/fontUtils';
66

77
/**
88
* Typography component that applies global typography styles to the application.

packages/gamut-styles/src/remoteAssets/fonts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FontConfig } from '../utils/fontUtils';
1+
import { FontConfig } from '../utilities/fontUtils';
22

33
export const FONT_ASSET_PATH = `https://www.codecademy.com/gamut`;
44

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { elementDir } from '../elementDir';
2+
3+
describe('elementDir', () => {
4+
afterEach(() => {
5+
document.documentElement.removeAttribute('dir');
6+
});
7+
8+
it('returns rtl when the element has dir="rtl"', () => {
9+
const el = document.createElement('div');
10+
el.setAttribute('dir', 'rtl');
11+
expect(elementDir(el)).toBe('rtl');
12+
});
13+
14+
it('returns ltr when the element has dir="ltr"', () => {
15+
const el = document.createElement('div');
16+
el.setAttribute('dir', 'ltr');
17+
expect(elementDir(el)).toBe('ltr');
18+
});
19+
20+
it('falls back to documentElement dir when computed style is empty (JSDOM)', () => {
21+
const el = document.createElement('div');
22+
document.documentElement.setAttribute('dir', 'rtl');
23+
expect(elementDir(el)).toBe('rtl');
24+
});
25+
});

0 commit comments

Comments
 (0)