mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	chore(react/ribbon): add basic note types & badges
This commit is contained in:
		| @@ -65,19 +65,9 @@ export default class NoteTypeWidget extends NoteContextAwareWidget { | |||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         for (const noteType of NOTE_TYPES.filter((nt) => !nt.reserved && !nt.static)) { |         for (const noteType of ) { | ||||||
|             let $typeLink: JQuery<HTMLElement>; |             let $typeLink: JQuery<HTMLElement>; | ||||||
|  |  | ||||||
|             const $title = $("<span>").text(noteType.title); |  | ||||||
|  |  | ||||||
|             if (noteType.isNew) { |  | ||||||
|                 $title.append($(`<span class="badge new-note-type-badge">`).text(t("note_types.new-feature"))); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             if (noteType.isBeta) { |  | ||||||
|                 $title.append($(`<span class="badge">`).text(t("note_types.beta-feature"))); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             if (noteType.type !== "code") { |             if (noteType.type !== "code") { | ||||||
|                 $typeLink = $('<a class="dropdown-item">') |                 $typeLink = $('<a class="dropdown-item">') | ||||||
|                     .attr("data-note-type", noteType.type) |                     .attr("data-note-type", noteType.type) | ||||||
|   | |||||||
| @@ -63,15 +63,21 @@ export default function FormList({ children, onSelect, style, fullHeight }: Form | |||||||
|     ); |     ); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | export interface FormListBadge { | ||||||
|  |     className?: string; | ||||||
|  |     text: string; | ||||||
|  | } | ||||||
|  |  | ||||||
| interface FormListItemOpts { | interface FormListItemOpts { | ||||||
|     children: ComponentChildren; |     children: ComponentChildren; | ||||||
|     icon?: string; |     icon?: string; | ||||||
|     value?: string; |     value?: string; | ||||||
|     title?: string; |     title?: string; | ||||||
|     active?: boolean; |     active?: boolean; | ||||||
|  |     badges?: FormListBadge[]; | ||||||
| } | } | ||||||
|  |  | ||||||
| export function FormListItem({ children, icon, value, title, active }: FormListItemOpts) { | export function FormListItem({ children, icon, value, title, active, badges }: FormListItemOpts) { | ||||||
|     return ( |     return ( | ||||||
|         <a |         <a | ||||||
|             class={`dropdown-item ${active ? "active" : ""}`} |             class={`dropdown-item ${active ? "active" : ""}`} | ||||||
| @@ -80,6 +86,9 @@ export function FormListItem({ children, icon, value, title, active }: FormListI | |||||||
|         > |         > | ||||||
|             <Icon icon={icon} />  |             <Icon icon={icon} />  | ||||||
|             {children} |             {children} | ||||||
|  |             {badges && badges.map(({ className, text }) => ( | ||||||
|  |                 <span className={`badge ${className ?? ""}`}>{text}</span> | ||||||
|  |             ))} | ||||||
|         </a> |         </a> | ||||||
|     ); |     ); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,3 +1,42 @@ | |||||||
|  | import { useCallback, useMemo } from "preact/hooks"; | ||||||
|  | import Dropdown from "../react/Dropdown"; | ||||||
|  | import { NOTE_TYPES } from "../../services/note_types"; | ||||||
|  | import { FormListBadge, FormListItem } from "../react/FormList"; | ||||||
|  | import { t } from "../../services/i18n"; | ||||||
|  |  | ||||||
| export default function BasicPropertiesTab() { | export default function BasicPropertiesTab() { | ||||||
|     return <p>Hi</p>; |     return ( | ||||||
|  |         <div className="basic-properties-widget"> | ||||||
|  |             <NoteTypeWidget /> | ||||||
|  |         </div> | ||||||
|  |     ); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function NoteTypeWidget() { | ||||||
|  |     const noteTypes = useMemo(() => NOTE_TYPES.filter((nt) => !nt.reserved && !nt.static), []); | ||||||
|  |  | ||||||
|  |     return ( | ||||||
|  |         <Dropdown> | ||||||
|  |             {noteTypes.map(noteType => { | ||||||
|  |                 const badges: FormListBadge[] = []; | ||||||
|  |                 if (noteType.isNew) { | ||||||
|  |                     badges.push({ | ||||||
|  |                         className: "new-note-type-badge", | ||||||
|  |                         text: t("note_types.new-feature") | ||||||
|  |                     }); | ||||||
|  |                 } | ||||||
|  |                 if (noteType.isBeta) { | ||||||
|  |                     badges.push({ | ||||||
|  |                         text: t("note_types.beta-feature") | ||||||
|  |                     }); | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 return ( | ||||||
|  |                     <FormListItem | ||||||
|  |                         badges={badges} | ||||||
|  |                     >{noteType.title}</FormListItem>     | ||||||
|  |                 ); | ||||||
|  |             })} | ||||||
|  |         </Dropdown> | ||||||
|  |     )    | ||||||
| } | } | ||||||
| @@ -101,7 +101,7 @@ const TAB_CONFIGURATION: TabConfiguration[] = [ | |||||||
| export default function Ribbon() { | export default function Ribbon() { | ||||||
|     const { note } = useNoteContext(); |     const { note } = useNoteContext(); | ||||||
|     const context: TabContext = { note }; |     const context: TabContext = { note }; | ||||||
|     const [ activeTab, setActiveTab ] = useState<number>(); |     const [ activeTab, setActiveTab ] = useState<number | undefined>(8); | ||||||
|     const activeTabConfiguration = activeTab ? TAB_CONFIGURATION[activeTab] : undefined; |     const activeTabConfiguration = activeTab ? TAB_CONFIGURATION[activeTab] : undefined; | ||||||
|  |  | ||||||
|     return ( |     return ( | ||||||
|   | |||||||
| @@ -92,3 +92,26 @@ | |||||||
| .ribbon-tab-title.active .ribbon-tab-title-label { | .ribbon-tab-title.active .ribbon-tab-title-label { | ||||||
|     display: inline; |     display: inline; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | .basic-properties-widget { | ||||||
|  |     padding: 0px 12px 6px 12px; | ||||||
|  |     display: flex; | ||||||
|  |     align-items: baseline; | ||||||
|  |     flex-wrap: wrap; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .basic-properties-widget > * { | ||||||
|  |     margin-top: 9px; | ||||||
|  |     margin-bottom: 2px; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .basic-properties-widget > * > :last-child { | ||||||
|  |     margin-right: 30px; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .note-type-container, | ||||||
|  | .editability-select-container, | ||||||
|  | .note-language-container { | ||||||
|  |     display: flex; | ||||||
|  |     align-items: center; | ||||||
|  | } | ||||||
| @@ -10,32 +10,6 @@ import type FNote from "../../entities/fnote.js"; | |||||||
| import NoteLanguageWidget from "../note_language.js"; | import NoteLanguageWidget from "../note_language.js"; | ||||||
|  |  | ||||||
| const TPL = /*html*/` | const TPL = /*html*/` | ||||||
| <div class="basic-properties-widget"> |  | ||||||
|     <style> |  | ||||||
|         .basic-properties-widget { |  | ||||||
|             padding: 0px 12px 6px 12px; |  | ||||||
|             display: flex; |  | ||||||
|             align-items: baseline; |  | ||||||
|             flex-wrap: wrap; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         .basic-properties-widget > * { |  | ||||||
|             margin-top: 9px; |  | ||||||
|             margin-bottom: 2px; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         .basic-properties-widget > * > :last-child { |  | ||||||
|             margin-right: 30px; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         .note-type-container, |  | ||||||
|         .editability-select-container, |  | ||||||
|         .note-language-container { |  | ||||||
|             display: flex; |  | ||||||
|             align-items: center; |  | ||||||
|         } |  | ||||||
|     </style> |  | ||||||
|  |  | ||||||
|     <div class="note-type-container"> |     <div class="note-type-container"> | ||||||
|         <span>${t("basic_properties.note_type")}:</span>   |         <span>${t("basic_properties.note_type")}:</span>   | ||||||
|     </div> |     </div> | ||||||
| @@ -55,7 +29,7 @@ const TPL = /*html*/` | |||||||
|     <div class="note-language-container"> |     <div class="note-language-container"> | ||||||
|         <span>${t("basic_properties.language")}:</span>   |         <span>${t("basic_properties.language")}:</span>   | ||||||
|     </div> |     </div> | ||||||
| </div>`; | `; | ||||||
|  |  | ||||||
| export default class BasicPropertiesWidget extends NoteContextAwareWidget { | export default class BasicPropertiesWidget extends NoteContextAwareWidget { | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user