Skip to content

Commit 82382b4

Browse files
authored
Add slots to Navigator Components (#789) rdar://119614739
Add slots to Navigator Components (#789) rdar://119614739
1 parent 3bafe3c commit 82382b4

File tree

6 files changed

+39
-4
lines changed

6 files changed

+39
-4
lines changed

src/components/Navigator/BaseNavigatorCardItem.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
<div class="title-container">
2727
<slot name="title-container" />
2828
</div>
29+
<div class="content-container">
30+
<slot name="content-container" />
31+
</div>
2932
</div>
3033
</div>
3134
</template>

src/components/Navigator/NavigatorCard.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
:item="item"
7272
:isRendered="active"
7373
:filter-pattern="filterPattern"
74+
:filter-text="debouncedFilter"
7475
:is-active="item.uid === activeUID"
7576
:is-bold="activePathMap[item.uid]"
7677
:expanded="openNodes[item.uid]"
@@ -129,7 +130,7 @@ import {
129130
SIDEBAR_ITEM_SIZE,
130131
} from 'docc-render/constants/sidebar';
131132
import { safeHighlightPattern } from 'docc-render/utils/search-utils';
132-
import NavigatorCardItem from 'docc-render/components/Navigator/NavigatorCardItem.vue';
133+
import NavigatorCardItem from 'theme/components/Navigator/NavigatorCardItem.vue';
133134
import BaseNavigatorCard from 'docc-render/components/Navigator/BaseNavigatorCard.vue';
134135
import { TopicTypes } from 'docc-render/constants/TopicTypes';
135136
import FilterInput from 'docc-render/components/Filter/FilterInput.vue';

src/components/Navigator/NavigatorCardItem.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@
105105
<Badge v-if="isDeprecated" variant="deprecated" />
106106
<Badge v-else-if="isBeta" variant="beta" />
107107
</template>
108+
<template #content-container>
109+
<slot name="card-item-content" />
110+
</template>
108111
</BaseNavigatorCardItem>
109112
</template>
110113

@@ -152,6 +155,10 @@ export default {
152155
type: RegExp,
153156
default: undefined,
154157
},
158+
filterText: {
159+
type: String,
160+
default: null,
161+
},
155162
isActive: {
156163
type: Boolean,
157164
default: false,
@@ -263,7 +270,7 @@ $chevron-width: $nav-card-horizontal-spacing;
263270
264271
.is-group {
265272
.leaf-link {
266-
color: var(--color-figure-gray-secondary);
273+
color: var(--color-figure-gray-tertiary);
267274
font-weight: $font-weight-semibold;
268275
// groups dont need the overlay
269276
&:after {

tests/unit/components/Navigator/BaseNavigatorCardItem.spec.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* This source file is part of the Swift.org open source project
33
*
4-
* Copyright (c) 2022 Apple Inc. and the Swift project authors
4+
* Copyright (c) 2022-2024 Apple Inc. and the Swift project authors
55
* Licensed under Apache License v2.0 with Runtime Library Exception
66
*
77
* See https://swift.org/LICENSE.txt for license information
@@ -79,4 +79,15 @@ describe('BaseNavigatorCardItem', () => {
7979
expect(wrapper.find('.title-container').exists()).toBe(true);
8080
expect(wrapper.find('.title-container-slot').exists()).toBe(true);
8181
});
82+
83+
it('renders a slot for content-container', () => {
84+
wrapper = shallowMount(BaseNavigatorCardItem, {
85+
slots: {
86+
'content-container': '<div class="content-container-slot"></div>',
87+
},
88+
});
89+
90+
expect(wrapper.find('.content-container').exists()).toBe(true);
91+
expect(wrapper.find('.content-container-slot').exists()).toBe(true);
92+
});
8293
});

tests/unit/components/Navigator/NavigatorCard.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ describe('NavigatorCard', () => {
273273
isActive: false,
274274
isRendered: false,
275275
filterPattern: null,
276+
filterText: '',
276277
isFocused: false,
277278
isBold: true,
278279
item: root0,
@@ -574,6 +575,7 @@ describe('NavigatorCard', () => {
574575
isFocused: false,
575576
item,
576577
filterPattern: null,
578+
filterText: '',
577579
isRendered: false,
578580
apiChange: null,
579581
enableFocus: false,
@@ -2143,6 +2145,7 @@ describe('NavigatorCard', () => {
21432145
apiChange: null,
21442146
expanded: true,
21452147
filterPattern: null,
2148+
filterText: '',
21462149
isActive: true,
21472150
isBold: true,
21482151
isFocused: true,
@@ -2168,6 +2171,7 @@ describe('NavigatorCard', () => {
21682171
apiChange: null,
21692172
expanded: true,
21702173
filterPattern: null,
2174+
filterText: '',
21712175
isActive: true,
21722176
isBold: true,
21732177
isFocused: true,

tests/unit/components/Navigator/NavigatorCardItem.spec.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* This source file is part of the Swift.org open source project
33
*
4-
* Copyright (c) 2022-2023 Apple Inc. and the Swift project authors
4+
* Copyright (c) 2022-2024 Apple Inc. and the Swift project authors
55
* Licensed under Apache License v2.0 with Runtime Library Exception
66
*
77
* See https://swift.org/LICENSE.txt for license information
@@ -538,5 +538,14 @@ describe('NavigatorCardItem', () => {
538538
expect(waitFrames).toHaveBeenCalledWith(8);
539539
expect(document.activeElement).not.toEqual(wrapper.element);
540540
});
541+
542+
it('exposes a #card-item-content slot', () => {
543+
const wrapper = createWrapper({
544+
scopedSlots: {
545+
'card-item-content': '<div class="card-item-content">CustomNavigatorCardItemContentComponent</div>',
546+
},
547+
});
548+
expect(wrapper.find('.card-item-content').text()).toBe('CustomNavigatorCardItemContentComponent');
549+
});
541550
});
542551
});

0 commit comments

Comments
 (0)