-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
feat(layout): sider-position #657
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/tusimple/naive-ui/Da9jx2CpQe4QmetaSwFVePXMAo8C |
Codecov Report
@@ Coverage Diff @@
## main #657 +/- ##
==========================================
- Coverage 40.38% 40.36% -0.03%
==========================================
Files 507 507
Lines 12398 12407 +9
Branches 3486 3490 +4
==========================================
+ Hits 5007 5008 +1
- Misses 6478 6485 +7
- Partials 913 914 +1
Continue to review full report at Codecov.
|
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.
写个 Demo 吧,带宽度折叠的那种
@@ -34,6 +34,7 @@ scroll-to | |||
| has-sider | `boolean` | `false` | Whether the component has sider inside. If so it must be `true`. | | |||
| native-scrollbar | `boolean` | `true` | Whether to use native scrollbar on itself. If set to `false`, layout will use a naive-ui style scrollbar for content. | | |||
| position | `'static' \| 'absolute'` | `'static'` | `static` position will make it css position set to `static`. `absolute` position will make it css position set to `absolute` and `left`, `right`, `top`, `bottom` to `0`. `absolute` position is very useful when you want to make content scroll in a fixed container or make the whole page's layout in a fixed position. You may need to change the style of the component to make it display as you expect. | | |||
| sider-positioned | `boolean` | `false` | Whether the component content is reversed, if you need to set the sidebar on the right, you must set it to `true`. | |
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.
use sider-placement
instead
@@ -66,6 +67,7 @@ scroll-to | |||
| position | `'static' \| 'absolute'` | `'static'` | `static` 模式将会把 CSS `position` 设为 `static`, `absolute` 模式将会把 CSS `position` 设为 `absolute`,还将 `left`、`top`、`bottom` 设为 `0`。`absolute` 模式在你想将内容在一个固定容器或者将这个页面的布局设为固定位置的时候很有用。你可能需要修改一些 style 来确保它按照你预想的方式展示 | | |||
| show-collapsed-content | `boolean` | `true` | 是否在 `sider` 折叠后展示内部内容 | | |||
| show-trigger | `boolean \| 'bar' \| 'arrow-circle'` | `false` | 内置的触发按钮是否展示 | | |||
| sider-position | `'left' \| 'right'` | `left` | 侧边栏显示在左侧还是右侧 | |
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.
footer 需要这个吗?
src/layout/src/LayoutSider.tsx
Outdated
const mergedTriggerStyle = computed(() => [ | ||
props.triggerStyle, | ||
{ | ||
left: props.siderPosition === 'left' ? 'unset' : 0, |
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.
props.siderPosition === 'left'
这个提一层,siderOnLeft = ...
src/layout/src/LayoutSider.tsx
Outdated
return { | ||
borderRight: | ||
props.bordered && props.siderPosition === 'left' | ||
? '1px solid var(--border-color)' |
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.
? '1px solid var(--border-color)' | |
? '1px solid var(--border-color)' |
这块在 css 用类处理
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.
现在的改动会让 trigger button 出问题,看看
|
就是位置不对,和线上的版本不一致,你可以看 vercel 的 preview |
可以和线上的文档网站对比一下 |
src/layout/src/LayoutSider.tsx
Outdated
const siderPlacement = ref<'left' | 'right'>('left') | ||
const siderOnLeft = computed(() => { | ||
return siderPlacement.value === 'left' | ||
}) | ||
const mergedToggleButtonStyle = computed(() => { | ||
const translateXAndY = siderOnLeft.value | ||
? 'translateX(50%) translateY(-50%)' | ||
: 'translateX(-50%) translateY(-50%)' | ||
const translateZ = siderOnLeft.value | ||
? mergedCollapsedRef.value | ||
? 'rotate(180deg)' | ||
: 'rotate(0)' | ||
: mergedCollapsedRef.value | ||
? 'rotate(0)' | ||
: 'rotate(180deg)' | ||
return [ | ||
props.triggerStyle, | ||
!siderOnLeft.value && { left: 0 }, | ||
{ | ||
transform: `${translateXAndY} ${translateZ}` | ||
} | ||
] |
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.
我的直觉这个功能不至于写这么多样式在组件里,能简化一下吗😂
我单 review 已经看不出是不是有问题了。
能不能试着尽量把样式集中在 css 里,用类名解决?
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.
那样代码应该会少很多。
src/layout/src/LayoutSider.tsx
Outdated
const siderPlacement = ref<'left' | 'right'>('left') | ||
const siderOnLeft = computed(() => { | ||
return siderPlacement.value === 'left' | ||
}) |
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.
这块用 inject,不要在 render 里面用 $parent 修改这个值
src/layout/src/LayoutSider.tsx
Outdated
const siderScrollContainerTransformStyle = | ||
!this.siderOnLeft && this.collapseMode === 'transform' | ||
? `translateX(${ | ||
parseInt(formatLength(this.width)) - parseInt(this.styleMaxWidth) | ||
}px)` | ||
: 'unset' |
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.
这个能放到 css 里吗?用类名区分就可以
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.
这个translateX的值要计算,怎么放到css里呀?
src/layout/src/LayoutSider.tsx
Outdated
!this.siderOnLeft && | ||
`${mergedClsPrefix}-layout-toggle-button--right`, |
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.
这块可以不用这个类,它是 layout-sider DOM 的 children,用 css 就行了
src/layout/src/LayoutSider.tsx
Outdated
class={[ | ||
!this.siderOnLeft && | ||
`${mergedClsPrefix}-layout-toggle-bar--right` | ||
]} |
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.
这里也同理
src/layout/src/LayoutSider.tsx
Outdated
const siderOnLeft = computed(() => { | ||
return siderPlacement === 'left' | ||
}) |
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.
const siderOnLeft = computed(() => { | |
return siderPlacement === 'left' | |
}) | |
const siderOnLeftRef = computed(() => { | |
return siderPlacement === 'left' | |
}) |
src/layout/src/LayoutSider.tsx
Outdated
return {} | ||
} | ||
) | ||
const siderPlacement = layoutProps?.siderPlacement || 'left' |
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.
不能这么写,会丢失响应式,直接在其他 computed 里面用就行
src/layout/src/LayoutSider.tsx
Outdated
if (!siderOnLeft.value && props.collapseMode === 'transform') { | ||
return { | ||
transform: `translateX(${ | ||
parseInt(formatLength(props.width)) - | ||
parseInt(styleMaxWidthRef.value) | ||
}px)` | ||
} | ||
} |
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.
这个状态估计是不能支持百分比的宽度,在左侧时候是能支持的
src/layout/src/LayoutSider.tsx
Outdated
`${mergedClsPrefix}-layout-sider--${this.siderPlacement}-positioned`, | ||
this.bordered && | ||
`${mergedClsPrefix}-layout-sider--border-${ | ||
this.siderOnLeft ? 'right' : 'left' |
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.
siderPlacement 就行吧?
src/layout/src/LayoutSider.tsx
Outdated
{ | ||
transition: 'transform .3s var(--bezier)' | ||
} |
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.
这个地方可以用
cB('layout-sider', [
c('>', [
cB('scrollbar', 'transition: transform .3s var(--bezier);')
])
])
来解决
transform: `translateX(calc(${formatLength(props.width)} - ${ | ||
styleMaxWidthRef.value | ||
}px)` |
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.
calc 在 transform 里用其实没啥用,不会用外层的值
做了点修改,去掉了一些没用的代码 |
No description provided.