Skip to content
Snippets Groups Projects
Commit 31237862 authored by Loïc Correnson's avatar Loïc Correnson
Browse files

[dome] TS boxes

parent d6f90bdd
No related branches found
No related tags found
No related merge requests found
...@@ -3,10 +3,6 @@ ...@@ -3,10 +3,6 @@
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** /**
@packageDocumentation
@module dome/layout/boxes
@description
This modules offers several `<div>` containers with various This modules offers several `<div>` containers with various
predefined layout. predefined layout.
...@@ -20,14 +16,14 @@ ...@@ -20,14 +16,14 @@
then vertically by wrapping cells in rows. then vertically by wrapping cells in rows.
The various containers layout and extensibility is listed below: The various containers layout and extensibility is listed below:
- [[Hbox]] horizontal, fixed height - [[Hbox]] horizontal, fixed height
- [[Vbox]] vertical, fixed width - [[Vbox]] vertical, fixed width
- [[Hpack]] horizontal, fixed dimensions - [[Hpack]] horizontal, fixed dimensions
- [[Vpack]] vertical, fixed dimensions - [[Vpack]] vertical, fixed dimensions
- [[Hfill]] horizontal, extends in both directions - [[Hfill]] horizontal, extends in both directions
- [[Vfill]] vertical, extends in both directions - [[Vfill]] vertical, extends in both directions
- [[Grid]] uses CSS grid columns, extends in both directions - [[Grid]] uses CSS grid columns, extends in both directions
- [[Scroll]] scrolls its content - [[Scroll]] scrolls its content
Inside a box, you may add `<Space/>` and `<Filler/>` to separate items. Inside a box, you may add `<Space/>` and `<Filler/>` to separate items.
Inside a grid, you may also use `<Space/>` or an empty `<div/>` for empty cells. Inside a grid, you may also use `<Space/>` or an empty `<div/>` for empty cells.
...@@ -35,21 +31,31 @@ ...@@ -35,21 +31,31 @@
<strong>Warning:</strong> large elements will be clipped if they overflow. <strong>Warning:</strong> large elements will be clipped if they overflow.
If you want to add scrolling capabilities to some item that does not manage overflow If you want to add scrolling capabilities to some item that does not manage overflow
natively, place it inside a `<Scroll/>` sub-container. natively, place it inside a `<Scroll/>` sub-container.
*/
@packageDocumentation
@module dome/layout/boxes
*/
import React from 'react'; import React from 'react';
import * as Dome from 'dome'; import * as Dome from 'dome';
import { Title } from 'dome/controls/labels' ; import { Title } from 'dome/controls/labels';
import './style.css' ; import './style.css';
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// --- Generic Box // --- Generic Box
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
const makeBox = ( boxClasses, props, morestyle ) => { /** Div properties that you can also use in boxes. */
const { children, className, style, ...others } = props ; export type DivProps = React.HTMLAttributes<HTMLDivElement>;
const allClasses = className ? boxClasses + ' ' + className : boxClasses ;
const allStyles = morestyle ? (style ? Object.assign( {}, style, morestyle ) : morestyle) : style ; const makeBox = (
boxClasses: string,
props: DivProps,
morestyle?: React.CSSProperties,
) => {
const { children, className, style, ...others } = props;
const allClasses = className ? boxClasses + ' ' + className : boxClasses;
const allStyles = morestyle ? (style ? Object.assign({}, style, morestyle) : morestyle) : style;
return ( return (
<div className={allClasses} style={allStyles} {...others} > <div className={allClasses} style={allStyles} {...others} >
{children} {children}
...@@ -62,120 +68,109 @@ const makeBox = ( boxClasses, props, morestyle ) => { ...@@ -62,120 +68,109 @@ const makeBox = ( boxClasses, props, morestyle ) => {
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** /**
@summary Horizontal box (extends horizontally, no overflow). Horizontal box (extends horizontally, no overflow).
@property {object} [...props] - Extra properties passed to the `<div>` container
@description
<strong>Warning:</strong> large elements will be clipped if they overflow.
*/ */
export const Hbox = (props) => makeBox( 'dome-xBoxes-hbox dome-xBoxes-box' , props ); export const Hbox = (props: DivProps) => makeBox('dome-xBoxes-hbox dome-xBoxes-box', props);
/** /**
@summary Vertical box (extends vertically, no overflow). Vertical box (extends vertically, no overflow).
@property {object} [...props] - Extra properties passed to the `<div>` container
@description
<strong>Warning:</strong> large elements will be clipped if they overflow.
*/ */
export const Vbox = (props) => makeBox( 'dome-xBoxes-vbox dome-xBoxes-box' , props ); export const Vbox = (props: DivProps) => makeBox('dome-xBoxes-vbox dome-xBoxes-box', props);
/** /**
@summary Compact Horizontal box (fixed dimensions, no overflow). Compact Horizontal box (fixed dimensions, no overflow).
@property {object} [...props] - Extra properties passed to the `<div>` container
@description
<strong>Warning:</strong> large elements would be clipped if they overflow.
*/ */
export const Hpack = (props) => makeBox( 'dome-xBoxes-hbox dome-xBoxes-pack' , props ); export const Hpack = (props: DivProps) => makeBox('dome-xBoxes-hbox dome-xBoxes-pack', props);
/** /**
@summary Compact Vertical box (fixed dimensions, no overflow). Compact Vertical box (fixed dimensions, no overflow).
@property {object} [...props] - Extra properties passed to the `<div>` container
@description
<strong>Warning:</strong> large elements will be clipped if they overflow.
*/ */
export const Vpack = (props) => makeBox( 'dome-xBoxes-vbox dome-xBoxes-pack' , props ); export const Vpack = (props: DivProps) => makeBox('dome-xBoxes-vbox dome-xBoxes-pack', props);
/** /**
@summary Horizontally filled box (fixed height, maximal width, no overflow). Horizontally filled box (fixed height, maximal width, no overflow).
@property {object} [...props] - Extra properties passed to the `<div>` container
@description
<strong>Warning:</strong> large elements will be clipped if they overflow.
*/ */
export const Hfill = (props) => makeBox( 'dome-xBoxes-hbox dome-xBoxes-fill' , props ); export const Hfill = (props: DivProps) => makeBox('dome-xBoxes-hbox dome-xBoxes-fill', props);
/** /**
@summary Vertically filled box (fixed width, maximal height, no overflow). Vertically filled box (fixed width, maximal height, no overflow).
@property {object} [...props] - Extra properties passed to the `<div>` container
@description
<strong>Warning:</strong> large elements will be clipped if they overflow.
*/ */
export const Vfill = (props) => makeBox( 'dome-xBoxes-vbox dome-xBoxes-fill' , props ); export const Vfill = (props: DivProps) => makeBox('dome-xBoxes-vbox dome-xBoxes-fill', props);
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// --- Scrolling & Spacing // --- Scrolling & Spacing
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** /**
@summary Scrolling container. Scrolling container.
@property {object} [...props] - Extra properties passed to the `<div>` container
*/ */
export const Scroll = (props) => makeBox( 'dome-xBoxes-scroll dome-container' , props ); export const Scroll = (props: DivProps) => makeBox('dome-xBoxes-scroll dome-container', props);
/** /**
@summary Rigid space between items in a box. Rigid space between items in a box.
@property {object} [...props] - Extra properties passed to the `<div>` separator
*/ */
export const Space = (props) => makeBox( 'dome-xBoxes-space' , props ); export const Space = (props: DivProps) => makeBox('dome-xBoxes-space', props);
/** /**
@summary Extensible space between items in a box. Extensible space between items in a box.
@property {object} [...props] - Extra properties passed to the `<div>` separator
*/ */
export const Filler = (props) => makeBox( 'dome-xBoxes-filler' , props ); export const Filler = (props: DivProps) => makeBox('dome-xBoxes-filler', props);
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// --- Grids // --- Grids
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
export interface GridProps extends DivProps { columns?: string; }
/** /**
@summary Grid box container. Grid box container.
@property {string} [columns] - Grid column specifications
@property {object} [...props] - Extra properties passed to the `<div>` container
@description
Layout its children in a multi-column grid. Each column is specified by its Layout its children in a multi-column grid. Each column is specified by its
width, following the CSS Grid Layout `grid-template-columns` property. width, following the CSS Grid Layout `grid-template-columns` property.
The rows are populated with children from left-to-right, using one column at a time. The rows are populated with children from left-to-right, using one column at a time.
Items layout can be modified by adding CSS Grid Layout item properties. Items layout can be modified by using CSS Grid Layout item properties.
Example: `<Grid columns="25% auto auto"> ... </Grid>` Example: `<Grid columns="25% auto auto"> ... </Grid>`
*/ */
export const Grid = ({columns='auto',...props}) => export const Grid = (props: GridProps) => {
makeBox( 'dome-xBoxes-grid', props , { gridTemplateColumns: columns }); const { columns, ...others } = props;
return makeBox('dome-xBoxes-grid', others, { gridTemplateColumns: columns });
};
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// --- Folders // --- Folders
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
export interface FolderProps {
/** Title bar label. */
label: string;
/** Title bar tooltip. */
title?: string;
/** Window settings key. */
settings?: string;
/** Default state (`false`). */
defaultUnfold?: boolean;
/** Contents left margin (in pixels, defaults to 18). */
indent?: number;
/** Children JSX elements. */
children: any;
}
/** /**
@summary Foldable Vpack box. Foldable (vertical, packed) box.
@property {string} label - box label The head label is clickable to fold/unfold its contents.
@property {string} [title] - box label tooltip
@property {string} [settings] - window setting to store the fold/unfold state
@property {boolean} [defaultUnfold] - initial state (default is `false`)
@property {React.Children} [children] - content of the vertical box
@description
A vertical `Vpack` box with a clickable head label to fold/unfold its content.
*/ */
export const Folder = export const Folder = (props: FolderProps) => {
({ settings, defaultUnfold=false, indent=18, label, title, children }) => const { settings, defaultUnfold = false, indent = 18, label, title, children } = props;
{ const [unfold, onClick] = Dome.useSwitch(settings, defaultUnfold);
const [ unfold , setUnfold ] = Dome.useState( settings, defaultUnfold ); const icon = unfold ? 'TRIANGLE.DOWN' : 'TRIANGLE.RIGHT';
const icon = unfold ? 'TRIANGLE.DOWN' : 'TRIANGLE.RIGHT' ; const display = unfold ? 'none' : 'block';
const onClick = () => setUnfold( !unfold );
return ( return (
<Vpack> <Vpack>
<Hpack onClick={onClick}><Title icon={icon} label={label} title={title} /></Hpack> <Hpack onClick={onClick}><Title icon={icon} label={label} title={title} /></Hpack>
<Vpack style={{ marginLeft:indent }}> <Vpack style={{ display, marginLeft: indent }}>
{ unfold && children } {children}
</Vpack> </Vpack>
</Vpack> </Vpack>
); );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment