Skip to content

Commit

Permalink
Merge branch 'FriedRiceNoodles:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
563316158 authored Aug 7, 2024
2 parents 804b898 + eb32972 commit 6a5db30
Show file tree
Hide file tree
Showing 16 changed files with 320 additions and 30 deletions.
6 changes: 4 additions & 2 deletions docs/example/Tooltip/demos/triggerAction.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/**
* title: 触发方式
* description: 通过 `triggerAction` 参数设置触发方式,可选值为 `hover`、`click`, 默认为 `hover`。
* description: 通过 `triggerAction` 参数设置触发方式,可选值为 `hover`、`click`、`none`, 默认为 `hover`。
*/

import { Button, Tooltip } from '@banana-ui/react';
import React from 'react';

export default function TriggerAction() {
return (
Expand All @@ -15,6 +14,9 @@ export default function TriggerAction() {
<Tooltip content="This is a tooltip." triggerAction="click">
<Button style={{ marginLeft: '16px' }}>Click</Button>
</Tooltip>
<Tooltip content="Set triggerAction to 'none' will make the tooltip always show." triggerAction="none">
<Button style={{ marginLeft: '16px' }}>None</Button>
</Tooltip>
</div>
);
}
24 changes: 12 additions & 12 deletions docs/example/Tooltip/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ demo:

## 属性 - Attributes & Properties

| 属性 | 说明 | 类型 | 默认值 |
| --------------------------------------------------------------- | ------------------------------- | -------------------- | --------------------- |
| content | 提示内容 | `boolean` | '' |
| placement | 弹出位置 | `Placement` | 'top' |
| disableAutoAdjustOverflow <br /> (disable-auto-adjust-overflow) | 禁用自动调整弹出位置 | `boolean` | false |
| maxWidth <br /> (max-width) | 气泡的最大宽度 | `number \| string ` | '300px' |
| backgroundColor <br /> (background-color) | 气泡的背景颜色 | `string` | 'rgba(46, 50 ,56, 1)' |
| margin | 气泡与触发元素(trigger)的距离 | `number` | 8 |
| mouseEnterDelay <br /> (mouse-enter-delay) | 鼠标移入后延时多少才显示 | `number` | 100 |
| mouseLeaveDelay <br /> (mouse-leave-delay) | 鼠标移出后延时多少才隐藏 | `number` | 100 |
| triggerAction <br /> (trigger-action) | 触发行为 | `'hover' \| 'click'` | 'hover' |
| noArrow | 是否隐藏箭头 | `boolean` | false |
| 属性 | 说明 | 类型 | 默认值 |
| --------------------------------------------------------------- | --------------------------------------- | ------------------------------ | --------------------- |
| content | 提示内容 | `boolean` | '' |
| placement | 弹出位置 | `Placement` | 'top' |
| disableAutoAdjustOverflow <br /> (disable-auto-adjust-overflow) | 禁用自动调整弹出位置 | `boolean` | false |
| maxWidth <br /> (max-width) | 气泡的最大宽度 | `number \| string ` | '300px' |
| backgroundColor <br /> (background-color) | 气泡的背景颜色 | `string` | 'rgba(46, 50 ,56, 1)' |
| margin | 气泡与触发元素(trigger)的距离 | `number` | 8 |
| mouseEnterDelay <br /> (mouse-enter-delay) | 鼠标移入后延时多少才显示 | `number` | 100 |
| mouseLeaveDelay <br /> (mouse-leave-delay) | 鼠标移出后延时多少才隐藏 | `number` | 100 |
| triggerAction <br /> (trigger-action) | 触发行为,为`none`时 tooltip 会一直展示 | `'hover' \| 'click' \| 'none'` | 'hover' |
| noArrow <br /> (no-arrow) | 是否隐藏箭头 | `boolean` | false |

```typescript
export type Placement =
Expand Down
15 changes: 11 additions & 4 deletions docs/guide/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,35 @@ order: 2

## 原生环境和非 React 框架

NPM 安装:
### NPM 安装:

```bash
npm i @banana-ui/banana
```

CDN 引入:
### CDN 引入:

```html
/* UMD Namespace: Banana */
<script src="https://cdn.jsdelivr.net/npm/@banana-ui/banana/umd/index.js"></script>
```

or

```html
<!-- 按需引入 -->
<script type="module" src="https://cdn.jsdelivr.net/npm/@banana-ui/banana/dist/banana-autoloader.js"></script>
```

## React

NPM 安装:
### NPM 安装:

```bash
npm i @banana-ui/react
```

CDN 引入:
### CDN 引入:

```html
/* UMD Namespace: BananaReact */
Expand Down
8 changes: 8 additions & 0 deletions docs/guide/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,17 @@ order: 1
### CDN

```html
<!-- 全量引入 -->
<script src="https://cdn.jsdelivr.net/npm/@banana-ui/banana/umd/index.js"></script>
```

or

```html
<!-- 按需引入 -->
<script type="module" src="https://cdn.jsdelivr.net/npm/@banana-ui/banana/dist/banana-autoloader.js"></script>
```

### NPM 安装

```bash
Expand Down
43 changes: 43 additions & 0 deletions packages/banana-react/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,48 @@
# @banana/banana-react

## 1.19.3

### Patch Changes

- 4fedae7: Fix a bug that make empty content shown when the trigger action is none.
- Updated dependencies [4fedae7]
- @banana-ui/banana@1.19.3

## 1.19.2

### Patch Changes

- 07107d5: Added a new trigger action to tooltip.
- Updated dependencies [07107d5]
- @banana-ui/banana@1.19.2

## 1.19.1

### Patch Changes

- 94c54f0: Make autoloader covers b-message
- Updated dependencies [94c54f0]
- @banana-ui/banana@1.19.1

## 1.19.0

### Minor Changes

- 4bb6fbb: Autoloader for banana.

### Patch Changes

- Updated dependencies [4bb6fbb]
- @banana-ui/banana@1.19.0

## 1.18.3

### Patch Changes

- 6800fbf: slide item's gap use margin to complete
- Updated dependencies [6800fbf]
- @banana-ui/banana@1.18.3

## 1.18.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/banana-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@banana-ui/react",
"version": "1.18.2",
"version": "1.19.3",
"description": "React components for Banana UI",
"keywords": [
"web components",
Expand Down
30 changes: 30 additions & 0 deletions packages/banana/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
# banana-ui

## 1.19.3

### Patch Changes

- 4fedae7: Fix a bug that make empty content shown when the trigger action is none.

## 1.19.2

### Patch Changes

- 07107d5: Added a new trigger action to tooltip.

## 1.19.1

### Patch Changes

- 94c54f0: Make autoloader covers b-message

## 1.19.0

### Minor Changes

- 4bb6fbb: Autoloader for banana.

## 1.18.3

### Patch Changes

- 6800fbf: slide item's gap use margin to complete

## 1.18.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/banana/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@banana-ui/banana",
"version": "1.18.2",
"version": "1.19.3",
"description": "An UI library of web components can be used in any framework",
"keywords": [
"web components",
Expand Down
96 changes: 96 additions & 0 deletions packages/banana/src/banana-autoloader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Inpired by https://github.com/shoelace-style/shoelace/blob/next/src/shoelace-autoloader.ts

function getBasePath(subpath = '') {
const scripts = [...document.getElementsByTagName('script')] as HTMLScriptElement[];
const autoloader = scripts.find((script) => script.src.includes('banana-autoloader')) as HTMLScriptElement;
const basePath = autoloader.src.split('/').slice(0, -1).join('/');

// Return the base path without a trailing slash. If one exists, append the subpath separated by a slash.
return basePath.replace(/\/$/, '') + (subpath ? `/${subpath.replace(/^\//, '')}` : ``);
}

const observer = new MutationObserver((mutations) => {
for (const { addedNodes } of mutations) {
for (const node of addedNodes) {
if (node.nodeType === Node.ELEMENT_NODE) {
void discover(node as Element);
}
}
}
});

/**
* Checks a node for undefined elements and attempts to register them.
*/
async function discover(root: Element | ShadowRoot) {
if (!root) return;

const rootTagName = root instanceof Element ? root.tagName.toLowerCase() : '';
const rootIsBananaElement = rootTagName?.toLowerCase().startsWith('b-');
const rootIsCustomElement = rootTagName?.includes('-');

const tags = [...root.querySelectorAll(':not(:defined)')]
.map((el) => el.tagName.toLowerCase())
.filter((tag) => tag.startsWith('b-'));

// If the root element is an undefined Banana component, add it to the list
if (rootIsBananaElement && !customElements.get(rootTagName)) {
tags.push(rootTagName);
}

// Make the list unique
const tagsToRegister = [...new Set(tags)];

const notBananaCustomElements = [...root.querySelectorAll('*')].filter(
(el) => el.tagName.includes('-') && !el.tagName.toLowerCase().startsWith('b-'),
);

// If the root element is a custom element and not a Banana component, add it to the list
if (rootIsCustomElement && !rootIsBananaElement && root instanceof Element) {
notBananaCustomElements.push(root);
}

// Discover any shadow roots
const customElementsPromises = notBananaCustomElements.map((el) => {
return customElements.whenDefined(el.tagName);
});
void Promise.allSettled(customElementsPromises).then(() => {
notBananaCustomElements.forEach((el) => {
if (el.shadowRoot) void discover(el.shadowRoot);
});
});

await Promise.allSettled(tagsToRegister.map((tagName) => register(tagName)));
}

/**
* Registers an element by tag name.
*/
function register(tagName: string): Promise<void> {
// If the element is already defined, there's nothing more to do
if (customElements.get(tagName)) {
return Promise.resolve();
}

const tagWithoutPrefix = tagName.replace(/^b-/i, '');
const path = getBasePath(`${tagWithoutPrefix}/index.js`);

// Register it
return new Promise((resolve, reject) => {
import(path).then(() => resolve()).catch(() => reject(new Error(`Unable to autoload <${tagName}> from ${path}`)));
});
}

// Initial discovery
void discover(document.body);

// Listen for new undefined elements
observer.observe(document.documentElement, { subtree: true, childList: true });

// BMessage is a special case because it's often used by window.BMessage methods but not directly in the DOM
// If it's not defined, import it directly
if (!customElements.get('b-message')) {
// import the module
const path = getBasePath('message/index.js');
void import(path);
}
3 changes: 2 additions & 1 deletion packages/banana/src/carousel/index.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export default [
transition: transform var(--banana-carousel-transition-duration, ${unsafeCSS(Var.TransitionNormal)});
/* This variable should not be used directly, use the gap property instead */
/* DO NOT PUT IT IN THE DOCUMENTATION */
gap: calc(var(--banana-carousel-gap, 0) * 1px);
}
.slides-wrapper--vertical {
flex-direction: column;
Expand All @@ -55,6 +54,7 @@ export default [
height: 100%;
flex-grow: 0;
flex-shrink: 0;
margin-right: calc(var(--banana-carousel-gap, 0) * 1px);
}
.slides-wrapper--vertical ::slotted(*) {
Expand All @@ -67,6 +67,7 @@ export default [
width: 100%;
flex-grow: 0;
flex-shrink: 0;
margin-bottom: calc(var(--banana-carousel-gap, 0) * 1px);
}
.navigation-buttons {
Expand Down
13 changes: 13 additions & 0 deletions packages/banana/src/carousel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,19 @@ export default class BCarousel extends LitElement {
this.requestUpdate();
await this.updateComplete;
this.calcHeight();
this._calcLastSlideGap();
}

private _calcLastSlideGap() {
if (this._loop) {
this.vertical
? (this._slidesWithCopys[this._slidesWithCopys.length - 1].style.marginBottom = '0px')
: (this._slidesWithCopys[this._slidesWithCopys.length - 1].style.marginRight = '0px');
} else {
this.vertical
? (this._slides[this._slides.length - 1].style.marginBottom = '0px')
: (this._slides[this._slides.length - 1].style.marginRight = '0px');
}
}

render() {
Expand Down
4 changes: 4 additions & 0 deletions packages/banana/src/tooltip/index.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export default [
z-index: 100;
}
.tooltip__empty-content {
display: none;
}
.tooltip__content-body {
padding: var(--banana-tooltip-padding, ${unsafeCSS(Var.TooltipPadding)});
background-color: var(--banana-tooltip-background-color, ${unsafeCSS(Var.TooltipBackgroundColor)});
Expand Down
Loading

0 comments on commit 6a5db30

Please sign in to comment.