Skip to content

Commit

Permalink
fix(style): make styles work with shadow DOM
Browse files Browse the repository at this point in the history
  • Loading branch information
yomatters authored and rebeccaeve committed Sep 18, 2024
1 parent df79c21 commit ec7fb14
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 23 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ This component provides a user interface to browse available Resources and their
| `allowedFilters` | A list of filters you want users to see. Ex: `["GPU Compute"]` | **False** |
| `excludedCategories` | A list of filter **categories** that you want hidden from users. Ex: `["Specialized Support", "Specialized Hardware"]` | **False** |
| `excludedFilters` | A list of filters that you want hidden from users. Ex: `["ACCESS Allocated", "ACCESS OnDemand"]` | **False** |
| `excludedResources` | A list of Resources that you want hidden from users. Ex: `["ACCESS Credits"]` | **False** |
| `excludedResources` | A list of Resources that you want hidden from users. Ex: `["ACCESS Credits"]` | **False** |
| `target` | The DOM element where the component will be rendered. | **True** |

Note: Avoid combining `allowedCategories` and `excludedCategories`, or `allowedFilters` and `excludedFilters`. If an invalid combination is found, it will default to what is specified in the `allowed*` options
Expand Down Expand Up @@ -65,8 +65,10 @@ In order for the Bootstrap styles to be applied, the component target element ne

```html
<div class="bootstrap">
<div class="bootstrap-variables bootstrap-fonts">
<div id="resource-catalog-react"></div>
<div class="bootstrap-variables">
<div class="bootstrap-fonts">
<div id="resource-catalog-react"></div>
</div>
</div>
</div>
```
Expand Down
17 changes: 13 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,25 @@
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN"
crossorigin="anonymous"
/>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.min.css"> -->
-->
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.min.css"
/>
</head>
<body>

<div id="resource-catalog-react"></div>

<script type="module">
import { resourceCatalog, shadowTarget } from "http://localhost:3000/xras-ui.js";
import {
resourceCatalog,
shadowTarget,
} from "http://localhost:3000/dist/xras-ui.js";
resourceCatalog({
target: shadowTarget(document.getElementById("resource-catalog-react"), {accessStyles: true}),
target: shadowTarget(
document.getElementById("resource-catalog-react"),
{ accessStyles: true }
),
onRamps: true,
});
</script>
Expand Down
9 changes: 5 additions & 4 deletions src/bootstrap/access.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ $warning: #ef7537;
$accordion-button-icon: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='#1a5b6e'><path d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/></svg>");
$accordion-button-active-icon: $accordion-button-icon;

body {
body,
:root {
--contrast: #232323;
--contrast-2: #3f3f3f;
--contrast-3: #707070;
Expand All @@ -18,14 +19,14 @@ body {
--base-3: #ffffff;
--black: #000000;
--teal-200: #ecf9f8;
--teal-300: #CEE8E9;
--teal-300: #cee8e9;
--teal-400: #48c0b9;
--teal-600: #107180;
--teal-700: #1a5b6e;
--yellow-400: #ffc42d;
--orange-400: #f07537;
// Bootstrap
--bs-font-sans-serif: 'Archivo', sans-serif;
--bs-font-sans-serif: "Archivo", sans-serif;
--bs-link-color: var(--teal-600);
--bs-link-hover-color: var(--orange-400);
}
}
22 changes: 10 additions & 12 deletions src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export function shadowTarget(
) {
const shadow = host.attachShadow({ mode: "open" });
const bsOuter = document.createElement("div");
const bsMiddle = document.createElement("div");
const bsInner = document.createElement("div");
const target = document.createElement("div");
const bsStyle = document.createElement("link");
Expand All @@ -41,15 +42,19 @@ export function shadowTarget(
accessStyle.href = `${baseUrl}/access.css`;

bsInner.appendChild(target);
bsOuter.appendChild(bsInner);
bsMiddle.appendChild(bsInner);
bsOuter.appendChild(bsMiddle);
shadow.appendChild(bsStyle);
shadow.appendChild(uiStyle);
shadow.appendChild(accessStyle);
shadow.appendChild(bsOuter);

bsOuter.classList.add("bootstrap");
if (bootstrapVariables) bsInner.classList.add("bootstrap-variables");
if (bootstrapFonts) bsInner.classList.add("bootstrap-fonts");
if (bootstrapVariables) bsMiddle.classList.add("bootstrap-variables");
if (bootstrapFonts) {
bsInner.classList.add("bootstrap-fonts");
bsInner.setAttribute("data-bs-theme", "light");
}

return target;
}
Expand Down Expand Up @@ -123,22 +128,15 @@ export function publicationsSelect({ target, routes }) {
);
}

export function resourceCatalog({
target,
catalogSources,
onRamps
}) {
export function resourceCatalog({ target, catalogSources, onRamps }) {
const store = configureStore({
reducer: {
resourceCatalog: catalogSlice,
},
});
ReactDOM.createRoot(target).render(
<Provider store={store}>
<ResourceCatalog
catalogSources={catalogSources}
onRamps={onRamps}
/>
<ResourceCatalog catalogSources={catalogSources} onRamps={onRamps} />
</Provider>
);
}

0 comments on commit ec7fb14

Please sign in to comment.