Skip to content

Commit

Permalink
finished temple-ui. first pass through
Browse files Browse the repository at this point in the history
  • Loading branch information
cblanquera committed Sep 26, 2024
1 parent f3b8c00 commit 68ca241
Show file tree
Hide file tree
Showing 28 changed files with 2,383 additions and 237 deletions.
1 change: 1 addition & 0 deletions packages/temple-ui-src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"inputmask": "5.0.9",
"marked": "14.1.2",
"prismjs": "1.29.0",
"suneditor": "2.47.0",
"typescript": "5.5.4"
}
}
8 changes: 7 additions & 1 deletion packages/temple-ui-src/package.live.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@
"repository": "OSSPhilippines/temple",
"main": "index.js",
"dependencies": {
"@editorjs/editorjs": "2.30.6",
"@editorjs/header": "2.8.7",
"@editorjs/image": "2.9.3",
"@editorjs/list": "1.10.0",
"@editorjs/paragraph": "2.11.6",
"@ossph/temple": "0.1.6",
"codemirror": "5.65.17",
"dayjs": "1.11.13",
"dompurify": "3.1.6",
"inputmask": "5.0.9",
"marked": "14.1.2",
"prismjs": "1.29.0"
"prismjs": "1.29.0",
"suneditor": "2.47.0"
},
"devDependencies": {
"@types/dompurify": "3.0.5",
Expand Down
61 changes: 48 additions & 13 deletions packages/temple-ui-src/src/field/color.tml
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
<link rel="import" type="component" href="./input.tml" name="field-input" />
<style>
:host {
background-color: var(--white);
border: 1px solid var(--border);
}
div {
align-items: stretch;
display: flex;
}
div span:last-child {
flex: 1;
padding: 7px 7px 8px 0;
}
input {
background-color: transparent;
border: 0;
box-sizing: border-box;
font-size: inherit;
font-family: inherit;
height: 100%;
}
::slotted(input) {
background-color: transparent;
border: 0;
box-sizing: border-box;
font-size: inherit;
font-family: inherit;
width: 100%;
}
::slotted(input:focus) {
outline: none;
}
</style>
<script observe="autocomplete,disabled,name,readonly,required,value">
import StyleSet from '@ossph/temple/dist/style/StyleSet';
Expand All @@ -17,42 +47,47 @@
this.styles = () => css + styles.toString();
//determine display
setDisplay(this.props, styles, 'inline-block', ':host');
styles.add('div', 'display', 'flex');
styles.add('div', 'align-items', 'stretch');
styles.add('input', 'height', '100%');
//handlers
const handlers = {
change: e => {
const box = e.target;
const input = this.querySelector('*');
if (!input) return;
input.setAttribute('value', box.value);
const input1 = this.querySelector('input');
const input2 = this.shadowRoot?.querySelector('input');
console.log('change', box.value, input1, input2);
if (!input1 || !input2) return;
input1.value = box.value;
input1.setAttribute('value', box.value);
input2.value = box.value;
input2.setAttribute('value', box.value);
},
attribute: e => {
//accepts: error,accept,autocomplete,checked,disabled,max,min,
// multiple,name,pattern,readonly,required,step,value
const { action, name, prev, value, target } = e.detail;
const input = this.querySelector('*');
if (!input) return;
const input1 = this.querySelector('input');
const input2 = this.shadowRoot?.querySelector('input');
if (!input1 || !input2) return;
switch (action) {
case 'add':
case 'update':
input.setAttribute(name, value);
input1.setAttribute(name, value);
input2.setAttribute(name, value);
break;
case 'remove':
input.removeAttribute(name);
input1.removeAttribute(name);
input2.removeAttribute(name);
break;
}
}
};
this.on('attributechange', handlers.attribute);
</script>
<template type="light">
<field-input {...attributes} />
<input {...attributes} change={handlers.change} />
</template>
<template type="shadow">
<div>
<span><input type="color" change={handlers.change} /></span>
<slot></slot>
<span><slot></slot></span>
</div>
</template>
162 changes: 151 additions & 11 deletions packages/temple-ui-src/src/field/country.tml
Original file line number Diff line number Diff line change
@@ -1,13 +1,153 @@
<link rel="import" type="component" href="./select.tml" name="field-select" />
<link rel="import" type="component" href="../format/country.tml" name="format-country" />
<script>
<style>
.select {
color: var(--black);
position: relative;
}
.display {
display: flex;
align-items: center;
padding: 7px;
border: 1px solid var(--black);
background-color: var(--white);
}
.selected {
width: 100%;
overflow: auto;
display: flex;
align-items: center;
flex-grow: 1;
gap: 5px;
cursor: pointer;
white-space: nowrap;
}
.placeholder {
color: var(--muted);
font-style: italic;
}
.count {
display: inline-block;
padding-left: 4px;
color: var(--muted);
font-size: 12px;
}
.clear, .toggle, .add {
cursor: pointer;
}
.dropdown {
background-color: var(--white);
border: 1px solid var(--black);
overflow: auto;
position: absolute;
width: 100%;
max-height: 200px;
}
.form {
display: flex;
align-items: center;
margin: 5px;
padding: 7px;
border: 1px solid var(--muted);
height: 18px;
}
.input {
flex-grow: 1;
padding: 0;
border: 0;
background-color: transparent;
}
.input:focus {
outline: none;
}
.search {
color: var(--muted);
}
.options {
overflow: auto;
cursor: pointer;
}
.option {
align-items: center;
display: flex;
padding: 7px;
}
.option img {
height: 16px;
margin-right: 5px;
}
.option:hover {
background-color: var(--muted);
}
.selected .option {
padding: 0;
}
.selected .option:hover {
background-color: transparent;
}
</style>
<script observe="name,value">
import intl from '../utilities/intl.json';
const { select = '', custom, multiple, ...attributes } = this.props;
import { getHandlers } from '../utilities/select';
//extract props
const { name, placeholder = 'Select Country' } = this.props;
const options = intl.map(country => {
const flag = this.createElement('img', {
loading: 'lazy',
src: `https://flagcdn.com/w80/${country.countryCode.toLowerCase()}.png`
});
const label = this.createElement('span', {}, [
new Text(country.countryName)
]);
return this.createElement('div', {
'class': 'option',
keyword: `${country.countryCode} ${country.countryName}`,
value: country.countryCode
}, [ flag, label ]).element;
});
//get handlers
const { state, clear, toggle, filter, add } = getHandlers(this, options, false);
</script>
<field-select {...attributes} class=select search>
<each value=country from=intl>
<option value={country.countryCode} keyword={`${country.countryCode} ${country.countryName}`}>
<format-country sm value={country.countryCode} />
</option>
</each>
</field-select>
<template type="light">
<if true={name}>
<each value=value from={state.value.values}>
<input type="hidden" {name} value={value.toString()} />
</each>
</if>
</template>
<template type="shadow">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css" />
<div class="select">
<div class="display">
<div class="selected" click={toggle}>
<if true={state.value.selected.length > 0}>
{state.value.selected}
<elif true={placeholder} />
<span class="placeholder">
{placeholder}
</span>
</if>
</div>
<if true={state.value.selected.length > 1}>
<em class="count">({state.value.selected.length})</em>
</if>
<if true={state.value.selected.length > 0}>
<i class="clear fas fa-fw fa-times" click={clear}></i>
</if>
<if true={state.value.filtered.length > 0 || state.value.query.length > 0}>
<if true={state.value.show}>
<i class="toggle fas fa-fw fa-caret-up" click={toggle}></i>
<else />
<i class="toggle fas fa-fw fa-caret-down" click={toggle}></i>
</if>
</if>
</div>
<if true={state.value.show && (state.value.filtered.length > 0 || state.value.query.length > 0)}>
<div class="dropdown">
<div class="form">
<input class="input" value={state.value.query} keyup={filter} />
<i class="search fas fa-fe fa-search"></i>
</div>
<div class="options">{state.value.filtered}</div>
</div>
</if>
</div>
</template>
Loading

0 comments on commit 68ca241

Please sign in to comment.