-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2463 from boltdesignsystem/feature/DS-567-remove-…
…button-link DS-567 Rewrite docs and dependency tests to remove use of button
- Loading branch information
Showing
3 changed files
with
30 additions
and
54 deletions.
There are no files selected for viewing
40 changes: 8 additions & 32 deletions
40
packages/core-v3.x/elements/replace-with-children/README.md
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 |
---|---|---|
@@ -1,41 +1,17 @@ | ||
## `<replace-with-children>` | ||
|
||
A "helper" `custom element` in the Bolt Design System to easily remove a Web Component's initial server-side / Twig-rendered HTML when booting up and replace itself with the custom element's children; as the name implies, "Replace With Children". | ||
A "helper" custom element that removes a web component's initial Twig-rendered HTML and replaces itself with the custom element's children; as the name implies, "Replace With Children". | ||
|
||
A great use case of this is with the `<bolt-button>` component which might output some initial HTML similar to this (when serverside-rendered): | ||
For example: | ||
|
||
```html | ||
<bolt-button align="center" color="primary" size="medium"> | ||
<button | ||
class="c-bolt-button c-bolt-button--medium c-bolt-button--primary c-bolt-button--center" | ||
is="shadow-root" | ||
<bolt-test-component foo="bar"> | ||
<replace-with-children class="c-bolt-test-component" | ||
>Twig-rendered text</replace-with-children | ||
> | ||
<replace-with-children class="c-bolt-button__item" | ||
>Button w/ Icon `after` Text</replace-with-children | ||
> | ||
<replace-with-children class="c-bolt-button__icon"> | ||
<bolt-icon name="chevron-right" slot="after"></bolt-icon> | ||
</replace-with-children> | ||
</button> | ||
</bolt-button> | ||
</bolt-test-component> | ||
``` | ||
|
||
The thing is, most of this HTML isn't technically needed to render our Web Component in a clean, semantic way. In fact, most of it isn't _technically_ needed to render out the component: | ||
In the example above, once the web component has rendered, "Twig-rendered text" will remain but `<replace-with-children class="c-bolt-test-component">` will have been removed so that the markup around the original text can be fully controlled by the web component's own renderer. | ||
|
||
```html | ||
<!-- This totally works if we wanted to customize the data or attributes on the semantic `<button>` tag that lives in our custom element --> | ||
<bolt-button align="center" color="primary" size="medium"> | ||
<button is="shadow-root" type="submit" data-uuid="foo"> | ||
Button w/ Icon `after` Text | ||
<bolt-icon name="chevron-right" slot="after"></bolt-icon> | ||
</button> | ||
</bolt-button> | ||
|
||
<!-- But if not, this also works! --> | ||
<bolt-button align="center" color="primary" size="medium"> | ||
Button w/ Icon `after` Text | ||
<bolt-icon name="chevron-right" slot="after"></bolt-icon> | ||
</bolt-button> | ||
``` | ||
|
||
That's where this helper element comes in: acting as a placeholder for styling non-semantic HTML before the JS kicks in. Once it does, throw away the markup that the component doesn't need / use without losing any valuable data or content. | ||
This is mainly used to avoid a content shift when web component rendering replaces the original Twig-rendered content. |
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
12 changes: 6 additions & 6 deletions
12
packages/testing/testing-utils/__tests__/fixtures/card/card.twig
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