Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: styles package #1074

Merged
merged 1 commit into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/styles/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
webpack.config.js
4 changes: 4 additions & 0 deletions packages/styles/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": ["../../node_modules/@standardnotes/config/src/.eslintrc"],
"ignorePatterns": [".eslintrc.js", "webpack.config.js"]
}
1 change: 1 addition & 0 deletions packages/styles/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
3 changes: 3 additions & 0 deletions packages/styles/linter.tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../node_modules/@standardnotes/config/src/linter.tsconfig.json"
}
24 changes: 24 additions & 0 deletions packages/styles/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "@standardnotes/styles",
"version": "1.0.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"publishConfig": {
"access": "public"
},
"scripts": {
"build": "webpack --mode='production' && yarn run tsc",
"start": "webpack --watch --mode='development'",
"lint": "prettier --check *.js"
},
"dependencies": {},
"devDependencies": {
"css-loader": "~6.6.0",
"mini-css-extract-plugin": "^2.5.3",
"node-sass": "^7.0.1",
"sass-loader": "^12.6.0",
"style-loader": "~3.3.1",
"webpack": "^5.69.1",
"webpack-cli": "^4.9.2"
}
}
127 changes: 127 additions & 0 deletions packages/styles/src/Alert/Alert.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
type AlertButtonStyle = 'small' | 'outlined' | 'contrast' | 'neutral' | 'info' | 'warning' | 'danger' | 'success'

type AlertButton = {
text: string
style: AlertButtonStyle
action: () => void
primary?: boolean
}

export class SKAlert {
private title?: string
private text: string
private buttons: AlertButton[]
private element!: HTMLDivElement
private onElement!: HTMLElement

constructor({ title, text, buttons }: { title?: string; text: string; buttons?: AlertButton[] }) {
this.title = title
this.text = text
this.buttons = buttons || []
}

buttonsString() {
const genButton = function (buttonDesc: AlertButton, index: number) {
return `
<button id='button-${index}' class='sn-button small ${buttonDesc.style}'>
<div class='sk-label'>${buttonDesc.text}</div>
</button>
`
}

const buttonString = this.buttons
.map(function (buttonDesc, index) {
return genButton(buttonDesc, index)
})
.join('')

const str = `
<div class='sk-button-group'>
${buttonString}
</div>
`
return str
}

templateString() {
let buttonsTemplate: string
let panelStyle: string
if (this.buttons) {
buttonsTemplate = `
<div class="sk-panel-row" style='margin-top: 8px;'>
${this.buttonsString()}
</div>
`
panelStyle = ''
} else {
buttonsTemplate = ''
panelStyle = 'style="padding-bottom: 8px"'
}
const titleTemplate = this.title ? `<div class='sk-h3 sk-panel-section-title'>${this.title}</div>` : ''
const messageTemplate = this.text ? `<p class='sk-p'>${this.text}</p>` : ''

const template = `
<div class="sk-modal">
<div class="sk-modal-background"></div>
<div class="sk-modal-content">
<div class="sn-component">
<div class="sk-panel" style='max-width: 500px;'>
<div class="sk-panel-content" ${panelStyle}>
<div class="sk-panel-section">
${titleTemplate}

<div class="sk-panel-row">
${messageTemplate}
</div>

${buttonsTemplate}
</div>
</div>
</div>
</div>
</div>
</div>
`

return template
}

dismiss() {
this.onElement.removeChild(this.element)
}

primaryButton() {
let primary = this.buttons.find((button) => button.primary === true)
if (!primary) {
primary = this.buttons[this.buttons.length - 1]
}
return primary
}

present(onElement?: HTMLElement) {
if (!onElement) {
onElement = document.body
}

this.onElement = onElement

this.element = document.createElement('div')
this.element.className = 'sn-component'
this.element.innerHTML = this.templateString().trim()

onElement.appendChild(this.element)

if (this.buttons && this.buttons.length) {
this.buttons.forEach((buttonDesc, index) => {
const buttonElem = this.element.querySelector(`#button-${index}`) as HTMLButtonElement
buttonElem.onclick = () => {
buttonDesc.action && buttonDesc.action()
this.dismiss()
}
if (index === 0) {
buttonElem.focus()
}
})
}
}
}
90 changes: 90 additions & 0 deletions packages/styles/src/Styles/_app-bar.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
.sk-app-bar {
display: flex;
width: 100%;
height: 1.625rem;
padding: 0 0.65rem;
background-color: var(--sn-stylekit-contrast-background-color);
color: var(--sn-stylekit-contrast-foreground-color);
justify-content: space-between;
align-items: center;
border: 1px solid var(--sn-stylekit-contrast-border-color);
user-select: none;

&.no-edges {
border-left: 0;
border-right: 0;
}

&.no-bottom-edge {
border-bottom: 0;
}

.left,
.right {
display: flex;
height: 100%;
}

.sk-app-bar-item {
flex-grow: 1;
&:not(:first-child) {
margin-left: 0.8125rem;
}

&.border {
border-left: 1px solid var(--sn-stylekit-contrast-border-color);
}

> .sk-app-bar-item-column {
height: 100%;
display: flex;
align-items: center;

&:not(:first-child) {
margin-left: 0.40625rem;
}
&.underline {
border-bottom: 2px solid var(--sn-stylekit-info-color);
}
}

cursor: pointer;
display: flex;
align-items: center;
justify-content: center;

&.no-pointer {
cursor: default;
}

&:hover {
> .sk-label,
> .sk-sublabel,
> .sk-app-bar-item-column > .sk-label,
> .sk-app-bar-item-column > .sk-sublabel {
&:not(.subtle) {
color: var(--sn-stylekit-info-color);
}
}
}

> .sk-label,
> .sk-app-bar-item-column > .sk-label {
font-weight: bold;
font-size: var(--sn-stylekit-font-size-h5);
white-space: nowrap;
}

> .sk-sublabel,
> .sk-app-bar-item-column > .sk-sublabel {
font-size: var(--sn-stylekit-font-size-h5);
font-weight: normal;
white-space: nowrap;
}

.subtle {
font-weight: normal;
opacity: 0.6;
}
}
}
96 changes: 96 additions & 0 deletions packages/styles/src/Styles/_menu-panel.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
.sk-menu-panel {
// box-shadow: 0px 4px 4px var(--sn-stylekit-shadow-color);
background-color: var(--sn-stylekit-background-color);
border: 1px solid var(--sn-stylekit-contrast-border-color);
border-radius: var(--sn-stylekit-general-border-radius);
overflow: scroll;
user-select: none;

// For Windows to hide needless scrollbars
overflow-y: auto !important;
overflow-x: auto !important;

.sk-menu-panel-header {
padding: 0.65rem 0.8125rem;
border-bottom: 1px solid var(--sn-stylekit-contrast-border-color);
background-color: var(--sn-stylekit-contrast-background-color);
color: var(--sn-stylekit-contrast-foreground-color);
display: flex;
justify-content: space-between;
align-items: center;
}

.sk-menu-panel-header-title {
font-weight: bold;
font-size: var(--sn-stylekit-font-size-h4);
}

.sk-menu-panel-header-subtitle {
margin-top: 0.1625rem;
opacity: 0.6;
}

.sk-menu-panel-row {
padding: 0.8125rem 0.8125rem;
cursor: pointer;
display: flex;
flex-direction: row;
justify-content: space-between;
border-bottom: 1px solid var(--sn-stylekit-border-color);

&:hover {
background-color: var(--sn-stylekit-contrast-background-color);
color: var(--sn-stylekit-contrast-foreground-color);
border-color: var(--sn-stylekit-contrast-border-color);
}

.sk-menu-panel-column {
display: flex;
justify-content: center;
flex-direction: column;

&:not(:first-child) {
padding-left: 1rem;
padding-right: 0.121875rem;
}

&.stretch {
width: 100%;
}

.sk-menu-panel-subrows {
margin-top: 0.8125rem;
}

/* Nested row */
.sk-menu-panel-row,
.sk-menu-panel-subrow {
border: 1px solid var(--sn-stylekit-contrast-border-color);
margin-top: -1px;
&:hover {
background-color: var(--sn-stylekit-background-color);
}
}

.left {
display: flex;
}
}

.sk-button .sk-label {
font-size: var(--sn-stylekit-font-size-h6);
font-weight: normal;
}

.sk-label {
font-size: var(--sn-stylekit-font-size-p);
font-weight: bold;
}

.sk-sublabel {
font-size: var(--sn-stylekit-font-size-h5);
margin-top: 0.1625rem;
opacity: 0.6;
}
}
}
Loading