-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #181 from chaxus/feat/token
- Loading branch information
Showing
12 changed files
with
368 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"threshold": 20, | ||
"threshold": 5, | ||
"reporters": ["html", "console"], | ||
"ignore": [ | ||
"**/__snapshots__/**", | ||
|
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,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; | ||
} | ||
} | ||
} |
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,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(); |
Oops, something went wrong.