-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into layout-components-rc
- Loading branch information
Showing
21 changed files
with
402 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# Removing `dividers` support from layout components | ||
|
||
Following the update to SEEK’s Browser Support Policy, we are now able to leverage [CSS gap] in Braid, and more importantly, our layout components. This will be landing in Braid in the v33 release. | ||
|
||
Previously, to enable gap-like behaviour layout components iterated over their children, wrapping them in container elements and applying padding. The trade off of this technique was an increased number of DOM elements and the introduction of unwanted space if the child element was hidden or returned `null` — requiring developers to hoist logic to the parent component. | ||
|
||
Migrating to CSS gap mitigates all of the above trade offs. | ||
|
||
However, because `Stack` and `Tiles` no longer iterate over their children, implementing the `dividers` feature centrally is no longer feasible. | ||
|
||
While we could have conditionally maintained this behaviour, it would have resulted in inconsistent edge cases when using `dividers`. E.g. if a child component rendered nothing or a hidden element, the `divider` would still be rendered, resulting in an inconsistent layout. | ||
|
||
## Migration guide | ||
|
||
Braid already provides the [`Divider` component], so migrating away from the `dividers` prop is a matter of inserting a `Divider` as required into your layout. | ||
How you migrate will depend on whether the children of your layout component are static or being iterated over. | ||
|
||
### `Stack` | ||
|
||
For `Stack`s with static children you can manually interleave `Divider` components: | ||
|
||
```diff | ||
-<Stack space="..." dividers> | ||
+<Stack space="..."> | ||
<Component>{item}</Component> | ||
+ <Divider /> | ||
<Component>{item}</Component>**** | ||
+ <Divider /> | ||
<Component>{item}</Component> | ||
</Stack> | ||
``` | ||
|
||
For `Stack`s with iterable children you can conditionally render `Divider` components, before each item (except the first): | ||
|
||
```diff | ||
-<Stack space="..." dividers> | ||
+<Stack space="..."> | ||
{items.map((item, index) => ( | ||
- <Component>{item}</Component> | ||
+ <Fragment key={...}> | ||
+ {index > 0 ? <Divider /> : null} | ||
+ <Component>{item}</Component> | ||
+ </Fragment> | ||
))} | ||
</Stack> | ||
``` | ||
|
||
### `Tiles` | ||
|
||
For `Tiles` the `dividers` prop was only applied when rendered as a single column. | ||
|
||
For this you can conditionally render the `Divider` in a `Stack` with the same spacing as specified on the `Tiles` instance, and hide it on breakpoints showing more than one column. | ||
|
||
Here is an example of this with static children: | ||
|
||
```diff | ||
-<Tiles space="..." columns={{mobile: 1, tablet: 2}} dividers> | ||
+<Tiles space="..." columns={{mobile: 1, tablet: 2}}> | ||
<Component>{item}</Component> | ||
+ <Stack space="..."> | ||
+ <Hidden above="mobile"> | ||
+ <Divider /> | ||
+ </Hidden> | ||
<Component>{item}</Component> | ||
+ </Stack> | ||
+ <Stack space="..."> | ||
+ <Hidden above="mobile"> | ||
+ <Divider /> | ||
+ </Hidden> | ||
<Component>{item}</Component> | ||
+ </Stack> | ||
</Tiles> | ||
``` | ||
|
||
Here is an example of this with iterable children: | ||
|
||
```diff | ||
-<Tiles space="..." columns={{mobile: 1, tablet: 2}} dividers> | ||
+<Tiles space="..." columns={{mobile: 1, tablet: 2}}> | ||
{items.map((item, index) => ( | ||
- <Component>{item}</Component> | ||
+ <Stack space="..." key={...}> | ||
+ {index > 0 ? ( | ||
+ <Hidden above="mobile"> | ||
+ <Divider /> | ||
+ </Hidden> | ||
+ ) : null} | ||
<Component>{item}</Component> | ||
+ </Stack> | ||
))} | ||
</Tiles> | ||
``` | ||
|
||
[CSS gap]: https://developer.mozilla.org/en-US/docs/Web/CSS/gap | ||
[`Divider` component]: https://seek-oss.github.io/braid-design-system/components/Divider/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,7 +87,7 @@ | |
"volta": { | ||
"node": "20.17.0" | ||
}, | ||
"packageManager": "pnpm@9.9.0", | ||
"packageManager": "pnpm@9.10.0", | ||
"pnpm": { | ||
"patchedDependencies": { | ||
"[email protected]": "patches/[email protected]", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
packages/braid-design-system/src/lib/components/Autosuggest/reverseMatches.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { type Match, reverseMatches } from './reverseMatches'; | ||
|
||
describe('reverseMatches', () => { | ||
it('should return intervals for non-matching parts of the suggestion', () => { | ||
const suggestion = 'Apples etc'; | ||
const matches: Match[] = [ | ||
[2, 4], | ||
[6, 8], | ||
]; | ||
const expected: Match[] = [ | ||
[0, 2], | ||
[4, 6], | ||
[8, 10], | ||
]; | ||
|
||
expect(reverseMatches(suggestion, matches)).toEqual(expected); | ||
}); | ||
|
||
it('should handle no matches', () => { | ||
const suggestion = 'Apple'; | ||
const matches: Match[] = []; | ||
const expected: Match[] = [[0, 5]]; | ||
|
||
expect(reverseMatches(suggestion, matches)).toEqual(expected); | ||
}); | ||
|
||
it('should handle matches that cover the entire suggestion', () => { | ||
const suggestion = 'Apple'; | ||
const matches: Match[] = [[0, 5]]; | ||
const expected: Match[] = []; | ||
|
||
expect(reverseMatches(suggestion, matches)).toEqual(expected); | ||
}); | ||
|
||
it('should handle matches at the start of the suggestion', () => { | ||
const suggestion = 'Apple'; | ||
const matches: Match[] = [[0, 2]]; | ||
const expected: Match[] = [[2, 5]]; | ||
|
||
expect(reverseMatches(suggestion, matches)).toEqual(expected); | ||
}); | ||
|
||
it('should handle matches at the end of the suggestion', () => { | ||
const suggestion = 'Apple'; | ||
const matches: Match[] = [[3, 5]]; | ||
const expected: Match[] = [[0, 3]]; | ||
|
||
expect(reverseMatches(suggestion, matches)).toEqual(expected); | ||
}); | ||
|
||
it('should handle matches for a single character suggestion', () => { | ||
const suggestion = 'A'; | ||
const matches: Match[] = [[0, 1]]; | ||
const expected: Match[] = []; | ||
|
||
expect(reverseMatches(suggestion, matches)).toEqual(expected); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
packages/braid-design-system/src/lib/components/Autosuggest/reverseMatches.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
In each Match, | ||
- First number: index of the first highlighted character in the match | ||
- Second number: index of the last highlighted character in the match *plus one* | ||
This matches the format expected by the parse function | ||
See https://github.com/moroshko/autosuggest-highlight?tab=readme-ov-file#parsetext-matches | ||
*/ | ||
|
||
export type Match = [number, number]; | ||
|
||
export function reverseMatches(suggestion: string, matches: Match[]): Match[] { | ||
const suggestionLength = suggestion.length; | ||
const reversedMatches: Match[] = []; | ||
|
||
let currentStart = 0; | ||
|
||
for (const [start, end] of matches) { | ||
if (currentStart < start) { | ||
reversedMatches.push([currentStart, start]); | ||
} | ||
|
||
currentStart = end; | ||
} | ||
|
||
if (currentStart < suggestionLength) { | ||
reversedMatches.push([currentStart, suggestionLength]); | ||
} | ||
|
||
return reversedMatches; | ||
} |
35 changes: 0 additions & 35 deletions
35
packages/braid-design-system/src/lib/components/Autosuggest/useScrollIntoView.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.