Skip to content

Commit e13b1bc

Browse files
Highlight unique components of overloaded declarations (#841) (#849)
Resolves: rdar://128997251 Co-authored-by: Vera Mitchell <[email protected]>
1 parent 5ba3781 commit e13b1bc

File tree

7 files changed

+92
-2
lines changed

7 files changed

+92
-2
lines changed

src/components/DocumentationTopic/PrimaryContent/DeclarationList.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,15 @@ export default {
195195
}
196196
}
197197
198+
// don't highlight tokens in initial declaration until the user has explicitly
199+
// expanded a list of overloaded declarations — this rule could be simplified
200+
// in the future if the HTML is restructured to have an expanded state class for
201+
// the whole list instead of having it on each declaration
202+
.declaration-pill:not(.declaration-pill--expanded):deep(.highlighted) {
203+
background: unset;
204+
font-weight: normal;
205+
}
206+
198207
.declaration-pill--expanded {
199208
transition-timing-function: linear;
200209
transition-property: opacity, height;
@@ -218,7 +227,7 @@ export default {
218227
border-color: var(--color-focus-border-color, var(--color-focus-border-color));
219228
}
220229
221-
:not(.selected-declaration) {
230+
.source:not(.selected-declaration) {
222231
background: unset;
223232
}
224233

src/components/DocumentationTopic/PrimaryContent/DeclarationToken.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import ChangedToken from './DeclarationToken/ChangedToken.vue';
1414
import LinkableToken from './DeclarationToken/LinkableToken.vue';
1515
import RawText from './DeclarationToken/RawText.vue';
1616
import SyntaxToken from './DeclarationToken/SyntaxToken.vue';
17+
import Highlighted from './DeclarationToken/Highlighted.vue';
1718
1819
const TokenKind = {
1920
attribute: 'attribute',
@@ -27,13 +28,14 @@ const TokenKind = {
2728
string: 'string',
2829
text: 'text',
2930
typeIdentifier: 'typeIdentifier',
31+
highlightDiff: 'highlightDiff',
3032
added: 'added',
3133
removed: 'removed',
3234
};
3335
3436
export default {
3537
name: 'DeclarationToken',
36-
render(createElement) {
38+
render: function _render(createElement) {
3739
const {
3840
kind,
3941
text,
@@ -69,6 +71,10 @@ export default {
6971
case TokenKind.added:
7072
case TokenKind.removed:
7173
return createElement(ChangedToken, { props: { tokens, kind } });
74+
case TokenKind.highlightDiff:
75+
return createElement(Highlighted, {}, (tokens || []).map(token => (
76+
_render.bind(token)(createElement)
77+
)));
7278
default: {
7379
const props = {
7480
kind,
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!--
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright (c) 2024 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See https://swift.org/LICENSE.txt for license information
8+
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
-->
10+
11+
<template>
12+
<strong class="highlighted"><slot /></strong>
13+
</template>
14+
15+
<script>
16+
export default { name: 'Highlighted' };
17+
</script>
18+
19+
<style scoped lang="scss">
20+
.highlighted {
21+
background: var(--color-syntax-highlighted, mark);
22+
}
23+
</style>

src/styles/core/colors/_dark.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
--color-syntax-comments: rgb(127, 140, 152);
6464
--color-syntax-documentation-markup: rgb(127, 140, 152);
6565
--color-syntax-documentation-markup-keywords: rgb(163, 177, 191);
66+
--color-syntax-highlighted: rgba(0, 113, 227, 0.6);
6667
--color-syntax-keywords: rgb(255, 122, 178);
6768
--color-syntax-marks: rgb(255, 255, 255);
6869
--color-syntax-numbers: rgb(217, 201, 124);

src/styles/core/colors/_light.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@
152152
--color-syntax-documentation-markup: rgb(80, 99, 117);
153153
--color-syntax-documentation-markup-keywords: rgb(80, 99, 117);
154154
--color-syntax-heading: rgb(186, 45, 162);
155+
--color-syntax-highlighted: rgba(0, 113, 227, 0.2);
155156
--color-syntax-keywords: rgb(173, 61, 164);
156157
--color-syntax-marks: rgb(0, 0, 0);
157158
--color-syntax-numbers: rgb(39, 42, 216);

tests/unit/components/DocumentationTopic/PrimaryContent/DeclarationToken.spec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import SyntaxToken
1818
import LinkableToken
1919
from 'docc-render/components/DocumentationTopic/PrimaryContent/DeclarationToken/LinkableToken.vue';
2020
import WordBreak from 'docc-render/components/WordBreak.vue';
21+
import Highlighted
22+
from 'docc-render/components/DocumentationTopic/PrimaryContent/DeclarationToken/Highlighted.vue';
2123

2224
const { TokenKind } = DeclarationToken.constants;
2325

@@ -58,6 +60,7 @@ describe('DeclarationToken', () => {
5860
otherKinds.delete(TokenKind.typeIdentifier);
5961
otherKinds.delete(TokenKind.removed);
6062
otherKinds.delete(TokenKind.added);
63+
otherKinds.delete(TokenKind.highlightDiff);
6164

6265
otherKinds.forEach((kind) => {
6366
const propsData = { kind, text: 'foo' };
@@ -125,4 +128,29 @@ describe('DeclarationToken', () => {
125128
expect(link.text()).toBe(propsData.text);
126129
expect(link.classes()).toContain('attribute-link');
127130
});
131+
132+
it('renders a `Highlighted` for `highlightDiff` tokens', () => {
133+
const stubs = { RawText };
134+
const propsData = {
135+
kind: TokenKind.highlightDiff,
136+
tokens: [
137+
{
138+
kind: TokenKind.text,
139+
text: 'foo',
140+
},
141+
{
142+
kind: TokenKind.text,
143+
text: 'bar',
144+
},
145+
],
146+
};
147+
const wrapper = mountToken({ propsData, stubs });
148+
const highlighted = wrapper.find(Highlighted);
149+
expect(highlighted.exists()).toBe(true);
150+
151+
const textTokens = highlighted.findAll(RawText);
152+
expect(textTokens.length).toBe(propsData.tokens.length);
153+
expect(textTokens.at(0).props('text')).toBe(propsData.tokens[0].text);
154+
expect(textTokens.at(1).props('text')).toBe(propsData.tokens[1].text);
155+
});
128156
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* This source file is part of the Swift.org open source project
3+
*
4+
* Copyright (c) 2024 Apple Inc. and the Swift project authors
5+
* Licensed under Apache License v2.0 with Runtime Library Exception
6+
*
7+
* See https://swift.org/LICENSE.txt for license information
8+
* See https://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
import { shallowMount } from '@vue/test-utils';
11+
import Highlighted from 'docc-render/components/DocumentationTopic/PrimaryContent/DeclarationToken/Highlighted.vue';
12+
13+
describe('Highlighted', () => {
14+
it('renders slotted content using strong.highlighted', () => {
15+
const slots = { default: 'hello, world' };
16+
const wrapper = shallowMount(Highlighted, { slots });
17+
18+
const strong = wrapper.find('strong.highlighted');
19+
expect(strong.exists()).toBe(true);
20+
expect(strong.text()).toBe(slots.default);
21+
});
22+
});

0 commit comments

Comments
 (0)