mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01:00 
			
		
		
		
	feat(react/ribbon): improve editability select
This commit is contained in:
		
							parent
							
								
									f772f59d7c
								
							
						
					
					
						commit
						da4810672d
					
				@ -4,7 +4,7 @@ import { CSSProperties } from "preact/compat";
 | 
				
			|||||||
import { useCallback, useEffect, useRef, useState } from "preact/hooks";
 | 
					import { useCallback, useEffect, useRef, useState } from "preact/hooks";
 | 
				
			||||||
import { useUniqueName } from "./hooks";
 | 
					import { useUniqueName } from "./hooks";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
interface DropdownProps {
 | 
					export interface DropdownProps {
 | 
				
			||||||
    className?: string;
 | 
					    className?: string;
 | 
				
			||||||
    buttonClassName?: string;
 | 
					    buttonClassName?: string;
 | 
				
			||||||
    isStatic?: boolean;
 | 
					    isStatic?: boolean;
 | 
				
			||||||
 | 
				
			|||||||
@ -1,7 +1,7 @@
 | 
				
			|||||||
import Dropdown from "./Dropdown";
 | 
					import Dropdown, { DropdownProps } from "./Dropdown";
 | 
				
			||||||
import { FormListItem } from "./FormList";
 | 
					import { FormListItem } from "./FormList";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
interface FormDropdownList<T> {
 | 
					interface FormDropdownList<T> extends Omit<DropdownProps, "children"> {
 | 
				
			||||||
    values: T[];
 | 
					    values: T[];
 | 
				
			||||||
    keyProperty: keyof T;
 | 
					    keyProperty: keyof T;
 | 
				
			||||||
    titleProperty: keyof T;
 | 
					    titleProperty: keyof T;
 | 
				
			||||||
@ -10,11 +10,11 @@ interface FormDropdownList<T> {
 | 
				
			|||||||
    onChange(newValue: string): void;
 | 
					    onChange(newValue: string): void;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default function FormDropdownList<T>({ values, keyProperty, titleProperty, descriptionProperty, currentValue, onChange }: FormDropdownList<T>) {
 | 
					export default function FormDropdownList<T>({ values, keyProperty, titleProperty, descriptionProperty, currentValue, onChange, ...restProps }: FormDropdownList<T>) {
 | 
				
			||||||
    const currentValueData = values.find(value => value[keyProperty] === currentValue);
 | 
					    const currentValueData = values.find(value => value[keyProperty] === currentValue);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return (
 | 
					    return (
 | 
				
			||||||
        <Dropdown text={currentValueData?.[titleProperty] ?? ""}>
 | 
					        <Dropdown text={currentValueData?.[titleProperty] ?? ""} {...restProps}>
 | 
				
			||||||
            {values.map(item => (
 | 
					            {values.map(item => (
 | 
				
			||||||
                <FormListItem
 | 
					                <FormListItem
 | 
				
			||||||
                    onClick={() => onChange(item[keyProperty] as string)}
 | 
					                    onClick={() => onChange(item[keyProperty] as string)}
 | 
				
			||||||
 | 
				
			|||||||
@ -2,4 +2,8 @@
 | 
				
			|||||||
    font-size: small;
 | 
					    font-size: small;
 | 
				
			||||||
    color: var(--muted-text-color);
 | 
					    color: var(--muted-text-color);
 | 
				
			||||||
    white-space: normal;
 | 
					    white-space: normal;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.dropdown-item span.bx {
 | 
				
			||||||
 | 
					    flex-shrink: 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -150,6 +150,7 @@ function EditabilitySelect({ note }: { note?: FNote | null }) {
 | 
				
			|||||||
            <span>{t("basic_properties.editable")}:</span>  
 | 
					            <span>{t("basic_properties.editable")}:</span>  
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            <FormDropdownList
 | 
					            <FormDropdownList
 | 
				
			||||||
 | 
					                className="editability-dropdown"
 | 
				
			||||||
                values={options}
 | 
					                values={options}
 | 
				
			||||||
                currentValue={ readOnly ? "readOnly" : autoReadOnlyDisabled ? "autoReadOnlyDisabled" : "auto" }
 | 
					                currentValue={ readOnly ? "readOnly" : autoReadOnlyDisabled ? "autoReadOnlyDisabled" : "auto" }
 | 
				
			||||||
                keyProperty="value" titleProperty="label" descriptionProperty="description"
 | 
					                keyProperty="value" titleProperty="label" descriptionProperty="description"
 | 
				
			||||||
 | 
				
			|||||||
@ -120,4 +120,8 @@
 | 
				
			|||||||
    max-height: 500px;
 | 
					    max-height: 500px;
 | 
				
			||||||
    overflow-y: auto;
 | 
					    overflow-y: auto;
 | 
				
			||||||
    overflow-x: hidden;
 | 
					    overflow-x: hidden;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.editability-dropdown {
 | 
				
			||||||
 | 
					    width: 300px;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user