Skip to content

Commit

Permalink
Merge pull request #181 from chaxus/feat/token
Browse files Browse the repository at this point in the history
  • Loading branch information
chaxus authored Nov 2, 2023
2 parents 36bdd96 + 05f0f46 commit 62f046a
Show file tree
Hide file tree
Showing 12 changed files with 368 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .jscpd.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"threshold": 20,
"threshold": 5,
"reporters": ["html", "console"],
"ignore": [
"**/__snapshots__/**",
Expand Down
30 changes: 27 additions & 3 deletions packages/docs/src/ranui/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

## Feature 特点

1. 基于`Web Components`开发,跨框架复用,统一所有情况。
2. `TypeScript`开发,有声明和类型文件
1. 基于`Web Components`,跨框架复用,统一所有情况。
2. 基于`TypeScript`,具备声明和类型文件
3. 纯原生手写,基础组件无依赖。
4. 文档基于`vitepress`,所有组件实例可交互
4. 文档所有组件实例可交互
5. `MIT`协议。

## Situation 项目情况
Expand Down Expand Up @@ -312,6 +312,30 @@ import 'ranui';
</script>
```

## style 自定义样式

- `::part`伪类

```html
<r-input id="input"></r-input>

<style>
/* #input 指的是当前的自定义元素
::part(input) 中的input指的是,当前自定义元素内部的 Shadow DOM 元素的类 */
#input::part(input) {
width:100px
}
</style>
```

- 通过属性传入

会在所有的组件上加一个`sheet`属性,传入`CSSStyleSheet`字符串。会直接插入到`Shadow DOM`

- `CSS`自定义属性`var`

`CSS`自定义属性可以直接穿透到 `Shadow DOM`。但太定制化了。

## Compatibility 兼容性

- 不支持 `IE`,其他均有较好支持
Expand Down
7 changes: 6 additions & 1 deletion packages/ranui/assets/icons/add-user.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions packages/ranui/assets/icons/arrow-down.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
114 changes: 114 additions & 0 deletions packages/ranui/base.less
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
@font-family:-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji',
'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';

@box-shadow: 0 6px 16px 0 rgba(0, 0, 0, 0.08),
0 3px 6px -4px rgba(0, 0, 0, 0.12), 0 9px 28px 8px rgba(0, 0, 0, 0.05);

@keyframes MessageMoveIn {
0% {
padding: 0;
Expand All @@ -22,6 +29,7 @@
opacity: 0;
}
}

.ranui-message {
box-sizing: border-box;
margin: 0;
Expand Down Expand Up @@ -1011,3 +1019,109 @@
}
}
}

@keyframes ranui-select-dropdown-down-in {
0% {
transform: scaleY(0.8);
transform-origin: 100% 100%;
opacity: 0;
}

100% {
transform: scaleY(1);
transform-origin: 100% 100%;
opacity: 1;
}
}

@keyframes ranui-select-dropdown-down-out {
0% {
transform: scaleY(1);
transform-origin: 100% 100%;
opacity: 1;
}

100% {
transform: scaleY(0.8);
transform-origin: 100% 100%;
opacity: 0;
}
}

@keyframes ranui-select-dropdown-up-in {
0% {
transform: scaleY(0.8);
transform-origin: 0% 0%;
opacity: 0;
}

100% {
transform: scaleY(1);
transform-origin: 0% 0%;
opacity: 1;
}
}

@keyframes ranui-select-dropdown-up-out {
0% {
transform: scaleY(1);
transform-origin: 0% 0%;
opacity: 1;
}

100% {
transform: scaleY(0.8);
transform-origin: 0% 0%;
opacity: 0;
}
}

.ranui-select-dropdown {
width: 170px;
height: 30px;
margin: 0;
padding: 4px;
color: rgba(0, 0, 0, 0.88);
font-size: 14px;
line-height: 1.5714285714285714;
list-style: none;
font-family: @font-family;
position: absolute;
z-index: 1050;
overflow: hidden;
font-variant: initial;
background-color: #ffffff;
border-radius: 8px;
outline: none;
box-shadow: @box-shadow;
&-option-item {
position: relative;
display: block;
min-height: 32px;
padding: 5px 12px;
color: rgba(0, 0, 0, 0.88);
font-weight: normal;
font-size: 14px;
line-height: 1.5714285714285714;
box-sizing: border-box;
cursor: pointer;
transition: background 0.3s ease;
border-radius: 4px;
background-color: rgba(0, 0, 0, 0.04);
&-content {
flex: auto;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
color: rgba(0, 0, 0, 0.88);
font-weight: normal;
font-size: 14px;
line-height: 1.5714285714285714;
cursor: pointer;
box-sizing: border-box;
list-style: none;
font-family: @font-family;
font-variant: initial;
}
}
}
1 change: 0 additions & 1 deletion packages/ranui/components/icon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ function Custom() {
// vite 对动态导入的一些限制 https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#limitations
import(`../../assets/icons/${this.name}.svg`)
.then((result) => {
console.log('result---->', result);
if (result && result.default && result.default._identification) {
const { data } = result.default;
this._icon && this._div.removeChild(this._icon);
Expand Down
75 changes: 75 additions & 0 deletions packages/ranui/components/select/index.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
@font-family:-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji',
'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';

@transition:all 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);

@theme-color: #1890ff;

.select {
font-size: 14px;
height: 32px;
box-sizing: border-box;
margin: 0;
padding: 0;
color: rgba(0, 0, 0, 0.88);
font-size: 14px;
line-height: 1.5714285714285714;
list-style: none;
font-family: @font-family;
position: relative;
display: inline-block;
cursor: pointer;
.selection {
position: relative;
background-color: #ffffff;
border: 1px solid #d9d9d9;
transition: @transition;
width: 100%;
height: 100%;
padding: 0 11px;
box-sizing: border-box;
margin: 0;
color: rgba(0, 0, 0, 0.88);
font-size: 14px;
line-height: 1.5714285714285714;
list-style: none;
font-family: inherit;
display: flex;
border-radius: 6px;
&:hover {
border: 1px solid @theme-color;
}
.search {
opacity: 0;
margin: 0;
padding: 0;
background: transparent;
border: none;
outline: none;
appearance: none;
font-family: inherit;
height: 30px;
cursor: pointer;
}
.icon {
display: flex;
align-items: center;
color: rgba(0, 0, 0, 0.25);
font-style: normal;
text-align: center;
text-transform: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
position: absolute;
top: 50%;
inset-inline-start: auto;
inset-inline-end: 8px;
height: 12px;
margin-top: -3px;
font-size: 12px;
pointer-events: none;
}
}
}
115 changes: 115 additions & 0 deletions packages/ranui/components/select/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import { createCustomError, isDisabled } from '@/utils/index';
import '@/components/icon';

function Custom() {
if (typeof document !== 'undefined' && !customElements.get('r-select')) {
class Select extends HTMLElement {
_slot: HTMLSlotElement;
_shadowDom: ShadowRoot;
_select: HTMLDivElement;
_selection: HTMLDivElement;
_search: HTMLElement;
_icon: HTMLElement;
_selectDropdown?: HTMLDivElement;
static get observedAttributes() {
return ['disabled', 'sheet'];
}
constructor() {
super();
this._slot = document.createElement('slot');
this._select = document.createElement('div');
this._select.setAttribute('class', 'select');
this._selection = document.createElement('div');
this._selection.setAttribute('class', 'selection');
this._search = document.createElement('input');
this._search.setAttribute('class', 'search');
this._search.setAttribute('type', 'search');
this._search.setAttribute('autocomplete', 'off');
this._icon = document.createElement('r-icon');
this._icon.setAttribute('class', 'icon');
this._icon.setAttribute('name', 'arrow-down');
this._icon.setAttribute('color', '#d9d9d9');
this._icon.setAttribute('size', '16');
this._selection.appendChild(this._search);
this._selection.appendChild(this._icon);
this._slot.setAttribute('class', 'slot');
this._select.appendChild(this._selection);
this._select.appendChild(this._slot);
const shadowRoot = this.attachShadow({ mode: 'closed' });
this._shadowDom = shadowRoot;
shadowRoot.appendChild(this._select);
}
get sheet() {
return this.getAttribute('sheet');
}
set sheet(value) {
this.setAttribute('sheet', value || '');
}
get disabled() {
return isDisabled(this);
}
set disabled(value: boolean | string | undefined | null) {
if (!value || value === 'false') {
this.removeAttribute('disabled');
} else {
this.setAttribute('disabled', '');
}
}
handlerExternalCss() {
if (this.sheet) {
try {
const sheet = new CSSStyleSheet();
sheet.insertRule(this.sheet);
this._shadowDom.adoptedStyleSheets = [sheet];
} catch (error) {
console.error(
`Failed to parse the rule in CSSStyleSheet: ${this.sheet}`,
);
}
}
}
createOption = () => {
if (!this._selectDropdown) {
this._selectDropdown = document.createElement('div');
}
const selectDropdown = document.createElement('div')
selectDropdown.setAttribute('class','ranui-select-dropdown')
const selectOptionItem = document.createElement('div')
selectOptionItem.setAttribute('class','ranui-select-dropdown-option-item')
const selectOptionItemContent = document.createElement('div')
selectOptionItemContent.setAttribute('class','ranui-select-dropdown-option-item-content')
selectOptionItemContent.innerText = 'Mike'
selectOptionItem.appendChild(selectOptionItemContent)
selectDropdown.appendChild(selectOptionItem)
this._selectDropdown.appendChild(selectDropdown)
document.body.appendChild(this._selectDropdown);
};
connectedCallback() {
this.handlerExternalCss();
this.createOption()
}
disconnectCallback() {}
attributeChangedCallback(
name: string,
oldValue: string,
newValue: string,
) {
if (name === 'disabled' && this._select) {
if (!newValue || newValue === 'false') {
this._select.setAttribute('disabled', '');
} else {
this._select.removeAttribute('disabled');
}
}
if (name === 'sheet' && this._shadowDom && oldValue !== newValue)
this.handlerExternalCss();
}
}
customElements.define('r-select', Select);
return Select;
} else {
return createCustomError('document is undefined or r-select is exist');
}
}

export default Custom();
Loading

0 comments on commit 62f046a

Please sign in to comment.