Skip to content

Commit 145b028

Browse files
committed
feat(experimental): add experimnetal serivce
1 parent d9658ff commit 145b028

34 files changed

+736
-375
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { Component, AfterViewInit, OnDestroy } from "@angular/core";
2+
import { ExperimentalService } from "../src/experimental.module";
3+
4+
@Component({
5+
selector: "app-experimental-component",
6+
template: ``
7+
})
8+
export class ExperimentalComponenent implements AfterViewInit, OnDestroy {
9+
constructor(protected experimental: ExperimentalService) {
10+
experimental.isExperimental = false;
11+
}
12+
13+
ngAfterViewInit() {
14+
this.toggleExperimental();
15+
document.querySelectorAll(".toggle-btn").forEach(button => {
16+
button.addEventListener("click", this.toggleExperimental);
17+
});
18+
}
19+
20+
ngOnDestroy() {
21+
document.querySelectorAll(".toggle-btn").forEach(button => {
22+
button.removeEventListener("click", this.toggleExperimental);
23+
});
24+
}
25+
26+
// arrow function to capture the correct `this`
27+
toggleExperimental = () => {
28+
if (document.body.classList.contains("experimental")) {
29+
this.experimental.isExperimental = true;
30+
} else {
31+
this.experimental.isExperimental = false;
32+
}
33+
}
34+
}

.storybook/manager-head.html

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,34 @@
3535

3636
<script>
3737
function setExperimental(event) {
38-
var classList = document.getElementsByTagName("iframe")[0].contentDocument.body.classList;
38+
var frame = document.querySelector("#storybook-preview-iframe");
39+
var classList = frame.contentDocument.body.classList;
3940
if(event.target.previousElementSibling) {
4041
classList.add("experimental");
42+
classList.remove("carbon");
4143
event.target.previousElementSibling.classList.remove("experimental-selected");
4244
} else {
4345
classList.remove("experimental");
46+
classList.add("carbon");
4447
event.target.nextElementSibling.classList.remove("experimental-selected");
4548
}
4649
event.target.classList.add("experimental-selected");
4750
};
4851

4952
var experimentalToggleInterval = setInterval(function() {
50-
if(!document.getElementsByTagName("iframe")[0] ||
51-
!document.getElementsByTagName("iframe")[0].contentDocument ||
52-
!document.getElementsByTagName("iframe")[0].contentDocument.getElementById("root")) {
53+
var frame = document.querySelector("#storybook-preview-iframe");
54+
if(!frame ||
55+
!frame.contentDocument ||
56+
!frame.contentDocument.getElementById("root")) {
5357
return;
5458
}
5559

56-
document.getElementsByTagName("iframe")[0].contentDocument.head.appendChild(
60+
frame.contentDocument.head.appendChild(
5761
document.getElementById("iframestyle")
5862
);
5963

6064
clearInterval(experimentalToggleInterval);
61-
document.getElementsByTagName("iframe")[0].contentDocument.body.insertAdjacentHTML(
65+
frame.contentDocument.body.insertAdjacentHTML(
6266
"beforeend",
6367
`<div style="position: fixed; right: 15px; bottom: 15px">
6468
<button
@@ -73,6 +77,9 @@
7377
</button>
7478
</div>
7579
`);
76-
document.getElementsByTagName("iframe")[0].contentWindow.setExperimental = setExperimental;
80+
frame.contentWindow.setExperimental = setExperimental;
81+
82+
var classList = frame.contentDocument.body.classList;
83+
classList.add("carbon");
7784
}, 100);
7885
</script>
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
$feature-flags: (
22
components-x: true,
33
ui-shell: true,
4+
css--body: false, // we're providing our own body styles
5+
css--reset: false // prevent thousands of resets being included...
46
);
7+
58
.experimental {
6-
@import "~carbon-components/src/globals/scss/styles";
9+
@import '~carbon-components/scss/globals/scss/styles';
10+
11+
// carbon body reset and styles
12+
// @include reset;
13+
@include font-family;
14+
color: $text-01;
15+
background-color: $ui-02;
16+
line-height: 1;
17+
18+
@include typography;
19+
20+
// padding/margin body reset
21+
padding: 0;
22+
margin: 0;
723
}

.storybook/preview.scss

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,59 @@
1-
@import "~carbon-components/src/globals/scss/styles";
1+
$feature-flags: (
2+
components-x: false,
3+
ui-shell: true,
4+
css--body: false, // we're providing our own body styles
5+
css--reset: false // prevent thousands of resets being included...
6+
);
7+
8+
.carbon {
9+
@import '~carbon-components/scss/globals/scss/styles';
10+
11+
// carbon body reset and styles
12+
// @include reset;
13+
@include font-family;
14+
color: $text-01;
15+
background-color: $ui-02;
16+
line-height: 1;
17+
18+
@include typography;
19+
20+
// padding/margin body reset
21+
padding: 0;
22+
margin: 0;
23+
24+
// for some reason this isn't included when tabs are built. So lets just manually include it here.
25+
.bx--tabs__nav-item + .bx--tabs__nav-item {
26+
margin-left: 3rem;
27+
}
28+
29+
// for some reason this isn't included when progress indicator is built. So lets just manually include it here.
30+
.bx--progress-step:first-child .bx--progress-line {
31+
display: none;
32+
}
33+
34+
// for some reason all this isn't included when structured list is built. So lets just manually include it here.
35+
.bx--structured-list--selection .bx--structured-list-row:hover:not(.bx--structured-list-row--header-row) {
36+
background-color: $hover-row;
37+
cursor: pointer;
38+
}
39+
40+
.bx--structured-list-row:focus:not(.bx--structured-list-row--header-row) {
41+
@include focus-outline('border');
42+
}
43+
44+
.bx--structured-list-svg {
45+
display: inline-block;
46+
fill: transparent;
47+
vertical-align: middle;
48+
transition: $transition--base $carbon--standard-easing;
49+
}
50+
51+
.bx--structured-list-row:hover .bx--structured-list-svg {
52+
fill: $hover-row;
53+
}
54+
55+
.bx--structured-list-input:checked + .bx--structured-list-row .bx--structured-list-svg,
56+
.bx--structured-list-input:checked + .bx--structured-list-td .bx--structured-list-svg {
57+
fill: $brand-02;
58+
}
59+
}

.storybook/webpack.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ module.exports = (baseConfig, env, defaultConfig) => {
1515
enforce: 'pre',
1616
});
1717

18-
console.log(defaultConfig);
1918
defaultConfig.mode = "development";
2019
defaultConfig.devtool = "source-map";
2120
return defaultConfig;

0 commit comments

Comments
 (0)