plain-design 1.0.0-beta.152 → 1.0.0-beta.154

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plain-design",
3
- "version": "1.0.0-beta.152",
3
+ "version": "1.0.0-beta.154",
4
4
  "description": "",
5
5
  "main": "dist/plain-design.min.js",
6
6
  "module": "dist/plain-design.commonjs.min.js",
@@ -0,0 +1,53 @@
1
+ import $dialog from "../$dialog";
2
+ import ImageSelector, {iImageSelectOption} from "../ImageSelector";
3
+ import {iDialogServiceOption} from "../useDialog/dialog.service.utils";
4
+ import $message from "../$message";
5
+ import i18n from "../i18n";
6
+
7
+ export const $imageSelector = (
8
+ {
9
+ selectOptions,
10
+ selectValue,
11
+ dialogServiceOption,
12
+ handleConfirm,
13
+ title,
14
+ aspectRatio,
15
+ imageFit,
16
+ }: {
17
+ title?: string,
18
+ selectOptions: iImageSelectOption[],
19
+ selectValue?: any,
20
+ dialogServiceOption?: iDialogServiceOption,
21
+ handleConfirm?: (selectValue: string, selectOption: iImageSelectOption) => void | boolean | Promise<void | boolean>,
22
+ aspectRatio?: string,
23
+ imageFit?: string,
24
+ }
25
+ ) => {
26
+ const _handleConfirm = async () => {
27
+ if (!selectValue) {
28
+ $message.error(i18n.$it('base.pleaseSelect').d('请选择'));
29
+ return false;
30
+ }
31
+ const flag = await handleConfirm?.(selectValue, selectOptions.find(i => i.val === selectValue)!);
32
+ if (flag !== false) {close();}
33
+ };
34
+ const close = $dialog({
35
+ title,
36
+ width: 800,
37
+ render: () => <ImageSelector
38
+ imageFit={imageFit}
39
+ modelValue={selectValue}
40
+ onUpdateModelValue={val => selectValue = val}
41
+ selectOptions={selectOptions}
42
+ aspectRatio={aspectRatio}
43
+ onDoubleClickOption={() => {_handleConfirm();}}
44
+ />,
45
+ confirmButton: true,
46
+ cancelButton: true,
47
+ handleConfirm: () => {
48
+ _handleConfirm();
49
+ return false;
50
+ },
51
+ ...dialogServiceOption,
52
+ });
53
+ };
@@ -0,0 +1,70 @@
1
+ @include comp(image-selector) {
2
+ $num: 3;
3
+ $gutter: 1em;
4
+
5
+ .image-select-option {
6
+ display: inline-flex;
7
+ margin-right: $gutter;
8
+ margin-bottom: $gutter;
9
+ border: solid 2px plv(border-color);
10
+ padding: 10px;
11
+ box-sizing: border-box;
12
+ position: relative;
13
+
14
+ width: calc((100% - (#{$gutter} * (#{$num} - 1))) / #{$num});
15
+ aspect-ratio: var(--aspect-ratio);
16
+ overflow: hidden;
17
+ cursor: pointer;
18
+ transition: all ease 300ms;
19
+
20
+ .image-select-option-checked {
21
+ position: absolute;
22
+ bottom: 0;
23
+ right: 0;
24
+ height: 36px;
25
+ width: 36px;
26
+ display: flex;
27
+ align-items: flex-end;
28
+ justify-content: flex-end;
29
+ color: white;
30
+ opacity: 0;
31
+ transition: all ease 300ms;
32
+
33
+ &:before {
34
+ position: absolute;
35
+ inset: 0;
36
+ content: '';
37
+ background-color: plv(primary-6);
38
+ transform: translateX(50%) translateY(50%) rotate(45deg);
39
+ transform-origin: center;
40
+ z-index: 1;
41
+ }
42
+
43
+ & > .#{componentName(icon)} {
44
+ z-index: 2;
45
+ transform: rotate(-4.5deg);
46
+ }
47
+ }
48
+
49
+ & > img {
50
+ width: 100%;
51
+ aspect-ratio: inherit;
52
+ }
53
+
54
+ &:nth-child(#{$num}n) {
55
+ margin-right: 0;
56
+ }
57
+
58
+ &:hover {
59
+ border-color: plv(primary-3);
60
+ }
61
+
62
+ &[data-selected=true] {
63
+ border-color: plv(primary-6);
64
+
65
+ .image-select-option-checked {
66
+ opacity: 1;
67
+ }
68
+ }
69
+ }
70
+ }
@@ -0,0 +1,52 @@
1
+ import {designComponent, getComponentCls, iMouseEvent, PropType, useModel} from "@peryl/react-compose";
2
+ import {Scroll} from "../Scroll";
3
+ import {Box} from "../Box";
4
+ import {Icon} from "../Icon";
5
+ import {Image} from "../Image";
6
+ import './image-selector.scss';
7
+
8
+ export const ImageSelector = designComponent({
9
+ name: 'image-selector',
10
+ props: {
11
+ modelValue: { type: [String, Number] },
12
+ selectOptions: { type: Array as PropType<iImageSelectOption[]> },
13
+ aspectRatio: { type: String, default: '3 / 4' },
14
+ imageFit: { type: String, default: 'contain' }
15
+ },
16
+ emits: {
17
+ onUpdateModelValue: (val?: string | number | null | undefined) => true,
18
+ onDoubleClickOption: (e: iMouseEvent) => true,
19
+ },
20
+ setup({ props, event: { emit } }) {
21
+
22
+ const model = useModel(() => props.modelValue, emit.onUpdateModelValue);
23
+
24
+ return () => (
25
+ <div className={getComponentCls('image-selector')} style={{ '--aspect-ratio': props.aspectRatio } as any}>
26
+ <Scroll>
27
+ {props.selectOptions?.map(item => (
28
+ <Box
29
+ className="image-select-option"
30
+ key={item.val}
31
+ data-selected={String(model.value === item.val)}
32
+ onClick={() => {model.value = item.val;}}
33
+ onDoubleClick={emit.onDoubleClickOption}
34
+ >
35
+ <Image src={item.url} previewOnClick={false} fit={props.imageFit as any} position="center left"/>
36
+ <div className="image-select-option-checked">
37
+ <Icon icon="pi-check"/>
38
+ </div>
39
+ </Box>
40
+ ))}
41
+ </Scroll>
42
+ </div>
43
+ );
44
+ },
45
+ });
46
+
47
+ export default ImageSelector;
48
+
49
+ export interface iImageSelectOption {
50
+ val: string,
51
+ url: string
52
+ }
@@ -140,7 +140,9 @@ export type {iChatBoxHistory} from './components/AiChatBox';
140
140
  export {$ai} from './components/$ai';
141
141
  export type {iAiChoice, iAiChatResponse, iAiConfiguration, iAiHistory} from './components/$ai';
142
142
  export {IconPicker} from './components/IconPicker';
143
- export {Skeleton} from './components/Skeleton'
143
+ export {Skeleton} from './components/Skeleton';
144
+ export {ImageSelector} from './components/ImageSelector';
145
+ export {$imageSelector} from './components/$imageSelector';
144
146
 
145
147
  export {VirtualTable} from './components/VirtualTable';
146
148
  export {Table} from './components/Table';