-
Notifications
You must be signed in to change notification settings - Fork 3
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
1 parent
fb0a79f
commit 28f420a
Showing
9 changed files
with
137 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
64 changes: 64 additions & 0 deletions
64
packages/design-system/src/elements/toniq-progress/toniq-progress.element.book.ts
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,64 @@ | ||
import {defineBookPage} from 'element-book'; | ||
import {CSSResult, css, html} from 'element-vir'; | ||
import {elementsBookPage} from '../../element-book/book-pages/elements.book'; | ||
import {ToniqProgress} from './toniq-progress.element'; | ||
|
||
export const toniqProgressBookPage = defineBookPage({ | ||
title: ToniqProgress.tagName, | ||
parent: elementsBookPage, | ||
elementExamplesCallback({defineExample}) { | ||
const examples: ReadonlyArray< | ||
Readonly< | ||
{ | ||
title: string; | ||
styles?: CSSResult; | ||
} & typeof ToniqProgress.inputsType | ||
> | ||
> = [ | ||
{ | ||
title: 'halfway', | ||
percent: 50, | ||
}, | ||
{ | ||
title: 'nothing', | ||
percent: 0, | ||
}, | ||
{ | ||
title: 'complete', | ||
percent: 100, | ||
}, | ||
{ | ||
title: 'custom height', | ||
styles: css` | ||
${ToniqProgress} { | ||
height: 32px; | ||
} | ||
:`, | ||
percent: 75, | ||
}, | ||
{ | ||
title: 'custom width', | ||
styles: css` | ||
${ToniqProgress} { | ||
width: 200%; | ||
} | ||
:`, | ||
percent: 75, | ||
}, | ||
]; | ||
|
||
examples.forEach((example) => { | ||
defineExample({ | ||
title: example.title, | ||
styles: example.styles, | ||
renderCallback() { | ||
return html` | ||
<${ToniqProgress.assign({ | ||
percent: example.percent, | ||
})}></${ToniqProgress}> | ||
`; | ||
}, | ||
}); | ||
}); | ||
}, | ||
}); |
61 changes: 61 additions & 0 deletions
61
packages/design-system/src/elements/toniq-progress/toniq-progress.element.ts
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,61 @@ | ||
import {clamp} from '@augment-vir/common'; | ||
import {css, html, nothing} from 'element-vir'; | ||
import {setCssVarValue} from 'lit-css-vars'; | ||
import {toniqColors} from '../../styles/colors'; | ||
import {defineToniqElement} from '../define-toniq-element'; | ||
|
||
export const ToniqProgress = defineToniqElement<{ | ||
/** | ||
* From 0-100 inclusive. Any values outside of that range will be clamped. Fractional values are | ||
* accepted. | ||
*/ | ||
percent: number; | ||
}>()({ | ||
tagName: 'toniq-progress', | ||
cssVars: { | ||
'toniq-progress-width': '0%', | ||
}, | ||
styles: ({cssVars}) => css` | ||
:host { | ||
position: relative; | ||
width: 100%; | ||
display: inline-block; | ||
background: ${toniqColors.accentSecondary.backgroundColor}; | ||
height: 8px; | ||
border-radius: 16px; | ||
overflow: hidden; | ||
} | ||
.progress { | ||
position: absolute; | ||
height: inherit; | ||
border-radius: inherit; | ||
left: 0; | ||
top: 0; | ||
width: ${cssVars['toniq-progress-width'].value}; | ||
background: ${toniqColors.pageInteraction.foregroundColor}; | ||
} | ||
`, | ||
renderCallback({inputs, cssVars, host}) { | ||
const clampedPercent = clamp({ | ||
value: inputs.percent, | ||
max: 100, | ||
min: 0, | ||
}); | ||
const progressPercentString = `${clampedPercent}%`; | ||
setCssVarValue({ | ||
forCssVar: cssVars['toniq-progress-width'], | ||
onElement: host, | ||
toValue: progressPercentString, | ||
}); | ||
|
||
host.setAttribute('title', `${progressPercentString} finished`); | ||
|
||
if (clampedPercent) { | ||
return html` | ||
<div class="progress"></div> | ||
`; | ||
} else { | ||
return nothing; | ||
} | ||
}, | ||
}); |
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