Skip to content

Commit c9751a9

Browse files
authored
Merge pull request #98 from advanced-rest-client/fix/dark-mode-union-buttons
[@W-21514384] fix(api-type-document): use transparent/inherit fallbacks for union buttons in dark mode
2 parents cf8b660 + c864211 commit c9751a9

9 files changed

Lines changed: 27232 additions & 4212 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ dist/
6464
!demo/avro.json
6565
!demo/avro2.json
6666
!demo/grpc-test.json
67+
!demo/grpc-test-old.json
6768
!demo/product-order-minimal.json
6869
!demo/product-order-minimal-compact.json
6970
!demo/product-order-deep-allof.json

demo/grpc-test-old.json

Lines changed: 4490 additions & 0 deletions
Large diffs are not rendered by default.

demo/grpc-test.json

Lines changed: 22668 additions & 4203 deletions
Large diffs are not rendered by default.

demo/index.html

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,68 @@
6161
.options > * {
6262
margin-left: 8px;
6363
}
64+
65+
/* Dark mode: simulates theme where union/oneOf buttons use transparent/inherit */
66+
body.dark-mode {
67+
background-color: #1e1e1e !important;
68+
color: #e0e0e0;
69+
}
70+
body.dark-mode header {
71+
background-color: #2d2d2d;
72+
--iron-icon-fill-color: #e0e0e0;
73+
--paper-input-container-focus-color: #90caf9;
74+
--paper-input-container-label: { color: #e0e0e0; };
75+
}
76+
body.dark-mode [role="main"] {
77+
background-color: #1e1e1e;
78+
}
79+
.dark-mode-toggle {
80+
position: fixed;
81+
bottom: 12px;
82+
right: 12px;
83+
z-index: 9999;
84+
padding: 6px 10px;
85+
background: #333;
86+
color: #fff;
87+
border-radius: 4px;
88+
font-size: 12px;
89+
cursor: pointer;
90+
box-shadow: 0 2px 8px rgba(0,0,0,0.3);
91+
}
92+
.dark-mode-toggle input { margin-right: 6px; }
6493
</style>
6594
</head>
6695

6796
<body>
6897
<div id="demo"></div>
98+
<label class="dark-mode-toggle" title="Toggle dark mode to verify union/oneOf button visibility">
99+
<input type="checkbox" id="darkModeCheckbox" /> Dark mode
100+
</label>
69101

70102
<script type="module" src="index.js"></script>
71103

72104
<script>
105+
(function() {
106+
function initDarkMode() {
107+
var cb = document.getElementById('darkModeCheckbox');
108+
var stored = localStorage.getItem('api-type-document-dark-mode') === 'true';
109+
if (stored) {
110+
document.body.classList.add('dark-mode');
111+
if (cb) cb.checked = true;
112+
}
113+
if (cb) {
114+
cb.addEventListener('change', function() {
115+
document.body.classList.toggle('dark-mode', cb.checked);
116+
localStorage.setItem('api-type-document-dark-mode', cb.checked);
117+
});
118+
}
119+
}
120+
if (document.readyState === 'loading') {
121+
document.addEventListener('DOMContentLoaded', initDarkMode);
122+
} else {
123+
initDarkMode();
124+
}
125+
})();
73126
document.addEventListener('WebComponentsReady', function() {
74127
if (!window.ShadyCSS) {
75128
return;

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@api-components/api-type-document",
33
"description": "A documentation table for type (resource) properties. Works with AMF data model",
4-
"version": "4.2.42",
4+
"version": "4.2.43",
55
"license": "Apache-2.0",
66
"main": "index.js",
77
"module": "index.js",

src/TypeStyles.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ export default css`
4141
4242
.media-toggle {
4343
outline: none;
44-
color: var(--api-type-document-media-button-color, #000);
44+
color: var(--api-type-document-media-button-color, inherit);
4545
background-color: var(
4646
--api-type-document-media-button-background-color,
47-
#fff
47+
transparent
4848
);
4949
border-width: 1px;
5050
border-color: var(--api-type-document-media-button-border-color, #a3b11d);
@@ -64,9 +64,9 @@ export default css`
6464
outline: none;
6565
background-color: var(
6666
--api-type-document-union-button-background-color,
67-
#fff
67+
transparent
6868
);
69-
color: var(--api-type-document-union-button-color, #000);
69+
color: var(--api-type-document-union-button-color, inherit);
7070
border-width: 1px;
7171
border-color: var(--api-type-document-media-button-border-color, #a3b11d);
7272
border-style: solid;

test/api-type-document.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,17 @@ describe('<api-type-document>', () => {
690690
assert.equal(buttons.length, 2);
691691
});
692692

693+
it('union toggle buttons have transparent background by default (dark mode fix)', () => {
694+
const button = element.shadowRoot.querySelector('.union-toggle');
695+
assert.ok(button, 'union toggle button should exist');
696+
const styles = getComputedStyle(button);
697+
assert.notEqual(
698+
styles.backgroundColor,
699+
'rgb(255, 255, 255)',
700+
'should not use hardcoded white background (invisible in dark mode)'
701+
);
702+
});
703+
693704
it('Button change selection', () => {
694705
const buttons = element.shadowRoot.querySelectorAll('.union-toggle');
695706
/** @type HTMLElement */ (buttons[1]).click();

test/grpc.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ describe('<api-type-document> - gRPC', () => {
7272
let amf;
7373

7474
before(async () => {
75-
amf = await AmfLoader.load(compact, 'grpc-test');
75+
amf = await AmfLoader.load(compact, 'grpc-test-old');
7676
});
7777

7878
describe('link-target resolution', () => {
@@ -209,7 +209,7 @@ describe('<api-type-document> - gRPC', () => {
209209
assert.isDefined(props1, 'Should have initial computed properties');
210210

211211
// Update amf reference (simulate amf reload)
212-
const newAmf = await AmfLoader.load(compact, 'grpc-test');
212+
const newAmf = await AmfLoader.load(compact, 'grpc-test-old');
213213
element.amf = newAmf;
214214
await nextFrame();
215215
await aTimeout(0);

0 commit comments

Comments
 (0)