plain-design 1.0.0-beta.151 → 1.0.0-beta.153

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.151",
3
+ "version": "1.0.0-beta.153",
4
4
  "description": "",
5
5
  "main": "dist/plain-design.min.js",
6
6
  "module": "dist/plain-design.commonjs.min.js",
@@ -0,0 +1,44 @@
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
+ }: {
16
+ title?: string,
17
+ selectOptions: iImageSelectOption[],
18
+ selectValue?: any,
19
+ dialogServiceOption?: iDialogServiceOption,
20
+ handleConfirm?: (selectValue: string, selectOption: iImageSelectOption) => void | boolean | Promise<void | boolean>,
21
+ aspectRatio?: string,
22
+ }
23
+ ) => {
24
+ $dialog({
25
+ title,
26
+ width: 800,
27
+ render: () => <ImageSelector
28
+ modelValue={selectValue}
29
+ onUpdateModelValue={val => selectValue = val}
30
+ selectOptions={selectOptions}
31
+ aspectRatio={aspectRatio}
32
+ />,
33
+ confirmButton: true,
34
+ cancelButton: true,
35
+ handleConfirm: async () => {
36
+ if (!selectValue) {
37
+ $message.error(i18n.$it('base.pleaseSelect').d('请选择'));
38
+ return false;
39
+ }
40
+ return handleConfirm?.(selectValue, selectOptions.find(i => i.val === selectValue)!);
41
+ },
42
+ ...dialogServiceOption,
43
+ });
44
+ };
@@ -288,6 +288,9 @@ div.#{componentName(image)} {
288
288
  span {
289
289
  color: plv(text-2);
290
290
  font-size: 12px;
291
+ transform: scale(0.8);
292
+ transform-origin: center;
293
+ white-space: nowrap;
291
294
  }
292
295
 
293
296
  &.image-status-pending {
@@ -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,49 @@
1
+ import {designComponent, getComponentCls, 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
+ },
15
+ emits: {
16
+ onUpdateModelValue: (val?: string | number | null | undefined) => true,
17
+ },
18
+ setup({ props, event: { emit } }) {
19
+
20
+ const model = useModel(() => props.modelValue, emit.onUpdateModelValue);
21
+
22
+ return () => (
23
+ <div className={getComponentCls('image-selector')} style={{ '--aspect-ratio': props.aspectRatio } as any}>
24
+ <Scroll>
25
+ {props.selectOptions?.map(item => (
26
+ <Box
27
+ className="image-select-option"
28
+ key={item.val}
29
+ data-selected={String(model.value === item.val)}
30
+ onClick={() => {model.value = item.val;}}
31
+ >
32
+ <Image src={item.url} previewOnClick={false} fit="cover" position="top left"/>
33
+ <div className="image-select-option-checked">
34
+ <Icon icon="pi-check"/>
35
+ </div>
36
+ </Box>
37
+ ))}
38
+ </Scroll>
39
+ </div>
40
+ );
41
+ },
42
+ });
43
+
44
+ export default ImageSelector;
45
+
46
+ export interface iImageSelectOption {
47
+ val: string,
48
+ url: string
49
+ }
@@ -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';