Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
apprat committed Dec 29, 2024
1 parent cfe1b52 commit e54e6de
Show file tree
Hide file tree
Showing 19 changed files with 225 additions and 86 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# 更新日志

## 1.0.0 (2024-12-30)

1. *Tooltip*
- 新增:`align` 属性新增 `left``right` 对齐方式。

## 0.8.0 (2024-12-25)

> 这是一个正式版之前的前瞻版本,对很多组件的 api 进行了调整使得它们容易和前端框架搭配使用。
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Sober

[![npm version](https://badge.fury.io/js/sober.svg)](https://badge.fury.io/js/sober)
![Static Badge](https://img.shields.io/badge/complete%20build-109kb-blue)
![Static Badge](https://img.shields.io/badge/gzip-25kb-wheat)
![Static Badge](https://img.shields.io/badge/complete%20build-110kb-blue)
![Static Badge](https://img.shields.io/badge/gzip-23kb-wheat)

Sober 是参考 Google Material You 设计规范的 Web Component UI 组件库。

Expand Down
4 changes: 3 additions & 1 deletion docs/zh-cn/BottomSheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
```html preview
<s-bottom-sheet>
<s-button slot="trigger"> Bottom Sheet </s-button>
问人生、头白京国,算来何事消得。不如罨画清溪上,蓑笠扁舟一只。人不识,且笑煮、鲈鱼趁著莼丝碧。无端酸鼻,向岐路消魂,征轮驿骑,断雁西风急。 英雄辈,事业东西南北。临风因甚泣。酬知有愿频挥手,零雨凄其此日。休太息,须信道、诸公衮衮皆虚掷。年来踪迹。有多少雄心,几翻恶梦,泪点霜华织。
<div slot="text">
问人生、头白京国,算来何事消得。不如罨画清溪上,蓑笠扁舟一只。人不识,且笑煮、鲈鱼趁著莼丝碧。无端酸鼻,向岐路消魂,征轮驿骑,断雁西风急。 英雄辈,事业东西南北。临风因甚泣。酬知有愿频挥手,零雨凄其此日。休太息,须信道、诸公衮衮皆虚掷。年来踪迹。有多少雄心,几翻恶梦,泪点霜华织。
</div>
</s-bottom-sheet>
```

Expand Down
2 changes: 1 addition & 1 deletion docs/zh-cn/Page.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
document.head.appendChild(themeColor)
//onChange
function themeChange() {
themeColor.content = getComputedStyle(page).getPropertyValue(`--s-color${page.isDark?'-dark':''}-surface-container-high`)
themeColor.content = getComputedStyle(page).getPropertyValue(`--s-color${page.isDark?'-dark':''}-surface-container`)
}
</script>
```
Expand Down
8 changes: 4 additions & 4 deletions docs/zh-cn/Popup.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@

## 属性

| 名称 | 类型 | 默认值 | 同步 | 介绍 |
| ------ | ------------------- | ------ | --- | ------- |
| align | center, left, right | center | | 位置 |
| 名称 | 类型 | 默认值 | 同步 | 介绍 |
| ------ | ------------------------ | ------ | --- | ------- |
| align | bottom, top, left, right | bottom | | 位置 |

---

Expand Down Expand Up @@ -69,7 +69,7 @@ class Popup extends HTMLElement {
//关闭弹出框
readonly close(): void
//位置
align: string = 'center'
align: 'top' | 'bottom' | 'left' | 'right' = 'bottom'
}
```

Expand Down
8 changes: 4 additions & 4 deletions docs/zh-cn/Tooltip.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

## 属性

| 名称 | 类型 | 默认值 | 同步 | 介绍 |
| ----- | ----------------- | ------ | --- | ---- |
| align | auto, bottom, top | auto || 位置 |
| 名称 | 类型 | 默认值 | 同步 | 介绍 |
| ----- | ------------------------ | ------ | --- | ---- |
| align | top, bottom, left, right | top || 位置 |

---

Expand All @@ -35,7 +35,7 @@ class Tooltip extends HTMLElement {
//隐藏提示框
readonly close(): void
//位置
align: 'auto' | 'bottom' | 'top' = 'auto'
align: 'top' | 'bottom' | 'left' | 'right' = 'top'
}
```

Expand Down
4 changes: 3 additions & 1 deletion src/appbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Theme } from './page.js'

const name = 's-appbar'
const props = {

}

const style = /*css*/`
Expand All @@ -14,11 +15,12 @@ const style = /*css*/`
position: relative;
padding: 0 8px;
flex-shrink: 0;
background: var(--s-color-surface-container-high, ${Theme.colorSurfaceContainerHigh});
background: var(--s-color-surface-container, ${Theme.colorSurfaceContainer});
}
::slotted([slot=navigation]){
margin-left: 4px;
flex-shrink: 0;
}
::slotted([slot=logo]){
margin-left: 12px;
Expand Down
6 changes: 3 additions & 3 deletions src/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const style = /*css*/`
font-size: .875rem;
padding: 4px 0;
flex-shrink: 0;
color: var(--s-color-on-surface, ${Theme.colorOnSurface});
}
:host(:nth-of-type(n+2)){
border-top: solid 1px var(--s-color-surface-variant, ${Theme.colorSurfaceVariant});
Expand Down Expand Up @@ -55,6 +54,7 @@ const itemStyle = /*css*/`
flex-direction: column;
flex-shrink: 0;
margin: 4px 8px 4px 0;
color: var(--s-color-on-surface, ${Theme.colorOnSurface});
}
.container{
display: flex;
Expand All @@ -71,8 +71,8 @@ const itemStyle = /*css*/`
.text{
flex-grow: 1;
white-space: nowrap;
display: flex;
align-items: center;
overflow: hidden;
text-overflow: ellipsis;
}
.toggle-icon{
width: 24px;
Expand Down
6 changes: 4 additions & 2 deletions src/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const style = /*css*/`
overflow: hidden;
background: var(--s-color-surface, ${Theme.colorSurface});
box-shadow: var(--s-elevation-level2, ${Theme.elevationLevel2});
color: var(--s-color-on-surface-variant, ${Theme.colorOnSurfaceVariant});
position: relative;
flex-shrink: 0;
padding-bottom: env(safe-area-inset-bottom);
Expand Down Expand Up @@ -98,6 +97,7 @@ const itemStyle = /*css*/`
max-width: 80px;
text-transform: capitalize;
transition: color .1s ease-out;
color: var(--s-color-on-surface, ${Theme.colorOnSurface});
}
:host([selected=true]){
color: var(--s-color-primary, ${Theme.colorPrimary});
Expand Down Expand Up @@ -142,7 +142,9 @@ const itemStyle = /*css*/`
}
::slotted([slot=icon]){
position: relative;
color: inherit;
}
:host([selected=true]) ::slotted([slot=icon]){
color: currentColor;
}
::slotted([slot=text]){
position: relative;
Expand Down
6 changes: 3 additions & 3 deletions src/picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,17 @@ const itemStyle = /*css*/`
border-radius: 4px;
flex-shrink: 0;
padding: 0 12px;
color: var(--s-color-on-surface, ${Theme.colorOnSurface});
}
:host([selected=true]){
background: var(--s-color-secondary-container, ${Theme.colorSecondaryContainer});
color: var(--s-color-on-secondary-container, ${Theme.colorOnSecondaryContainer});
}
.text{
flex-grow: 1;
display: flex;
align-items: center;
height: 100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
::slotted(svg){
fill: var(--s-color-on-surface-variant, ${Theme.colorOnSurfaceVariant});
Expand Down
7 changes: 4 additions & 3 deletions src/popup-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const style = /*css*/`
display: inline-block;
vertical-align: middle;
font-size: .875rem;
color: var(--s-color-on-surface, ${Theme.colorOnSurface});
}
.popup{
display: block;
Expand Down Expand Up @@ -60,6 +59,7 @@ export class PopupMenu extends useElement({
})
this.addEventListener(`${name}:click`, (event) => {
event.stopPropagation()
popup.close()
})
return {
mounted: () => {
Expand Down Expand Up @@ -88,12 +88,13 @@ const itemStyle = /*css*/`
cursor: pointer;
position: relative;
border-radius: 4px;
color: var(--s-color-on-surface, ${Theme.colorOnSurface});
}
.text{
flex-grow: 1;
white-space: nowrap;
display: flex;
align-items: center;
overflow: hidden;
text-overflow: ellipsis;
}
::slotted(svg){
fill: var(--s-color-on-surface-variant, ${Theme.colorOnSurfaceVariant});
Expand Down
77 changes: 43 additions & 34 deletions src/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { Theme } from './page.js'

const name = 's-popup'
const props = {
align: 'center' as 'center' | 'left' | 'right'
align: 'bottom' as 'top' | 'bottom' | 'left' | 'right'
}

const style = /*css*/`
:host{
display: inline-block;
vertical-align: middle;
text-align: left;
}
dialog{
top: 0;
Expand Down Expand Up @@ -81,47 +82,55 @@ class Popup extends useElement({
const el = option ?? this
if (!el) return
const rect = el.getBoundingClientRect()
position.origin = ['center', 'top']
position.top = rect.top + rect.height
position.left = rect.left - ((cWidth - rect.width) / 2)
if (this.align === 'center') {
if (position.left < 0) {
position.left = rect.left, 0
position.origin[0] = 'left'
}
if (position.left + cWidth > innerWidth) {
position.left = rect.left + rect.width - cWidth, 0
position.origin[0] = 'right'
}
if (position.top + rect.height + cHeight > innerHeight) {
position.top = rect.top - cHeight
position.origin[1] = 'bottom'
}
}
const calls = {
middle(align: 'top' | 'bottom') {
position.origin[0] = 'center'
position.left = rect.left - ((cWidth - rect.width) / 2)
const bottom = () => {
position.top = rect.top + rect.height
position.origin[1] = 'top'
return position.top + cHeight > innerHeight
}
const top = () => {
position.top = rect.top - cHeight
position.origin[1] = 'bottom'
return position.top < 0
}
if (position.left < 0) {
position.left = rect.left
position.origin[0] = 'left'
}
if (position.left + cWidth > innerWidth) {
position.left = rect.left + rect.width - cWidth
position.origin[0] = 'right'
}
if (align === 'top') top() && bottom()
if (align === 'bottom') bottom() && top()
},
left() {
position.top = rect.top
position.origin = ['right', 'top']
position.left = rect.left - cWidth
position.origin[0] = 'right'
position.top = rect.top
return position.left < 0
},
right() {
position.top = rect.top
position.origin = ['left', 'top']
position.left = rect.left + rect.width
position.origin[0] = 'left'
},
bottom() {
position.top = rect.top - cHeight + rect.height
position.origin[1] = 'bottom'
position.top = rect.top
return position.left + cWidth > innerWidth
}
}
if (this.align === 'left') {
calls.left()
if (position.top + cHeight > innerHeight) calls.bottom()
}
if (this.align === 'right') {
calls.right()
if (position.left + cWidth > innerWidth) calls.left()
if (position.top + cHeight > innerHeight) calls.bottom()
switch (this.align) {
case 'bottom':
case 'top':
calls.middle(this.align)
break
case 'left':
calls.left() && calls.right()
break
case 'right':
calls.right() && calls.left()
break
}
} else {
position.top = option.y
Expand Down
2 changes: 1 addition & 1 deletion src/segmented-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ const itemStyle = /*css*/`
display: flex;
justify-content: center;
align-items: center;
color: var(--s-color-on-surface, ${Theme.colorOnSurface});
height: 100%;
min-width: 48px;
padding: 0 16px;
Expand All @@ -70,6 +69,7 @@ const itemStyle = /*css*/`
position: relative;
cursor: pointer;
box-sizing: border-box;
color: var(--s-color-on-surface, ${Theme.colorOnSurface});
border-left: solid 1px var(--s-color-outline, ${Theme.colorOutline});
}
:host(:first-child){
Expand Down
Loading

0 comments on commit e54e6de

Please sign in to comment.