# web/pane (vanilla.js 0.4.0)

> https://vanillapunch.com/docs/vanilla.js/0.4.0/api/web/pane/

Split panel (Pane) class.

## PaneStyle

Utility for styles and element creation.

Example: Create a button with the theme style

```js
import { PaneStyle, PaneTheme } from "./build/vanilla.js";

const button = PaneStyle.create("button", "button", { text: "OK", accent: true });
PaneStyle.apply(button, { margin: "8px" });
document.body.appendChild(button);
console.log(button.style.margin, PaneTheme.color.accent);
```

- `static apply(el, styles)` (static, since 0.0.10): Applies several styles to an element at once. (does nothing if the element or the styles are missing)
  - `el` HTMLElement: The element to apply the styles to.
  - `styles` Object: CSS property names and values to apply. (camelCase)
- `static create(tagName, preset = "", options = {})` (static, since 0.0.10): Creates an element with a style preset applied.
  - `tagName` string: The tag name to create.
  - `preset` string: The preset name. ("panel", "toolbar", "button", "input", "textarea", "text", or empty for the common style only)
  - `options` Object: { id, text, style, type, placeholder, accent, warning }. (a button with accent or warning true gets that color as its background)
  - returns HTMLElement: The created element.

## Pane

Split panel (Pane) class.

Example: Split left and right and attach to a parent element

```js
import { Pane } from "./build/vanilla.js";

const rootPane = new Pane({ direction: "horizontal" });
const leftPane = new Pane({ size: 200, minSize: 100 });
const rightPane = new Pane({ size: "flex" });
rootPane.addPane(leftPane);
rootPane.addPane(rightPane);
rootPane.attachTo(document.body);
console.log(leftPane.getInitialSize(), rightPane.isFlex(), leftPane.getMinSize());
```

- `constructor(options = {})` (constructor, since 0.0.10): Constructor.
  - `options` { direction?: string, size?: number | string, minSize?: number, maxSize?: number, isResizable?: boolean, resizableEdges?: { top: boolean, bottom: boolean, left: boolean, right: boolean } }: The split direction (horizontal or vertical), the initial size (pixels, a ratio of 1 or less, a percent string, or flex), the smallest and largest size, whether it can be resized and which edges.
- `addPane(pane)` (method, since 0.0.10): Adds a child.
  - `pane` Pane: The panel to attach as a child. (a resizer appears between it and the previous child)
- `updateLayout(x, y, w, h)` (method, since 0.0.10): Layout engine.
  - `x` number: The left position. (pixels)
  - `y` number: The top position. (pixels)
  - `w` number: Width. (pixels)
  - `h` number: Height. (pixels)
- `resetLayout()` (method, since 0.0.10): Resets the layout. (discards dragged sizes)
- `refresh()` (method, since 0.0.10): Lays out again with the parent element's size. (does nothing if there is no parent)
- `attachTo(p)` (method, since 0.0.10): Attaches to a parent element. (lays out again every time the window size changes)
  - `p` HTMLElement: The parent element to attach to.
- `setVisible(isVisible)` (method, since 0.3.2): Shows and hides. (a hidden panel takes no space, and the resizers next to it hide too)
  - `isVisible` boolean: True to show, false to hide.
- `isVisible()` (method, since 0.3.2): Returns whether it is visible.
  - returns boolean: True if visible.
- `isFlex()` (method, since 0.0.10): Returns whether it shares the remaining space. (true when the initial size is 0)
  - returns boolean: True if it shares the remaining space.
- `getInitialSize()` (method, since 0.0.10): Returns the initial size. (a ratio of the parent if 1 or less, pixels if more)
  - returns number: The initial size. (a ratio of the parent if 1 or less, pixels if more)
- `getFixedSize()` (method, since 0.0.10): Returns the decided size. (the value if it was set by dragging or the initial size is in pixels, otherwise 0)
  - returns number: The decided size. (pixels, 0 if none is decided)
- `setFixedSize(s)` (method, since 0.0.10): Sets the decided size. (pixels)
  - `s` number: The size to decide. (pixels)
- `getMinSize()` (method, since 0.0.10): Returns the smallest size. (pixels)
  - returns number: The smallest size. (pixels)
- `getMaxSize()` (method, since 0.0.10): Returns the largest size. (pixels)
  - returns number: Largest size. (pixels)
- `getContainer()` (method, since 0.0.10): Returns the container element.
  - returns HTMLElement: The container element.
- `setCallback(c)` (method, since 0.0.10): Sets the function to call every time the layout changes.
  - `c` Function | null: The function to call every time the layout changes.
- `isResizable()` (method, since 0.0.10): Returns whether the size can be resized.
  - returns boolean: True if the size can be resized.
- `getResizableEdges()` (method, since 0.0.10): Returns the edges that can be resized. ({ top, right, bottom, left })
  - returns { top: boolean, bottom: boolean, left: boolean, right: boolean }: The edges that can be resized.

## PaneTheme (enum)

Theme constants.

- `color` = `{ background: "#1e1e1e", panel: "#252526", toolbar: "#2d2d30", border: "#444", text: "#ccc", textDim: "#aaaaaa", accent: "#0e639c", accentHover: "#1177bb", warning: "#d97706", warningHover: "#f59e0b", error: "#f44336", success: "#4CAF50", inputBg: "#3c3c3c", resizer: "#333", resizerHover: "#007acc" }`: Colors. (CSS color strings)
- `size` = `{ resizer: 5 }`: Size. (pixels)
- `font` = `{ family: "sans-serif", mono: "\"Consolas\", monospace", size: "13px", sizeSmall: "12px" }`: Font and font size.
