@tempots/ui 0.1.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/README.md +1 -1
  2. package/components/pop-over.d.ts +13 -0
  3. package/index.cjs +1 -0
  4. package/index.d.ts +1 -24
  5. package/index.js +1440 -20
  6. package/package.json +15 -38
  7. package/components/Box/Box.d.ts +0 -8
  8. package/components/Box/Box.js +0 -8
  9. package/components/Button/Button.d.ts +0 -12
  10. package/components/Button/Button.js +0 -19
  11. package/components/Control/Control.d.ts +0 -8
  12. package/components/Control/Control.js +0 -16
  13. package/components/Field/Field.d.ts +0 -11
  14. package/components/Field/Field.js +0 -37
  15. package/components/Field/field-layout.d.ts +0 -1
  16. package/components/Field/field-layout.js +0 -1
  17. package/components/Fieldset/Fieldset.d.ts +0 -8
  18. package/components/Fieldset/Fieldset.js +0 -12
  19. package/components/Fieldset/fieldset-context.d.ts +0 -7
  20. package/components/Fieldset/fieldset-context.js +0 -3
  21. package/components/Group/Group.d.ts +0 -13
  22. package/components/Group/Group.js +0 -28
  23. package/components/Input/BaseInput.d.ts +0 -10
  24. package/components/Input/BaseInput.js +0 -17
  25. package/components/Input/FloatInput.d.ts +0 -10
  26. package/components/Input/FloatInput.js +0 -14
  27. package/components/Input/IntInput.d.ts +0 -9
  28. package/components/Input/IntInput.js +0 -25
  29. package/components/Input/NativeSelect.d.ts +0 -11
  30. package/components/Input/NativeSelect.js +0 -27
  31. package/components/Input/TextInput.d.ts +0 -7
  32. package/components/Input/TextInput.js +0 -9
  33. package/components/Input/UnitInput.d.ts +0 -10
  34. package/components/Input/UnitInput.js +0 -14
  35. package/components/Popover/Popover.d.ts +0 -9
  36. package/components/Popover/Popover.js +0 -35
  37. package/components/Popover/UnstyledPopover.d.ts +0 -19
  38. package/components/Popover/UnstyledPopover.js +0 -97
  39. package/components/Popover/index.d.ts +0 -2
  40. package/components/Popover/index.js +0 -2
  41. package/components/SegmentedControl/SegmentedControl.d.ts +0 -9
  42. package/components/SegmentedControl/SegmentedControl.js +0 -16
  43. package/components/Stack/Stack.d.ts +0 -11
  44. package/components/Stack/Stack.js +0 -18
  45. package/components/StyleProvider/StyleProvider.d.ts +0 -37
  46. package/components/StyleProvider/StyleProvider.js +0 -103
  47. package/components/Tooltip/index.d.ts +0 -5
  48. package/components/Tooltip/index.js +0 -31
  49. package/components/styling/Sizing.d.ts +0 -10
  50. package/components/styling/Sizing.js +0 -5
  51. package/components/styling/Spacing.d.ts +0 -28
  52. package/components/styling/Spacing.js +0 -49
  53. package/components/styling/Sx.d.ts +0 -6
  54. package/components/styling/Sx.js +0 -6
  55. package/styles/color.d.ts +0 -1
  56. package/styles/color.js +0 -1
  57. package/styles/reset.d.ts +0 -1
  58. package/styles/reset.js +0 -283
  59. package/styles/side.d.ts +0 -1
  60. package/styles/side.js +0 -1
  61. package/styles/size.d.ts +0 -5
  62. package/styles/size.js +0 -44
  63. package/styles/sx.d.ts +0 -9
  64. package/styles/sx.js +0 -28
  65. package/styles/ui-styles.d.ts +0 -67
  66. package/styles/ui-styles.js +0 -118
package/package.json CHANGED
@@ -1,46 +1,23 @@
1
1
  {
2
2
  "name": "@tempots/ui",
3
- "version": "0.1.0",
4
- "main": "index.js",
5
- "types": "index.d.ts",
6
- "scripts": {
7
- "watch": "tsc --watch",
8
- "build": "tsc",
9
- "test": "jest",
10
- "test:watch": "jest --watch",
11
- "coverage": "jest --coverage",
12
- "npm:prep": "yarn build && cp README.md package.json dist",
13
- "npm:publish": "yarn npm:prep && (cd dist && yarn publish --access public)"
14
- },
15
- "dependencies": {
16
- "@emotion/css": "^11.10.6",
17
- "@floating-ui/dom": "^1.2.6",
18
- "@tempots/dom": "^5.0.2",
19
- "@tempots/std": "^0.9.7"
20
- },
21
- "devDependencies": {
22
- "@happy-dom/jest-environment": "^9.1.7",
23
- "@types/jest": "^29.5.0",
24
- "@types/node": "^18.15.11",
25
- "@typescript-eslint/eslint-plugin": "^5.43.0",
26
- "eslint": "^8.0.1",
27
- "eslint-config-standard-with-typescript": "^34.0.1",
28
- "eslint-plugin-import": "^2.25.2",
29
- "eslint-plugin-n": "^15.0.0",
30
- "eslint-plugin-promise": "^6.0.0",
31
- "happy-dom": "^9.1.0",
32
- "jest": "^29.5.0",
33
- "ts-jest": "^29.1.0",
34
- "typescript": "^5.0.3"
3
+ "version": "0.3.1",
4
+ "type": "module",
5
+ "main": "./index.cjs",
6
+ "module": "./index.js",
7
+ "types": "./index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./index.js",
11
+ "require": "./index.cjs"
12
+ }
35
13
  },
14
+ "license": "Apache-2.0",
36
15
  "repository": {
37
16
  "type": "git",
38
- "url": "git+https://github.com/fponticelli/tempots-ui.git"
17
+ "url": "git+https://github.com/fponticelli/tempots.git"
39
18
  },
40
- "author": "Franco Ponticelli",
41
- "license": "Apache-2.0",
42
19
  "bugs": {
43
- "url": "https://github.com/fponticelli/tempots-ui/issues"
20
+ "url": "https://github.com/fponticelli/tempots/issues"
44
21
  },
45
- "homepage": "https://github.com/fponticelli/tempots-ui#readme"
46
- }
22
+ "homepage": "https://github.com/fponticelli/tempots#readme"
23
+ }
@@ -1,8 +0,0 @@
1
- import { type JSX } from '@tempots/dom';
2
- import { type SizingProps } from '../styling/Sizing';
3
- import { type SpacingProps } from '../styling/Spacing';
4
- import { type SxProps } from '../styling/Sx';
5
- export interface BoxProps extends SxProps, SpacingProps, SizingProps {
6
- children?: JSX.DOMNode;
7
- }
8
- export declare const Box: (props: BoxProps) => JSX.DOMNode;
@@ -1,8 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "@tempots/dom/jsx-runtime";
2
- import { Sizing } from '../styling/Sizing';
3
- import { Spacing } from '../styling/Spacing';
4
- import { Sx } from '../styling/Sx';
5
- export const Box = (props) => {
6
- const { children, sx, ...rest } = props;
7
- return (_jsxs("div", { children: [_jsx(Sx, { sx: sx }), _jsx(Spacing, { ...rest }), _jsx(Sizing, { ...rest }), children] }));
8
- };
@@ -1,12 +0,0 @@
1
- import { type JSX, Signal } from '@tempots/dom';
2
- import { type Size } from '../../styles/size';
3
- import { type ButtonVariant } from '../StyleProvider/StyleProvider';
4
- export interface ButtonProps {
5
- children?: JSX.DOMNode;
6
- disabled?: Signal<boolean>;
7
- onClick?: () => void;
8
- size?: Signal<Size>;
9
- variant?: Signal<ButtonVariant>;
10
- compact?: Signal<boolean>;
11
- }
12
- export declare function Button({ children, size, disabled, onClick, variant, compact }: ButtonProps): JSX.DOMNode;
@@ -1,19 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "@tempots/dom/jsx-runtime";
2
- import { Consumer, Signal, ClassName } from '@tempots/dom';
3
- import { StyleMarker } from '../StyleProvider/StyleProvider';
4
- export function Button({ children, size, disabled, onClick, variant, compact }) {
5
- return (_jsx(Consumer, { mark: StyleMarker, children: (theme) => {
6
- const cls = Signal.combine([
7
- theme.styles,
8
- size ?? Signal.of('md'),
9
- variant ?? Signal.of('primary'),
10
- compact ?? Signal.of(false)
11
- ], ({ components: { button: { root, content } } }, size, variant, compact) => {
12
- return [
13
- root({ size, variant, compact }),
14
- content({ size, variant, compact })
15
- ];
16
- });
17
- return _jsxs("button", { disabled: disabled, type: "button", onClick: onClick, children: [_jsx(ClassName, { value: cls.at(0) }), _jsxs("span", { children: [_jsx(ClassName, { value: cls.at(1) }), children] })] });
18
- } }));
19
- }
@@ -1,8 +0,0 @@
1
- import { type JSX, Signal } from '@tempots/dom';
2
- import { type Size } from '../../styles/size';
3
- export interface ControlProps {
4
- size?: Signal<Size>;
5
- spacing?: Signal<Size>;
6
- children?: JSX.DOMNode;
7
- }
8
- export declare const Control: (props: ControlProps) => JSX.DOMNode;
@@ -1,16 +0,0 @@
1
- import { jsx as _jsx } from "@tempots/dom/jsx-runtime";
2
- import { Consumer, Signal } from '@tempots/dom';
3
- import { StyleMarker } from '../StyleProvider/StyleProvider';
4
- export const Control = (props) => {
5
- const { children, size, spacing } = props;
6
- return (_jsx(Consumer, { mark: StyleMarker, children: ({ styles }) => {
7
- const cls = Signal.combine([
8
- styles,
9
- size ?? Signal.of('md'),
10
- spacing ?? Signal.of('md')
11
- ], (styles, size, spacing) => {
12
- return styles.components.control.root({ size, spacing });
13
- });
14
- return (_jsx("div", { className: cls, children: children }));
15
- } }));
16
- };
@@ -1,11 +0,0 @@
1
- import { type JSX, Signal } from '@tempots/dom';
2
- import { type FieldLayout } from './field-layout';
3
- export interface FieldProps {
4
- children?: JSX.DOMNode;
5
- description?: JSX.DOMNode;
6
- error?: JSX.DOMNode;
7
- label?: JSX.DOMNode;
8
- layout?: Signal<FieldLayout>;
9
- required?: Signal<boolean>;
10
- }
11
- export declare const Field: ({ children, ...props }: FieldProps) => JSX.DOMNode;
@@ -1,37 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "@tempots/dom/jsx-runtime";
2
- import { Consumer, HiddenWhenEmpty, Signal, When } from '@tempots/dom';
3
- import { Box } from '../Box/Box';
4
- import { FieldsetMark } from '../Fieldset/fieldset-context';
5
- const layoutToFlexDirection = (layout) => {
6
- // TODO: any
7
- switch (layout) {
8
- case 'horizontal':
9
- return 'row';
10
- case 'vertical':
11
- return 'column';
12
- }
13
- };
14
- export const Field = ({ children, ...props }) => {
15
- return (_jsx(Consumer, { mark: FieldsetMark, children: ({ layout: fsLayout }) => {
16
- const required = props.required ?? Signal.of(false);
17
- const layout = props.layout ?? fsLayout;
18
- const error = props.error;
19
- const label = Signal.of(props.label);
20
- const description = props.description;
21
- const isHorizontal = layout.map(v => v === 'horizontal');
22
- return (
23
- // TODO force vertical layout if there is not enough space
24
- _jsxs(Box, { sx: {
25
- display: 'flex',
26
- flexDirection: layout.map(layoutToFlexDirection)
27
- }, children: [_jsxs(Box, { width: isHorizontal.map(v => v ? 200 : undefined), children: [_jsxs(Box
28
- // sx={{
29
- // minHeight: isHorizontal.map(v => (v ? ('36px' as any) : undefined)) // TODO
30
- // }}
31
- , { children: [label, _jsx(When, { is: required, children: _jsx("span", { children: " *" }) })] }), _jsxs(Box, { sx: {
32
- fontSize: '0.8em' // TODO
33
- }, children: [_jsx(HiddenWhenEmpty, {}), description] })] }), _jsxs(Box, { sx: {
34
- flex: isHorizontal.map(v => (v ? '1 1 auto' : undefined))
35
- }, children: [_jsx(Box, { children: children }), _jsxs(Box, { children: [_jsx(HiddenWhenEmpty, {}), error] })] })] }));
36
- } }));
37
- };
@@ -1 +0,0 @@
1
- export type FieldLayout = 'horizontal' | 'vertical';
@@ -1 +0,0 @@
1
- export {};
@@ -1,8 +0,0 @@
1
- import { type JSX, Signal } from '@tempots/dom';
2
- import { type FieldLayout } from '../Field/field-layout';
3
- export interface FieldsetProps {
4
- children?: JSX.DOMNode;
5
- layout?: FieldLayout | Signal<FieldLayout>;
6
- title?: JSX.DOMNode;
7
- }
8
- export declare const Fieldset: ({ children, layout, title }: FieldsetProps) => JSX.DOMNode;
@@ -1,12 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "@tempots/dom/jsx-runtime";
2
- import { Signal, Provider } from '@tempots/dom';
3
- import { Sx } from '../styling/Sx';
4
- import { FIELDSET_DEFAULT_LAYOUT, FieldsetMark } from './fieldset-context';
5
- export const Fieldset = ({ children, layout, title }) => {
6
- const payload = { layout: layout == null ? Signal.of(FIELDSET_DEFAULT_LAYOUT) : Signal.wrap(layout) };
7
- return (_jsxs("fieldset", { children: [_jsx(Sx, { sx: {
8
- display: 'flex',
9
- flexDirection: 'column',
10
- gap: 10 // TODO
11
- } }), title && _jsx("legend", { children: title }), _jsx(Provider, { mark: FieldsetMark, value: payload, children: children })] }));
12
- };
@@ -1,7 +0,0 @@
1
- import { type Signal } from '@tempots/dom';
2
- import { type FieldLayout } from '../Field/field-layout';
3
- export declare const FIELDSET_DEFAULT_LAYOUT: FieldLayout;
4
- export interface FieldsetProvider {
5
- layout: Signal<FieldLayout>;
6
- }
7
- export declare const FieldsetMark: symbol;
@@ -1,3 +0,0 @@
1
- import { makeProviderMark } from '@tempots/dom/types/idom-context';
2
- export const FIELDSET_DEFAULT_LAYOUT = 'horizontal';
3
- export const FieldsetMark = makeProviderMark();
@@ -1,13 +0,0 @@
1
- import { type JSX, Signal } from '@tempots/dom';
2
- import { type Size } from '../../styles/size';
3
- import { type AlignItems } from '../Stack/Stack';
4
- export type Position = 'left' | 'right' | 'center' | 'apart';
5
- export interface GroupProps {
6
- align?: Signal<AlignItems>;
7
- grow?: Signal<boolean>;
8
- noWrap?: Signal<boolean>;
9
- position?: Signal<Position>;
10
- spacing?: Signal<number> | Signal<Size>;
11
- children?: JSX.DOMNode;
12
- }
13
- export declare const Group: (props: GroupProps) => JSX.DOMNode;
@@ -1,28 +0,0 @@
1
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "@tempots/dom/jsx-runtime";
2
- import { Consumer, Signal } from '@tempots/dom';
3
- import { StyleMarker } from '../StyleProvider/StyleProvider';
4
- import { Sx } from '../styling/Sx';
5
- export const Group = (props) => {
6
- const { children, align, grow, noWrap, position, spacing } = props;
7
- return (_jsx(Consumer, { mark: StyleMarker, children: ({ styles }) => {
8
- return (_jsxs("div", { children: [_jsx(Sx, { sx: {
9
- display: 'flex',
10
- flexDirection: 'row',
11
- alignItems: align,
12
- flexWrap: (noWrap ?? Signal.of(false)).map(v => v ? 'nowrap' : 'wrap'),
13
- justifyContent: position?.map(v => {
14
- switch (v) {
15
- case 'left': return 'flex-start';
16
- case 'right': return 'flex-end';
17
- case 'center': return 'center';
18
- case 'apart': return 'space-between';
19
- default: return 'flex-start';
20
- }
21
- }),
22
- flexGrow: grow?.map(v => v ? 1 : 0),
23
- gap: (spacing ?? Signal.of('md')).combine(styles, (sp, st) => {
24
- return (typeof sp === 'number' ? sp : st.styles.spacing[sp]);
25
- })
26
- } }), _jsx(_Fragment, { children: children })] }));
27
- } }));
28
- };
@@ -1,10 +0,0 @@
1
- import { type JSX, type Signal } from '@tempots/dom';
2
- export interface BaseInputProps {
3
- max?: Signal<number>;
4
- min?: Signal<number>;
5
- type: string;
6
- value: Signal<string>;
7
- step?: Signal<number>;
8
- onChange: (value: string) => void;
9
- }
10
- export declare const BaseInput: ({ max, min, value, onChange, step, type }: BaseInputProps) => JSX.DOMNode;
@@ -1,17 +0,0 @@
1
- import { jsx as _jsx } from "@tempots/dom/jsx-runtime";
2
- import { Sx } from '../styling/Sx';
3
- export const BaseInput = ({ max, min, value, onChange, step, type }) => {
4
- return (_jsx("input", { min: min, max: max, type: type, value: value, step: step, onInput: e => {
5
- const target = e.target;
6
- onChange(target.value);
7
- }, children: _jsx(Sx, { sx: {
8
- width: '100%',
9
- backgroundColor: 'transparent',
10
- flexGrow: '1 1 auto',
11
- textAlign: type === 'number' ? 'right' : undefined,
12
- padding: '0 8px',
13
- ':focus': {
14
- outline: 'none'
15
- }
16
- } }) }));
17
- };
@@ -1,10 +0,0 @@
1
- import { type JSX, type Signal } from '@tempots/dom';
2
- export interface FloatInputProps {
3
- min?: Signal<number>;
4
- max?: Signal<number>;
5
- step?: Signal<number>;
6
- value: Signal<number>;
7
- onChange: (value: number) => void;
8
- }
9
- export declare const FloatInput: ({ min, max, value, onChange, step }: FloatInputProps) => JSX.DOMNode;
10
- export declare const BaseFloatInput: ({ min, max, value, onChange, step }: FloatInputProps) => JSX.DOMNode;
@@ -1,14 +0,0 @@
1
- import { jsx as _jsx } from "@tempots/dom/jsx-runtime";
2
- import { Control } from '../Control/Control';
3
- import { BaseInput } from './BaseInput';
4
- export const FloatInput = ({ min, max, value, onChange, step }) => {
5
- return (_jsx(Control, { children: _jsx(BaseFloatInput, { min: min, max: max, value: value, onChange: onChange, step: step }) }));
6
- };
7
- export const BaseFloatInput = ({ min, max, value, onChange, step }) => {
8
- return (_jsx(BaseInput, { min: min, max: max, type: "number", step: step, value: value.map(String), onChange: value => {
9
- const newValue = parseFloat(value);
10
- if (!isNaN(newValue)) {
11
- onChange(newValue);
12
- }
13
- } }));
14
- };
@@ -1,9 +0,0 @@
1
- import { type JSX, Signal } from '@tempots/dom';
2
- export interface IntInputProps {
3
- max?: Signal<number>;
4
- min?: Signal<number>;
5
- value: Signal<number>;
6
- onChange: (value: number) => void;
7
- }
8
- export declare const IntInput: ({ value, onChange, max, min }: IntInputProps) => JSX.DOMNode;
9
- export declare const BaseIntInput: ({ value, onChange, max, min }: IntInputProps) => JSX.DOMNode;
@@ -1,25 +0,0 @@
1
- import { jsx as _jsx } from "@tempots/dom/jsx-runtime";
2
- import { Signal } from '@tempots/dom';
3
- import { Control } from '../Control/Control';
4
- import { BaseInput } from './BaseInput';
5
- export const IntInput = ({ value, onChange, max, min }) => {
6
- return (_jsx(Control, { children: _jsx(BaseIntInput, { value: value, onChange: onChange, max: max, min: min }) }));
7
- };
8
- export const BaseIntInput = ({ value, onChange, max, min }) => {
9
- const minSignal = (min ?? Signal.of(null));
10
- const maxSignal = (max ?? Signal.of(null));
11
- return (_jsx(BaseInput, { type: "number", min: min, max: max, step: Signal.of(1), value: Signal.combine([value, minSignal, maxSignal], (v, mi, ma) => {
12
- if (mi !== null && v < mi) {
13
- return mi;
14
- }
15
- if (ma !== null && v > ma) {
16
- return ma;
17
- }
18
- return v;
19
- }).map(String), onChange: (value) => {
20
- const newValue = Math.round(Number(value));
21
- if (isFinite(newValue)) {
22
- onChange(Math.round(newValue));
23
- }
24
- } }));
25
- };
@@ -1,11 +0,0 @@
1
- import { type JSX, type Signal } from '@tempots/dom';
2
- export interface NativeSelectProps<T> {
3
- value: Signal<T>;
4
- options: Signal<T[]>;
5
- onChange?: (value: T) => void;
6
- display?: (value: T) => string;
7
- equality?: (a: T, b: T) => boolean;
8
- disabled?: (value: T) => boolean;
9
- }
10
- export declare function NativeSelect<T>({ value, onChange, options, display, equality, disabled }: NativeSelectProps<T>): JSX.DOMNode;
11
- export declare function BaseNativeSelect<T>(props: NativeSelectProps<T>): JSX.DOMNode;
@@ -1,27 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "@tempots/dom/jsx-runtime";
2
- import { For } from '@tempots/dom';
3
- import { strictEqual } from '@tempots/std/equals';
4
- import { Control } from '../Control/Control';
5
- import { Spacing } from '../styling/Spacing';
6
- import { Sx } from '../styling/Sx';
7
- export function NativeSelect({ value, onChange, options, display, equality, disabled }) {
8
- return (_jsx(Control, { children: _jsx(BaseNativeSelect, { value: value, onChange: onChange, options: options, display: display, equality: equality, disabled: disabled }) }));
9
- }
10
- export function BaseNativeSelect(props) {
11
- const options = props.options;
12
- const equality = props.equality ?? strictEqual;
13
- const display = props.display ?? String;
14
- const disabled = props.disabled ?? (() => false);
15
- // eslint-disable-next-line @typescript-eslint/no-empty-function
16
- const onChange = props.onChange ?? (() => { });
17
- return (_jsxs("select", { onChange: e => {
18
- const target = e.target;
19
- const index = Number(target.value);
20
- onChange(options.get()[index]);
21
- }, children: [_jsx(Sx, { sx: {
22
- ':focus': {
23
- outline: 'none',
24
- background: 'rgba(10%, 10%, 100%, 0.2)' // TODO
25
- }
26
- } }), _jsx(Spacing, { ph: 8 }), _jsx(For, { of: options, children: (option, index) => (_jsx("option", { disabled: option.map(disabled), selected: option.combine(props.value, equality), value: String(index), children: option.map(display) })) })] }));
27
- }
@@ -1,7 +0,0 @@
1
- import { type JSX, type Signal } from '@tempots/dom';
2
- export interface TextInputProps {
3
- value: Signal<string>;
4
- onChange: (value: string) => void;
5
- }
6
- export declare const TextInput: ({ value, onChange }: TextInputProps) => JSX.DOMNode;
7
- export declare const BaseTextInput: ({ value, onChange }: TextInputProps) => JSX.DOMNode;
@@ -1,9 +0,0 @@
1
- import { jsx as _jsx } from "@tempots/dom/jsx-runtime";
2
- import { Control } from '../Control/Control';
3
- import { BaseInput } from './BaseInput';
4
- export const TextInput = ({ value, onChange }) => {
5
- return (_jsx(Control, { children: _jsx(BaseTextInput, { value: value, onChange: onChange }) }));
6
- };
7
- export const BaseTextInput = ({ value, onChange }) => {
8
- return _jsx(BaseInput, { type: "text", value: value, onChange: onChange });
9
- };
@@ -1,10 +0,0 @@
1
- import { type JSX, type Signal } from '@tempots/dom';
2
- export interface UnitInputProps<T> {
3
- step?: Signal<number>;
4
- value: Signal<number>;
5
- unit: Signal<T>;
6
- units: Signal<T[]>;
7
- onChange: (value: number, unit: T) => void;
8
- convert?: (from: T, to: T, value: number) => number;
9
- }
10
- export declare function UnitInput<T>({ value, onChange, step, unit, units, ...props }: UnitInputProps<T>): JSX.DOMNode;
@@ -1,14 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "@tempots/dom/jsx-runtime";
2
- import { Control } from '../Control/Control';
3
- import { BaseFloatInput } from './FloatInput';
4
- import { BaseNativeSelect } from './NativeSelect';
5
- export function UnitInput({ value, onChange, step, unit, units, ...props }) {
6
- const convert = props.convert ?? ((from, to, value) => value);
7
- const onChangeValue = (value) => {
8
- onChange(value, unit.get());
9
- };
10
- const onChangeUnit = (newUnit) => {
11
- onChange(convert(unit.get(), newUnit, value.get()), newUnit);
12
- };
13
- return (_jsxs(Control, { children: [_jsx(BaseFloatInput, { value: value, onChange: onChangeValue, step: step }), _jsx(BaseNativeSelect, { value: unit, onChange: onChangeUnit, options: units })] }));
14
- }
@@ -1,9 +0,0 @@
1
- import { type JSX, Signal, type Prop } from '@tempots/dom';
2
- export type OpenStrategy = 'click' | 'hover';
3
- export interface PopoverProps {
4
- children?: JSX.DOMNode;
5
- openStrategy?: OpenStrategy;
6
- maxWidth?: Signal<number>;
7
- opened?: Prop<boolean>;
8
- }
9
- export declare function Popover({ children, openStrategy, maxWidth, opened }: PopoverProps): JSX.DOMNode;
@@ -1,35 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "@tempots/dom/jsx-runtime";
2
- import { Consumer, Signal, Attribute } from '@tempots/dom';
3
- import { UnstyledPopover } from '../Popover';
4
- import { onTargetClickMount, onTargetOverMount } from '../Popover/UnstyledPopover';
5
- import { StyleMarker } from '../StyleProvider/StyleProvider';
6
- import { Sx } from '../styling/Sx';
7
- const ARROW_SIZE = 8;
8
- export function Popover({ children, openStrategy, maxWidth, opened }) {
9
- return (_jsx(_Fragment, { children: _jsx(Consumer, { mark: StyleMarker, children: ({ styles }) => {
10
- const at = styles.at('styles').at;
11
- return (_jsxs(UnstyledPopover, { opened: opened, arrowOver: true, onTargetMount: openStrategy === 'hover' ? onTargetOverMount : onTargetClickMount, placement: Signal.of('bottom'), offset: Signal.of(ARROW_SIZE), arrow: _jsx("div", { children: _jsx(Sx, { sx: {
12
- backgroundColor: at('background').at('color'),
13
- // boxShadow: at('shadow').at('md') as Signal<any>,
14
- border: at('control').map(v => `1px solid ${v.borderColor}`),
15
- borderRight: 'none',
16
- borderBottom: 'none',
17
- marginTop: -ARROW_SIZE / 2,
18
- transform: 'rotate(45deg)',
19
- width: ARROW_SIZE,
20
- height: ARROW_SIZE
21
- } }) }), children: [_jsx(Attribute, { name: "role", value: Signal.of('dialog') }), _jsx(Sx, { sx: {
22
- maxWidth: (maxWidth ?? Signal.of(240)),
23
- height: 'auto',
24
- lineHeight: '1em',
25
- textAlign: 'center',
26
- whiteSpace: 'normal',
27
- backgroundColor: at('background').at('color'),
28
- color: at('font').at('color'),
29
- padding: at('spacing').map(v => `${v.xs}px ${v.md}px`),
30
- border: at('control').map(v => `1px solid ${v.borderColor}`),
31
- borderRadius: at('border').at('radius').at('md'),
32
- boxShadow: at('shadow').at('md')
33
- } }), children] }));
34
- } }) }));
35
- }
@@ -1,19 +0,0 @@
1
- import { type JSX, Signal, Prop } from '@tempots/dom';
2
- export type Alignment = 'start' | 'end';
3
- export type Side = 'top' | 'right' | 'bottom' | 'left';
4
- export type AlignedPlacement = `${Side}-${Alignment}`;
5
- export type Placement = Side | AlignedPlacement;
6
- export interface UnstyledPopoverProps {
7
- children?: JSX.DOMNode;
8
- placement?: Signal<Placement>;
9
- shiftPadding?: Signal<number>;
10
- offset?: Signal<number>;
11
- arrow?: JSX.DOMNode;
12
- arrowOver?: boolean;
13
- arrowPadding?: Signal<number>;
14
- onTargetMount?: (el: HTMLElement, open: () => void, close: () => void) => () => void;
15
- opened?: Prop<boolean>;
16
- }
17
- export declare function onTargetOverMount(el: HTMLElement, open: () => void, close: () => void): () => void;
18
- export declare function onTargetClickMount(el: HTMLElement, open: () => void, close: () => void): () => void;
19
- export declare function UnstyledPopover({ children, placement: maybePlacement, shiftPadding: maybeShiftPadding, offset: maybeOffset, arrow: maybeArrow, arrowOver, arrowPadding: maybeArrowPadding, onTargetMount, opened: passedOpened }: UnstyledPopoverProps): JSX.DOMNode;
@@ -1,97 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "@tempots/dom/jsx-runtime";
2
- import { Lifecycle, Signal, Prop, FadeIn, FadeOut, When } from '@tempots/dom';
3
- import { computePosition, flip, shift, offset, arrow } from '@floating-ui/dom';
4
- import { Sx } from '../styling/Sx';
5
- export function onTargetOverMount(el, open, close) {
6
- el.addEventListener('mouseenter', open);
7
- el.addEventListener('mouseleave', close);
8
- el.addEventListener('focus', open);
9
- el.addEventListener('blur', close);
10
- return () => {
11
- el.removeEventListener('mouseenter', open);
12
- el.removeEventListener('mouseleave', close);
13
- el.removeEventListener('focus', open);
14
- el.removeEventListener('blur', close);
15
- };
16
- }
17
- export function onTargetClickMount(el, open, close) {
18
- el.addEventListener('click', open);
19
- function clickOutside(e) {
20
- if (!el.contains(e.target)) {
21
- close();
22
- }
23
- }
24
- document.addEventListener('click', clickOutside);
25
- return () => {
26
- el.removeEventListener('click', open);
27
- document.removeEventListener('click', clickOutside);
28
- };
29
- }
30
- export function UnstyledPopover({ children, placement: maybePlacement, shiftPadding: maybeShiftPadding, offset: maybeOffset, arrow: maybeArrow, arrowOver, arrowPadding: maybeArrowPadding, onTargetMount, opened: passedOpened }) {
31
- let target = null;
32
- let dropdown = null;
33
- let arrowElement = null;
34
- const placement = maybePlacement ?? Signal.of('bottom');
35
- const shiftPadding = maybeShiftPadding ?? Signal.of(5);
36
- const offsetValue = maybeOffset ?? Signal.of(5);
37
- const arrowPadding = maybeArrowPadding ?? Signal.of(0);
38
- const opened = passedOpened ?? Prop.of(false);
39
- const placementTop = Prop.of(false);
40
- function open() { opened.set(true); }
41
- function close() { opened.set(false); }
42
- function execute() {
43
- if ((target == null) || (dropdown == null))
44
- return;
45
- const middleware = [];
46
- if (maybeArrow == null) {
47
- middleware.push(flip());
48
- }
49
- middleware.push(shift({ padding: shiftPadding.get() }), offset(offsetValue.get()));
50
- if (arrowElement != null) {
51
- middleware.push(arrow({
52
- element: arrowElement,
53
- padding: arrowPadding.get()
54
- }));
55
- }
56
- computePosition(target, dropdown, {
57
- placement: placement.get(),
58
- middleware
59
- }).then(({ x, y, middlewareData, placement }) => {
60
- if (dropdown == null)
61
- return;
62
- placementTop.set(placement.includes('top'));
63
- dropdown.style.top = `${String(y)}px`;
64
- dropdown.style.left = `${String(x)}px`;
65
- if (arrowElement != null && middlewareData.arrow != null) {
66
- const { x, y } = middlewareData.arrow;
67
- arrowElement.style.top = y != null ? `${String(y)}px` : '';
68
- arrowElement.style.left = x != null ? `${String(x)}px` : '';
69
- }
70
- });
71
- }
72
- let unmountTarget;
73
- function onMountTarget(element) {
74
- target = element;
75
- unmountTarget = onTargetMount?.(element, open, close);
76
- }
77
- function onUnmountTarget() {
78
- target = null;
79
- unmountTarget?.();
80
- }
81
- function onMountArrow(element) {
82
- arrowElement = element;
83
- }
84
- function onUnmountArrow() {
85
- arrowElement = null;
86
- }
87
- function onMountDropdown(element) {
88
- dropdown = element;
89
- window.addEventListener('resize', execute);
90
- execute();
91
- }
92
- function onUnmountDropdown() {
93
- dropdown = null;
94
- window.removeEventListener('resize', execute);
95
- }
96
- return (_jsxs(_Fragment, { children: [_jsx(When, { is: opened, children: _jsxs("div", { children: [_jsx(FadeIn, { start: { opacity: 0, translateY: 12 }, opacity: 1, translateY: 0, duration: 250 }), _jsx(FadeOut, { opacity: 0, translateY: 12, duration: 250 }), _jsx(Sx, { sx: { position: 'absolute' } }), _jsx(When, { is: placementTop.map(v => !v && maybeArrow != null), children: _jsxs("div", { children: [_jsx(Sx, { sx: { position: 'absolute', zIndex: (arrowOver ?? false) ? 1 : 0 } }), _jsx(Lifecycle, { onMount: onMountArrow, onUnmount: onUnmountArrow }), maybeArrow] }) }), _jsxs("div", { children: [_jsx(Sx, { sx: { zIndex: (arrowOver ?? false) ? 0 : 1, position: 'relative' } }), children] }), _jsx(When, { is: placementTop.map(v => v && maybeArrow != null), children: _jsxs("div", { children: [_jsx(Sx, { sx: { position: 'absolute', zIndex: (arrowOver ?? false) ? 1 : 0 } }), _jsx(Lifecycle, { onMount: onMountArrow, onUnmount: onUnmountArrow }), maybeArrow] }) }), _jsx(Lifecycle, { onMount: onMountDropdown, onUnmount: onUnmountDropdown })] }) }), _jsx(Lifecycle, { onMount: onMountTarget, onUnmount: onUnmountTarget })] }));
97
- }
@@ -1,2 +0,0 @@
1
- export { UnstyledPopover, type Placement, type UnstyledPopoverProps } from './UnstyledPopover';
2
- export { Popover, type PopoverProps, type OpenStrategy } from './Popover';