|
| 1 | +import { ColorScheme, NoteShadow } from '@blocksuite/affine-model'; |
| 2 | +import { |
| 3 | + ArrowDownSmallIcon, |
| 4 | + NoteShadowDuotoneIcon, |
| 5 | +} from '@blocksuite/icons/lit'; |
| 6 | +import { css, html, LitElement } from 'lit'; |
| 7 | +import { property } from 'lit/decorators.js'; |
| 8 | +import { repeat } from 'lit/directives/repeat.js'; |
| 9 | +import { styleMap } from 'lit/directives/style-map.js'; |
| 10 | + |
| 11 | +import { NoteNoShadowIcon, NoteShadowSampleIcon } from './icons'; |
| 12 | + |
| 13 | +const SHADOWS = [ |
| 14 | + { |
| 15 | + type: NoteShadow.None, |
| 16 | + styles: { |
| 17 | + light: '', |
| 18 | + dark: '', |
| 19 | + }, |
| 20 | + tooltip: 'No shadow', |
| 21 | + }, |
| 22 | + { |
| 23 | + type: NoteShadow.Box, |
| 24 | + styles: { |
| 25 | + light: |
| 26 | + '0px 0.2px 4.8px 0px rgba(66, 65, 73, 0.2), 0px 0px 1.6px 0px rgba(66, 65, 73, 0.2)', |
| 27 | + dark: '0px 0.2px 6px 0px rgba(0, 0, 0, 0.44), 0px 0px 2px 0px rgba(0, 0, 0, 0.66)', |
| 28 | + }, |
| 29 | + tooltip: 'Box shadow', |
| 30 | + }, |
| 31 | + { |
| 32 | + type: NoteShadow.Sticker, |
| 33 | + styles: { |
| 34 | + light: |
| 35 | + '0px 9.6px 10.4px -4px rgba(66, 65, 73, 0.07), 0px 10.4px 7.2px -8px rgba(66, 65, 73, 0.22)', |
| 36 | + dark: '0px 9.6px 10.4px -4px rgba(0, 0, 0, 0.66), 0px 10.4px 7.2px -8px rgba(0, 0, 0, 0.44)', |
| 37 | + }, |
| 38 | + tooltip: 'Sticker shadow', |
| 39 | + }, |
| 40 | + { |
| 41 | + type: NoteShadow.Paper, |
| 42 | + styles: { |
| 43 | + light: |
| 44 | + '0px 0px 0px 4px rgba(255, 255, 255, 1), 0px 1.2px 2.4px 4.8px rgba(66, 65, 73, 0.16)', |
| 45 | + dark: '0px 1.2px 2.4px 4.8px rgba(0, 0, 0, 0.36), 0px 0px 0px 3.4px rgba(75, 75, 75, 1)', |
| 46 | + }, |
| 47 | + tooltip: 'Paper shadow', |
| 48 | + }, |
| 49 | + { |
| 50 | + type: NoteShadow.Float, |
| 51 | + styles: { |
| 52 | + light: |
| 53 | + '0px 5.2px 12px 0px rgba(66, 65, 73, 0.13), 0px 0px 0.4px 1px rgba(0, 0, 0, 0.06)', |
| 54 | + dark: '0px 5.2px 12px 0px rgba(0, 0, 0, 0.66), 0px 0px 0.4px 1px rgba(0, 0, 0, 0.44)', |
| 55 | + }, |
| 56 | + tooltip: 'Floation shadow', |
| 57 | + }, |
| 58 | + { |
| 59 | + type: NoteShadow.Film, |
| 60 | + styles: { |
| 61 | + light: |
| 62 | + '0px 0px 0px 1.4px rgba(0, 0, 0, 1), 2.4px 2.4px 0px 1px rgba(0, 0, 0, 1)', |
| 63 | + dark: '0px 0px 0px 1.4px rgba(178, 178, 178, 1), 2.4px 2.4px 0px 1px rgba(178, 178, 178, 1)', |
| 64 | + }, |
| 65 | + tooltip: 'Film shadow', |
| 66 | + }, |
| 67 | +]; |
| 68 | + |
| 69 | +export class EdgelessNoteShadowDropdownMenu extends LitElement { |
| 70 | + static override styles = css` |
| 71 | + :host { |
| 72 | + display: flex; |
| 73 | + align-items: center; |
| 74 | + justify-content: space-between; |
| 75 | + gap: 8px; |
| 76 | + } |
| 77 | +
|
| 78 | + .item { |
| 79 | + padding: 8px; |
| 80 | + border-radius: 4px; |
| 81 | + display: flex; |
| 82 | + justify-content: center; |
| 83 | + align-items: center; |
| 84 | + cursor: pointer; |
| 85 | + } |
| 86 | +
|
| 87 | + .item-icon { |
| 88 | + display: flex; |
| 89 | + justify-content: center; |
| 90 | + align-items: center; |
| 91 | + } |
| 92 | +
|
| 93 | + .item-icon svg rect:first-of-type { |
| 94 | + fill: var(--background); |
| 95 | + } |
| 96 | +
|
| 97 | + .item:hover { |
| 98 | + background-color: var(--affine-hover-color); |
| 99 | + } |
| 100 | +
|
| 101 | + .item[data-selected] { |
| 102 | + border: 1px solid var(--affine-brand-color); |
| 103 | + } |
| 104 | + `; |
| 105 | + |
| 106 | + select(value: NoteShadow) { |
| 107 | + this.dispatchEvent(new CustomEvent('select', { detail: value })); |
| 108 | + } |
| 109 | + |
| 110 | + override render() { |
| 111 | + const { value, background, theme } = this; |
| 112 | + const isDark = theme === ColorScheme.Dark; |
| 113 | + |
| 114 | + return html` |
| 115 | + <editor-menu-button |
| 116 | + .contentPadding="${'8px'}" |
| 117 | + .button=${html` |
| 118 | + <editor-icon-button |
| 119 | + aria-label="Shadow style" |
| 120 | + .tooltip="${'Shadow style'}" |
| 121 | + > |
| 122 | + ${NoteShadowDuotoneIcon()} ${ArrowDownSmallIcon()} |
| 123 | + </editor-icon-button> |
| 124 | + `} |
| 125 | + > |
| 126 | + <div |
| 127 | + data-orientation="horizontal" |
| 128 | + style=${styleMap({ |
| 129 | + '--background': background.startsWith('--') |
| 130 | + ? `var(${background})` |
| 131 | + : background, |
| 132 | + })} |
| 133 | + > |
| 134 | + ${repeat( |
| 135 | + SHADOWS, |
| 136 | + shadow => shadow.type, |
| 137 | + ({ type, tooltip, styles: { dark, light } }, index) => |
| 138 | + html`<div |
| 139 | + class="item" |
| 140 | + ?data-selected="${value === type}" |
| 141 | + @click=${() => this.select(type)} |
| 142 | + > |
| 143 | + <editor-icon-button |
| 144 | + class="item-icon" |
| 145 | + data-testid="${type.replace('--', '')}" |
| 146 | + .tooltip=${tooltip} |
| 147 | + .tipPosition="${'bottom'}" |
| 148 | + .iconContainerPadding=${0} |
| 149 | + .hover=${false} |
| 150 | + style=${styleMap({ |
| 151 | + boxShadow: `${isDark ? dark : light}`, |
| 152 | + })} |
| 153 | + > |
| 154 | + ${index === 0 ? NoteNoShadowIcon : NoteShadowSampleIcon} |
| 155 | + </editor-icon-button> |
| 156 | + </div>` |
| 157 | + )} |
| 158 | + </div> |
| 159 | + </editor-menu-button> |
| 160 | + `; |
| 161 | + } |
| 162 | + |
| 163 | + @property({ attribute: false }) |
| 164 | + accessor background!: string; |
| 165 | + |
| 166 | + @property({ attribute: false }) |
| 167 | + accessor theme!: ColorScheme; |
| 168 | + |
| 169 | + @property({ attribute: false }) |
| 170 | + accessor value!: NoteShadow; |
| 171 | +} |
| 172 | + |
| 173 | +declare global { |
| 174 | + interface HTMLElementTagNameMap { |
| 175 | + 'edgeless-note-shadow-dropdown-menu': EdgelessNoteShadowDropdownMenu; |
| 176 | + } |
| 177 | +} |
0 commit comments