-
Notifications
You must be signed in to change notification settings - Fork 60
Support the @Row
directive
#409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f675d65
69d46be
2ac6401
a159625
0a7f54a
a039a17
61570d9
40b3a36
67ddb8b
76c2c06
9f62ff4
c240b7f
640a02a
1335bc1
2171764
5761406
d99cb7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<!-- | ||
This source file is part of the Swift.org open source project | ||
|
||
Copyright (c) 2022 Apple Inc. and the Swift project authors | ||
Licensed under Apache License v2.0 with Runtime Library Exception | ||
|
||
See https://swift.org/LICENSE.txt for license information | ||
See https://swift.org/CONTRIBUTORS.txt for Swift project authors | ||
--> | ||
<template> | ||
<div class="column" :style="style"> | ||
<slot /> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: 'Column', | ||
props: { | ||
span: { | ||
type: Number, | ||
default: null, | ||
}, | ||
}, | ||
computed: { | ||
style: ({ span }) => ({ '--col-span': span }), | ||
}, | ||
}; | ||
</script> | ||
|
||
<style scoped lang='scss'> | ||
@import 'docc-render/styles/_core.scss'; | ||
|
||
.column { | ||
grid-column: span var(--col-span); | ||
min-width: 0; | ||
@include breakpoint(small) { | ||
grid-column: span 1; | ||
} | ||
} | ||
</style> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<!-- | ||
This source file is part of the Swift.org open source project | ||
|
||
Copyright (c) 2022 Apple Inc. and the Swift project authors | ||
Licensed under Apache License v2.0 with Runtime Library Exception | ||
|
||
See https://swift.org/LICENSE.txt for license information | ||
See https://swift.org/CONTRIBUTORS.txt for Swift project authors | ||
--> | ||
<template> | ||
<div class="row" :style="style" :class="{ 'with-columns': columns }"> | ||
<slot /> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
/** | ||
* A Row component that accepts an optional `columns` prop. | ||
* When columns is passed, the grid will have that exact number of columns. | ||
* If no `columns` provided, width is split up equally across each cell. | ||
*/ | ||
export default { | ||
name: 'Row', | ||
props: { | ||
columns: { | ||
type: Number, | ||
default: null, | ||
required: false, | ||
validator: v => v > 0, | ||
}, | ||
gap: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we using this prop at the moment? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not right now, but I am assuming we may start to, if we start using this as a building block for future components. |
||
type: Number, | ||
required: false, | ||
}, | ||
}, | ||
computed: { | ||
style: ({ columns, gap }) => ({ | ||
'--col-count': columns, | ||
'--col-gap': gap && `${gap}px`, | ||
}), | ||
}, | ||
}; | ||
</script> | ||
|
||
<style scoped lang='scss'> | ||
@import 'docc-render/styles/_core.scss'; | ||
|
||
.row { | ||
display: grid; | ||
grid-auto-flow: column; | ||
grid-auto-columns: 1fr; | ||
grid-gap: var(--col-gap, #{$article-stacked-margin-small}); | ||
|
||
&.with-columns { | ||
grid-template-columns: repeat(var(--col-count), 1fr); | ||
grid-auto-flow: row; | ||
|
||
@include breakpoint(small) { | ||
grid-template-columns: 1fr; | ||
} | ||
} | ||
|
||
@include breakpoint(small) { | ||
grid-template-columns: 1fr; | ||
grid-auto-flow: row; | ||
} | ||
|
||
/deep/ + * { | ||
margin-top: $stacked-margin-large; | ||
} | ||
} | ||
</style> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* This source file is part of the Swift.org open source project | ||
* | ||
* Copyright (c) 2022 Apple Inc. and the Swift project authors | ||
* Licensed under Apache License v2.0 with Runtime Library Exception | ||
* | ||
* See https://swift.org/LICENSE.txt for license information | ||
* See https://swift.org/CONTRIBUTORS.txt for Swift project authors | ||
*/ | ||
|
||
import Column from '@/components/ContentNode/Column.vue'; | ||
import { shallowMount } from '@vue/test-utils'; | ||
|
||
const createWrapper = props => shallowMount(Column, { | ||
slots: { | ||
default: 'Default Content', | ||
}, | ||
...props, | ||
}); | ||
|
||
describe('Column', () => { | ||
it('renders the Column', () => { | ||
const wrapper = createWrapper(); | ||
expect(wrapper.classes()).toContain('column'); | ||
expect(wrapper.text()).toBe('Default Content'); | ||
expect(wrapper.vm.style).toHaveProperty('--col-span', null); | ||
wrapper.setProps({ | ||
span: 5, | ||
}); | ||
expect(wrapper.vm.style).toHaveProperty('--col-span', 5); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* This source file is part of the Swift.org open source project | ||
* | ||
* Copyright (c) 2022 Apple Inc. and the Swift project authors | ||
* Licensed under Apache License v2.0 with Runtime Library Exception | ||
* | ||
* See https://swift.org/LICENSE.txt for license information | ||
* See https://swift.org/CONTRIBUTORS.txt for Swift project authors | ||
*/ | ||
|
||
import Row from '@/components/ContentNode/Row.vue'; | ||
import { shallowMount } from '@vue/test-utils'; | ||
|
||
const createWrapper = props => shallowMount(Row, { | ||
slots: { | ||
default: 'Slot Content', | ||
}, | ||
...props, | ||
}); | ||
|
||
describe('Row', () => { | ||
it('renders the Row', () => { | ||
const wrapper = createWrapper(); | ||
expect(wrapper.classes()).toContain('row'); | ||
expect(wrapper.classes()).not.toContain('with-columns'); | ||
expect(wrapper.text()).toContain('Slot Content'); | ||
}); | ||
|
||
it('renders with columns in mind', () => { | ||
const wrapper = createWrapper({ | ||
propsData: { | ||
columns: 4, | ||
}, | ||
}); | ||
expect(wrapper.classes()).toContain('with-columns'); | ||
expect(wrapper.vm.style).toHaveProperty('--col-count', 4); | ||
}); | ||
|
||
it('provides a --col-gap', () => { | ||
const wrapper = createWrapper({ | ||
propsData: { | ||
gap: 10, | ||
}, | ||
}); | ||
expect(wrapper.vm.style).toHaveProperty('--col-gap', '10px'); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is
min-width: 0;
needed?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tells the flex/column item to become smaller than it can right now, so it does not overflow.
If we have images or text that are wider than the column, this will make the column outgrow what it should.