@canlooks/can-ui 0.0.35 → 0.0.37

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.
@@ -26,10 +26,11 @@ const Button = ({ component: Component = 'button', color = 'primary', shape = 's
26
26
  };
27
27
  const actualPrefix = prefix ?? icon;
28
28
  const actualChildren = label ?? props.children;
29
+ const reverseTextColor = variant === 'filled' || variant === 'flatted' ? '#ffffff' : color;
29
30
  return ((0, jsx_runtime_1.jsxs)(Component, { ...props, css: (0, button_style_1.useStyle)({ color: color || 'primary' }), className: (0, utils_2.clsx)(button_style_1.classes.root, props.className), onPointerUp: onPointerUp, onClick: onClick, "data-variant": variant, "data-orientation": orientation, "data-shape": shape, "data-size": size, "data-loading": loading, "data-read-only": readOnly, children: [loading
30
31
  ? actualPrefix
31
- ? (0, jsx_runtime_1.jsx)(loadingIndicator_1.LoadingIndicator, { color: variant === 'filled' ? '#ffffff' : color })
32
- : (0, jsx_runtime_1.jsx)(transitionBase_1.Collapse, { orientation: "horizontal", in: true, children: (0, jsx_runtime_1.jsx)(loadingIndicator_1.LoadingIndicator, { color: variant === 'filled' ? '#ffffff' : color }) })
32
+ ? (0, jsx_runtime_1.jsx)(loadingIndicator_1.LoadingIndicator, { color: reverseTextColor })
33
+ : (0, jsx_runtime_1.jsx)(transitionBase_1.Collapse, { orientation: "horizontal", in: true, children: (0, jsx_runtime_1.jsx)(loadingIndicator_1.LoadingIndicator, { color: reverseTextColor }) })
33
34
  : actualPrefix, !!actualChildren &&
34
35
  (0, jsx_runtime_1.jsx)("div", { className: button_style_1.classes.content, children: actualChildren }), !!suffix &&
35
36
  (0, jsx_runtime_1.jsx)("div", { className: button_style_1.classes.suffix, children: suffix })] }));
@@ -16,9 +16,17 @@ function useStyle({ color }) {
16
16
  return (0, utils_1.useCss)(({ borderRadius, easing, spacing, text, gray }) => {
17
17
  const c = (0, color_1.default)(colorValue);
18
18
  const outlineColor = c.alpha(.4).string();
19
- const light = c.lighten(.1).hex();
20
- const lighter = c.lighten(.15).hex();
21
- const lightest = c.lighten(.2).hex();
19
+ let light, lighter, lightest;
20
+ if (c.hue()) {
21
+ light = c.lighten(.1).hex();
22
+ lighter = c.lighten(.15).hex();
23
+ lightest = c.lighten(.2).hex();
24
+ }
25
+ else {
26
+ light = c.lightness(20).hex();
27
+ lighter = c.lightness(30).hex();
28
+ lightest = c.lightness(60).hex();
29
+ }
22
30
  const darkC = c.darken(.1);
23
31
  const dark = darkC.hex();
24
32
  const defaultStyle = (0, react_1.css) `
@@ -35,16 +35,16 @@ exports.ToggleButton = (({ variant = 'filled', size, color = 'primary', disabled
35
35
  if (items) {
36
36
  return items.map((p, i) => {
37
37
  const itemValue = p[primaryKey];
38
- return ((0, jsx_runtime_1.jsx)(button_1.Button, { ref: p.ref, shape: p.shape, prefix: p.prefix, suffix: p.suffix, loading: p.loading, label: p.label, ...makeProps(p, itemValue, (0, utils_1.isSelected)(itemValue, innerValue.current)), children: p.children }, itemValue ?? i));
38
+ return ((0, jsx_runtime_1.jsx)(button_1.Button, { ref: p.ref, shape: p.shape, prefix: p.prefix, suffix: p.suffix, loading: p.loading, label: p.label, ...makeProps(p, itemValue, (0, utils_1.isSelected)(itemValue, innerValue)), children: p.children }, itemValue ?? i));
39
39
  });
40
40
  }
41
41
  return react_1.Children.map(props.children, c => {
42
42
  if ((0, react_1.isValidElement)(c)) {
43
43
  const { props } = c;
44
- return (0, react_1.cloneElement)(c, makeProps(props, props.value, (0, utils_1.isSelected)(props.value, innerValue.current)));
44
+ return (0, react_1.cloneElement)(c, makeProps(props, props.value, (0, utils_1.isSelected)(props.value, innerValue)));
45
45
  }
46
46
  return c;
47
47
  });
48
48
  };
49
- return ((0, jsx_runtime_1.jsx)(flex_1.Flex, { compact: true, ...props, className: (0, utils_1.clsx)(toggleButton_style_1.classes.root, props.className), children: renderItems() }));
49
+ return ((0, jsx_runtime_1.jsx)(flex_1.Flex, { compact: true, ...props, css: toggleButton_style_1.style, className: (0, utils_1.clsx)(toggleButton_style_1.classes.root, props.className), children: renderItems() }));
50
50
  });
@@ -1,3 +1,4 @@
1
1
  export declare const classes: {
2
2
  root: string;
3
3
  };
4
+ export declare const style: () => import("@emotion/react").SerializedStyles;
@@ -1,5 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.classes = void 0;
3
+ exports.style = exports.classes = void 0;
4
4
  const utils_1 = require("../../utils");
5
+ const react_1 = require("@emotion/react");
6
+ const button_style_1 = require("../button/button.style");
5
7
  exports.classes = (0, utils_1.defineInnerClasses)('buttonGroup');
8
+ exports.style = (0, utils_1.defineCss)(({ divider }) => (0, react_1.css) `
9
+ .${button_style_1.classes.root}[data-variant=outlined] {
10
+ border-color: ${divider};
11
+
12
+ &:not(:disabled):not([data-read-only=true]):not([data-loading=true]) {
13
+ &:hover {
14
+ color: inherit;
15
+ }
16
+ }
17
+ }
18
+ `);
@@ -38,7 +38,12 @@ function defineClasses(prefixName, names) {
38
38
  return ret;
39
39
  }
40
40
  function defineInnerClasses(prefixName, names) {
41
- return defineClasses(`CanUI-${prefixName}`, names);
41
+ const prefix = definePrefix('CanUI-' + (0, utils_1.humpToSegmented)(prefixName));
42
+ const ret = { root: prefix() };
43
+ names?.forEach(name => {
44
+ ret[name] = prefix((0, utils_1.humpToSegmented)(name));
45
+ });
46
+ return ret;
42
47
  }
43
48
  /**
44
49
  * 用于定义css,返回一个可调用的函数,可直接传入emotion的css属性
@@ -23,10 +23,11 @@ export const Button = ({ component: Component = 'button', color = 'primary', sha
23
23
  };
24
24
  const actualPrefix = prefix ?? icon;
25
25
  const actualChildren = label ?? props.children;
26
+ const reverseTextColor = variant === 'filled' || variant === 'flatted' ? '#ffffff' : color;
26
27
  return (_jsxs(Component, { ...props, css: useStyle({ color: color || 'primary' }), className: clsx(classes.root, props.className), onPointerUp: onPointerUp, onClick: onClick, "data-variant": variant, "data-orientation": orientation, "data-shape": shape, "data-size": size, "data-loading": loading, "data-read-only": readOnly, children: [loading
27
28
  ? actualPrefix
28
- ? _jsx(LoadingIndicator, { color: variant === 'filled' ? '#ffffff' : color })
29
- : _jsx(Collapse, { orientation: "horizontal", in: true, children: _jsx(LoadingIndicator, { color: variant === 'filled' ? '#ffffff' : color }) })
29
+ ? _jsx(LoadingIndicator, { color: reverseTextColor })
30
+ : _jsx(Collapse, { orientation: "horizontal", in: true, children: _jsx(LoadingIndicator, { color: reverseTextColor }) })
30
31
  : actualPrefix, !!actualChildren &&
31
32
  _jsx("div", { className: classes.content, children: actualChildren }), !!suffix &&
32
33
  _jsx("div", { className: classes.suffix, children: suffix })] }));
@@ -11,9 +11,17 @@ export function useStyle({ color }) {
11
11
  return useCss(({ borderRadius, easing, spacing, text, gray }) => {
12
12
  const c = Color(colorValue);
13
13
  const outlineColor = c.alpha(.4).string();
14
- const light = c.lighten(.1).hex();
15
- const lighter = c.lighten(.15).hex();
16
- const lightest = c.lighten(.2).hex();
14
+ let light, lighter, lightest;
15
+ if (c.hue()) {
16
+ light = c.lighten(.1).hex();
17
+ lighter = c.lighten(.15).hex();
18
+ lightest = c.lighten(.2).hex();
19
+ }
20
+ else {
21
+ light = c.lightness(20).hex();
22
+ lighter = c.lightness(30).hex();
23
+ lightest = c.lightness(60).hex();
24
+ }
17
25
  const darkC = c.darken(.1);
18
26
  const dark = darkC.hex();
19
27
  const defaultStyle = css `
@@ -2,7 +2,7 @@ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
2
2
  import { Children, cloneElement, isValidElement } from 'react';
3
3
  import { Flex } from '../flex';
4
4
  import { clsx, isSelected } from '../../utils';
5
- import { classes } from './toggleButton.style';
5
+ import { classes, style } from './toggleButton.style';
6
6
  import { Button } from '../button';
7
7
  import { useShallowSelection } from '../selectionContext';
8
8
  export const ToggleButton = (({ variant = 'filled', size, color = 'primary', disabled, readOnly, items, primaryKey = 'value', multiple, defaultValue, value, onChange, ...props }) => {
@@ -32,16 +32,16 @@ export const ToggleButton = (({ variant = 'filled', size, color = 'primary', dis
32
32
  if (items) {
33
33
  return items.map((p, i) => {
34
34
  const itemValue = p[primaryKey];
35
- return (_jsx(Button, { ref: p.ref, shape: p.shape, prefix: p.prefix, suffix: p.suffix, loading: p.loading, label: p.label, ...makeProps(p, itemValue, isSelected(itemValue, innerValue.current)), children: p.children }, itemValue ?? i));
35
+ return (_jsx(Button, { ref: p.ref, shape: p.shape, prefix: p.prefix, suffix: p.suffix, loading: p.loading, label: p.label, ...makeProps(p, itemValue, isSelected(itemValue, innerValue)), children: p.children }, itemValue ?? i));
36
36
  });
37
37
  }
38
38
  return Children.map(props.children, c => {
39
39
  if (isValidElement(c)) {
40
40
  const { props } = c;
41
- return cloneElement(c, makeProps(props, props.value, isSelected(props.value, innerValue.current)));
41
+ return cloneElement(c, makeProps(props, props.value, isSelected(props.value, innerValue)));
42
42
  }
43
43
  return c;
44
44
  });
45
45
  };
46
- return (_jsx(Flex, { compact: true, ...props, className: clsx(classes.root, props.className), children: renderItems() }));
46
+ return (_jsx(Flex, { compact: true, ...props, css: style, className: clsx(classes.root, props.className), children: renderItems() }));
47
47
  });
@@ -1,3 +1,4 @@
1
1
  export declare const classes: {
2
2
  root: string;
3
3
  };
4
+ export declare const style: () => import("@emotion/react").SerializedStyles;
@@ -1,2 +1,15 @@
1
- import { defineInnerClasses } from '../../utils';
1
+ import { defineCss, defineInnerClasses } from '../../utils';
2
+ import { css } from '@emotion/react';
3
+ import { classes as buttonClasses } from '../button/button.style';
2
4
  export const classes = defineInnerClasses('buttonGroup');
5
+ export const style = defineCss(({ divider }) => css `
6
+ .${buttonClasses.root}[data-variant=outlined] {
7
+ border-color: ${divider};
8
+
9
+ &:not(:disabled):not([data-read-only=true]):not([data-loading=true]) {
10
+ &:hover {
11
+ color: inherit;
12
+ }
13
+ }
14
+ }
15
+ `);
@@ -22,7 +22,12 @@ export function defineClasses(prefixName, names) {
22
22
  return ret;
23
23
  }
24
24
  export function defineInnerClasses(prefixName, names) {
25
- return defineClasses(`CanUI-${prefixName}`, names);
25
+ const prefix = definePrefix('CanUI-' + humpToSegmented(prefixName));
26
+ const ret = { root: prefix() };
27
+ names?.forEach(name => {
28
+ ret[name] = prefix(humpToSegmented(name));
29
+ });
30
+ return ret;
26
31
  }
27
32
  /**
28
33
  * 用于定义css,返回一个可调用的函数,可直接传入emotion的css属性