Skip to content

Commit fdc731b

Browse files
authored
Add option to disable automatic media sizing in River.Visual (#59)
1 parent 8e0bcd6 commit fdc731b

17 files changed

+287
-26
lines changed

.changeset/hungry-pillows-watch.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@primer/react-brand': patch
3+
---
4+
5+
Added `fillMedia` prop to River.Visual
6+
7+
Previously, all image and video children were automatically styled to fit the parent elements dimensions.
8+
9+
This isn't ideal in all situations, so the ability to toggle-off this behaviour is now available through an `fillMedia` prop.
10+
11+

.github/workflows/ui_test_primitives_diff.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545

4646
- name: Export diff
4747
run: |
48-
diff -y --width=150 -B -I '*' -I 'Generated' --suppress-common-lines temp-main/lib/css lib/css | tail -n +2 > diff.txt
48+
diff -y --width=150 -B -I '*' -I 'Generated' --suppress-common-lines temp-main/lib/design-tokens/css lib/design-tokens/css | tail -n +2 > diff.txt
4949
npx ts-node ./scripts/ci-check-diff.ts
5050
5151
- name: Read raw diff

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ storybook-static
99
.test/
1010
coverage
1111
playwright-test-results/
12+
playwright-report/
1213

1314
# misc
1415
.DS_Store

docs/content/components/River.mdx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,11 @@ import {River} from '@primer/react-brand'
159159

160160
### River.Visual <Label>Required</Label>
161161

162-
| Name | Type | Default | Description |
163-
| :---------- | :------------- | :-----: | :--------------------------------------------------------------------------------------------------------------- |
164-
| `children` | `ReactElement` | | Bring your own component (BYOC) `img` or `ReactElement` (E.g. Next.js `Image` component) |
165-
| `hasShadow` | `boolean` | `true` | Shadow automatically applied to the `children`. Set be `false` when the child node has a transparent background. |
162+
| Name | Type | Default | Description |
163+
| :---------- | :------------- | :-----: | :-------------------------------------------------------------------------------------------------------------------------------------------- |
164+
| `fillMedia` | `boolean` | true | Automatically styles images and video to fill and fit the width of the parent. Disable this setting if you have bespoke styling requirements. |
165+
| `children` | `ReactElement` | | Bring your own component (BYOC) `img` or `ReactElement` (E.g. Next.js `Image` component) |
166+
| `hasShadow` | `boolean` | `true` | Shadow automatically applied to the `children`. Set be `false` when the child node has a transparent background. |
166167

167168
### River.Content <Label>Required</Label>
168169

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@
4242
"start:docs": "cd docs && npm run develop",
4343
"start:css-types": "tcm -w -p 'src/**/*.css' .",
4444
"test": "jest",
45-
"test:visual": "scripts/playwright/run-visual-tests",
45+
"test:visual": "npx build-storybook && scripts/playwright/run-visual-tests",
4646
"test:visual:generate": "npm run build:docs && ts-node scripts/playwright/playwright.generate-tests.ts",
47-
"test:visual:update-snapshots": "scripts/playwright/update-visual-snapshots"
47+
"test:visual:update-snapshots": "npx build-storybook && scripts/playwright/update-visual-snapshots"
4848
},
4949
"peerDependencies": {
5050
"react": ">=17 <= 18",

scripts/playwright/playwright.generate-tests.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,17 @@
3333
* Manual lookup for tests that need animation or side-effects to complete before tests start
3434
*/
3535
const waitForTimeoutLookup = {
36-
'components-faq-fixtures--all-open': 250, // for the animation
37-
'components-river--video': 1000 // video is slow to load
36+
'components-faq-fixtures--all-open': 250 // for the animation
3837
}
3938

39+
/**
40+
* Manual lookup for tests that we want to skip
41+
* Only add tests here that aren't suitable for visual regression testing
42+
*/
43+
const skipTestLookup = [
44+
'components-river--video' // video makes this too flakey
45+
]
46+
4047
const categorisedStories = Object.keys(stories as Stories).reduce((acc, key) => {
4148
const {id, story: storyName, importPath} = stories[key]
4249

@@ -79,6 +86,9 @@
7986
test.describe('Visual Comparison: ${key}', () => {
8087
8188
${componentStories.reduce((acc, {id, storyName, timeout}) => {
89+
if (skipTestLookup.includes(id)) {
90+
return acc
91+
}
8292
return (acc += `
8393
test('${storyName}', async ({page}) => {
8494
await page.goto('http://localhost:${port}/iframe.html?args=&id=${id}&viewMode=story')
34.6 KB
Loading

src/River/River.module.css

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
margin: var(--brand-River-layout-margin-vertical);
66
}
77

8+
.River--align-center {
9+
text-align: center;
10+
}
11+
812
.River__visual {
913
position: relative;
1014
order: 2;
1115
}
1216

13-
.River--align-center {
14-
text-align: center;
15-
}
16-
17-
.River__visual img,
18-
.River__visual video {
17+
.River__visual--fill-media img,
18+
.River__visual--fill-media video {
1919
width: 100%;
2020
height: 100%;
2121
object-fit: cover;

src/River/River.module.css.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
declare const styles: {
22
readonly "River": string;
3-
readonly "River__visual": string;
43
readonly "River--align-center": string;
4+
readonly "River__visual": string;
5+
readonly "River__visual--fill-media": string;
56
readonly "River__visual--has-shadow": string;
67
readonly "River__heading": string;
78
readonly "River__call-to-action": string;

src/River/River.stories.module.css

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.overflow {
2+
overflow: hidden;
3+
}
4+
5+
.container {
6+
max-width: 1280px;
7+
margin: 0 auto;
8+
}
9+
10+
.river-logos {
11+
display: grid;
12+
width: 120%;
13+
grid-template: auto/repeat(7, 1fr);
14+
grid-gap: 1rem;
15+
gap: 1rem;
16+
align-self: center;
17+
margin-right: -20%;
18+
max-width: 600px;
19+
}
20+
21+
.river-logo {
22+
background: var(--brand-canvas-default);
23+
box-shadow: rgba(140, 149, 159, 0.2) 0px 8px 24px 0px;
24+
height: auto;
25+
}
26+
27+
.river-logo--row-two {
28+
margin-left: 50%;
29+
}
30+
31+
.river-logo--row-three {
32+
margin-left: 100%;
33+
}

0 commit comments

Comments
 (0)