Skip to content

Commit

Permalink
feat(ui/app-bar): support props.safeAreaTop
Browse files Browse the repository at this point in the history
  • Loading branch information
haoziqaq committed Mar 30, 2023
1 parent 7783acf commit 9f00d43
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 5 deletions.
13 changes: 12 additions & 1 deletion packages/varlet-ui/src/app-bar/AppBar.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<template>
<div :class="classes(n(), [round, n('--round')], formatElevation(elevation, 3))" :style="rootStyles">
<div
:class="
classes(
n(),
n('$--box'),
[safeAreaTop, n('--safe-area-top')],
[round, n('--round')],
formatElevation(elevation, 3)
)
"
:style="rootStyles"
>
<div :class="n('toolbar')">
<div :class="n('left')">
<slot name="left" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`test app bar component props test app bar image and image-linear-gradient 1`] = `
"<div class=\\"var-app-bar var-elevation--3\\" style=\\"background-position: center center; background-size: cover;\\">
"<div class=\\"var-app-bar var--box var-elevation--3\\" style=\\"background-position: center center; background-size: cover;\\">
<div class=\\"var-app-bar__toolbar\\">
<div class=\\"var-app-bar__left\\">
<div class=\\"var-app-bar__title\\"></div>
Expand All @@ -15,7 +15,7 @@ exports[`test app bar component props test app bar image and image-linear-gradie
`;
exports[`test app bar slots test app bar content slot 1`] = `
"<div class=\\"var-app-bar var-elevation--3\\">
"<div class=\\"var-app-bar var--box var-elevation--3\\">
<div class=\\"var-app-bar__toolbar\\">
<div class=\\"var-app-bar__left\\">
<div class=\\"var-app-bar__title\\"></div>
Expand Down
6 changes: 6 additions & 0 deletions packages/varlet-ui/src/app-bar/appBar.less
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,10 @@
&--round {
border-radius: var(--app-bar-border-radius);
}

&--safe-area-top {
padding-top: constant(safe-area-inset-top);
padding-top: env(safe-area-inset-top);
box-sizing: content-box !important;
}
}
1 change: 1 addition & 0 deletions packages/varlet-ui/src/app-bar/docs/en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ const active = ref(0)
| `round` | Whether to use rounded border | _boolean_ | `false` |
| `image` | Background image | _string_ | `-` |
| `image-linear-gradient` | Background image linear gradient | _string_ | `-` |
| `safe-area-top` | Whether to enable top safe area adaptation | _boolean_ | `false` |

### Slots

Expand Down
1 change: 1 addition & 0 deletions packages/varlet-ui/src/app-bar/docs/zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ const active = ref(0)
| `round` | 是否使用圆角 | _boolean_ | `false` |
| `image` | 背景图片 | _string_ | `-` |
| `image-linear-gradient` | 背景图片渐变色 | _string_ | `-` |
| `safe-area-top` | 是否开启顶部安全区适配 | _boolean_ | `false` |

### 插槽

Expand Down
4 changes: 4 additions & 0 deletions packages/varlet-ui/src/app-bar/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ export const props = {
imageLinearGradient: {
type: String,
},
safeAreaTop: {
type: Boolean,
default: false,
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
-webkit-tap-highlight-color: transparent;

&--safe-area {
margin-bottom: constant(safe-area-inset-bottom); // iOS < 11.2
margin-bottom: env(safe-area-inset-bottom); // iOS >= 11.2
padding-bottom: constant(safe-area-inset-bottom); // iOS < 11.2
padding-bottom: env(safe-area-inset-bottom); // iOS >= 11.2
box-sizing: content-box !important;
}

&--fixed {
Expand Down
1 change: 1 addition & 0 deletions packages/varlet-ui/types/appBar.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface AppBarProps extends BasicAttributes {
round?: boolean
image?: string
imageLinearGradient?: string
safeAreaTop?: boolean
}

export class AppBar extends VarComponent {
Expand Down

0 comments on commit 9f00d43

Please sign in to comment.