-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
171 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# SafeArea 安全区 <Badge>v1.5.8</Badge> | ||
|
||
### 介绍 | ||
|
||
在全面屏下提供自适应的边距调整。当网页被全屏展示时,可借助安全区实现自动适配。 | ||
|
||
### 基础用法 | ||
|
||
```vue | ||
<script setup lang="ts"> | ||
function generateRandomTextArray(count: number) { | ||
const characters = 'abcdefghijklmnopqrstuvwxyz' | ||
const textArray = [] | ||
for (let j = 0; j < count; j++) { | ||
const randomLength = Math.floor(Math.random() * 5) + 4 // 随机生成长度在4到8之间的数 | ||
let randomText = '' | ||
for (let i = 0; i < randomLength; i++) { | ||
const randomIndex = Math.floor(Math.random() * characters.length) | ||
randomText += characters.charAt(randomIndex) | ||
} | ||
textArray.push(randomText) | ||
} | ||
return textArray | ||
} | ||
</script> | ||
<template> | ||
<div class="demo full"> | ||
<h2 class="title"> | ||
基础用法 | ||
</h2> | ||
<div> | ||
{{ generateRandomTextArray(900).join(' ') }} | ||
</div> | ||
<nut-safe-area position="bottom" /> | ||
</div> | ||
</template> | ||
``` | ||
|
||
## SafeArea | ||
|
||
### Props | ||
|
||
| 属性 | 说明 | 类型 | 默认值 | | ||
| --- | --- | --- |-----| | ||
| position | 安全区的位置 | `'top' \| 'bottom'` | `-` | | ||
|
||
## 主题定制 | ||
|
||
### 样式变量 | ||
|
||
组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 [ConfigProvider 组件](/components/basic/configprovider)。 | ||
|
||
| 名称 | 说明 | 默认值 | | ||
| --- | --- | --- | | ||
| \--nutui-safe-area-multiple | 显示的倍数 | `1` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<script setup lang="ts"> | ||
function generateRandomTextArray(count: number) { | ||
const characters = 'abcdefghijklmnopqrstuvwxyz' | ||
const textArray = [] | ||
for (let j = 0; j < count; j++) { | ||
const randomLength = Math.floor(Math.random() * 5) + 4 // 随机生成长度在4到8之间的数 | ||
let randomText = '' | ||
for (let i = 0; i < randomLength; i++) { | ||
const randomIndex = Math.floor(Math.random() * characters.length) | ||
randomText += characters.charAt(randomIndex) | ||
} | ||
textArray.push(randomText) | ||
} | ||
return textArray | ||
} | ||
</script> | ||
|
||
<template> | ||
<div class="demo full"> | ||
<h2 class="title"> | ||
基础用法 | ||
</h2> | ||
<div> | ||
{{ generateRandomTextArray(900).join(' ') }} | ||
</div> | ||
<nut-safe-area position="bottom" /> | ||
</div> | ||
</template> | ||
|
||
<route lang="json"> | ||
{ | ||
"style": { | ||
"navigationBarTitleText": "SafeArea" | ||
} | ||
} | ||
</route> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.nut-safe-area { | ||
display: block; | ||
width: 100%; | ||
|
||
&-position-top { | ||
padding-top: calc( | ||
env(safe-area-inset-top) * var(--nutui-safe-area-multiple, 1) | ||
); | ||
} | ||
|
||
&-position-bottom { | ||
padding-bottom: calc( | ||
env(safe-area-inset-bottom) * var(--nutui-safe-area-multiple, 1) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './safearea' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { ExtractPropTypes, PropType } from 'vue' | ||
import { commonProps } from '../_utils' | ||
|
||
export const safeareaProps = { | ||
...commonProps, | ||
/** | ||
* @description 安全区的位置 | ||
*/ | ||
position: String as PropType<'top' | 'bottom'>, | ||
} | ||
|
||
export type SafeAreaProps = ExtractPropTypes<typeof safeareaProps> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<script setup lang="ts"> | ||
import { computed, defineComponent } from 'vue' | ||
import { PREFIX } from '../_constants' | ||
import { getMainClass } from '../_utils' | ||
import { safeareaProps } from './safearea' | ||
const props = defineProps(safeareaProps) | ||
const classes = computed(() => { | ||
return getMainClass(props, componentName, [ | ||
`${componentName}-position-${props.position}`, | ||
]) | ||
}) | ||
</script> | ||
|
||
<script lang="ts"> | ||
const componentName = `${PREFIX}-safe-area` | ||
export default defineComponent({ | ||
name: componentName, | ||
options: { | ||
virtualHost: true, | ||
addGlobalClass: true, | ||
styleIsolation: 'shared', | ||
}, | ||
}) | ||
</script> | ||
|
||
<template> | ||
<view :class="classes" :style="customStyle" /> | ||
</template> | ||
|
||
<style lang="scss"> | ||
@import './index'; | ||
</style> |