Skip to content

Commit d814cd8

Browse files
committed
[rdar://30234820] fix: address feedback
1 parent f81e35c commit d814cd8

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

src/components/ContentNode/Caption.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ export default {
3333
},
3434
tag: {
3535
type: String,
36-
required: false,
37-
default: () => 'caption',
36+
required: true,
37+
validator: v => new Set(['caption', 'figcaption']).has(v),
3838
},
3939
},
4040
};
@@ -44,12 +44,16 @@ export default {
4444
@import 'docc-render/styles/_core.scss';
4545
4646
.caption {
47-
@include font-styles(documentation-figcaption);
47+
@include font-styles(documentation-caption);
4848
4949
&:last-child {
5050
margin-top: var(--spacing-stacked-margin-large);
5151
}
5252
53+
&:has(+ *) {
54+
margin-bottom: var(--spacing-stacked-margin-large);
55+
}
56+
5357
&.centered {
5458
text-align: center;
5559
}
@@ -58,8 +62,4 @@ export default {
5862
/deep/ p {
5963
display: inline-block;
6064
}
61-
62-
caption {
63-
margin: 1rem 0;
64-
}
6565
</style>

src/components/ContentNode/Figure.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ export default {
2323
},
2424
};
2525
</script>
26-
2726
<style scoped lang="scss">
28-
/deep/ figcaption + * {
29-
margin-top: 1rem;
27+
/deep/ figcaption {
28+
--spacing-stacked-margin-large: 1rem;
3029
}
3130
</style>

tests/unit/components/ContentNode.spec.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,29 @@ describe('ContentNode', () => {
112112
expect(codeListing.props('content')).toEqual(listing.code);
113113
expect(codeListing.isEmpty()).toBe(true);
114114
});
115+
116+
it('renders a `Figure`/`Caption` with metadata', () => {
117+
const metadata = {
118+
anchor: '42',
119+
title: 'Listing 42',
120+
abstract: [{
121+
type: 'paragraph',
122+
inlineContent: [{ type: 'text', text: 'blah' }],
123+
}],
124+
};
125+
const wrapper = mountWithItem({ ...listing, metadata });
126+
127+
const figure = wrapper.find(Figure);
128+
expect(figure.exists()).toBe(true);
129+
expect(figure.props('anchor')).toBe(metadata.anchor);
130+
expect(figure.contains(CodeListing)).toBe(true);
131+
132+
const caption = figure.find(Caption);
133+
expect(caption.exists()).toBe(true);
134+
expect(caption.props('title')).toBe(metadata.title);
135+
expect(caption.contains('p')).toBe(true);
136+
expect(caption.text()).toContain('blah');
137+
});
115138
});
116139

117140
describe('with type="endpointExample"', () => {
@@ -753,7 +776,7 @@ describe('ContentNode', () => {
753776
`);
754777
});
755778

756-
it('renders a `FigureCaption` before the image, if it has a title', () => {
779+
it('renders a `Caption` before the image, if it has a title', () => {
757780
const metadata = {
758781
title: 'foo',
759782
abstract: [{
@@ -776,7 +799,7 @@ describe('ContentNode', () => {
776799
`);
777800
});
778801

779-
it('renders no `FigureCaption`, if there is a `title`, but no `abstract`', () => {
802+
it('renders no `Caption`, if there is a `title`, but no `abstract`', () => {
780803
const metadata = {
781804
postTitle: true,
782805
title: 'Foo',

0 commit comments

Comments
 (0)