Skip to content

Commit 8a39820

Browse files
committed
radio-group
1 parent 68cc2c3 commit 8a39820

10 files changed

Lines changed: 167 additions & 0 deletions

File tree

projects/daisyui/extension/component.index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ export { logicGroupFGC } from './logic-group';
1111
export { DockTabNFCC } from './dock-tab';
1212
export { SearchFGC } from './search-group';
1313
export { TableFGC } from './table-group';
14+
export { RadioFGC } from './radio-group';
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<ng-template #templateRef let-attr="attributes">
2+
<div [class]="radioClass()">
3+
@for (item of children$$(); track $index) {
4+
<span [class]="radioClass()">
5+
@let id = name + '-' + $index;
6+
<input
7+
type="radio"
8+
[name]="name"
9+
[disabled]="item.form.control!.disabled || field$$().form.control?.disabled$$()"
10+
[checked]="$index === activatedIndex()"
11+
(change)="changeIndex($index)"
12+
[attributes]="attr()"
13+
[excludes]="['class']"
14+
[class]="attr()?.class | mergeClass: ('radio' | cssPrefix)"
15+
[id]="id"
16+
/>
17+
@let props = item.props();
18+
<label
19+
[for]="id"
20+
[class]="!!props['description'] ? ('tooltip' | cssPrefix) : undefined"
21+
[attr.data-tip]="props['description']!"
22+
>{{ props['title'] }}
23+
</label>
24+
</span>
25+
}
26+
</div>
27+
@let activeItem = children$$()[activatedIndex()];
28+
<ng-container
29+
*ngTemplateOutlet="fieldTemplateRef; context: { $implicit: activeItem }"
30+
></ng-container>
31+
</ng-template>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { NgTemplateOutlet } from '@angular/common';
2+
import {
3+
Component,
4+
computed,
5+
effect,
6+
inject,
7+
input,
8+
linkedSignal,
9+
model,
10+
viewChild,
11+
} from '@angular/core';
12+
import { SelectorlessOutlet } from '@cyia/ngx-common/directive';
13+
import { PurePipe } from '@cyia/ngx-common/pipe';
14+
import { StrOrTemplateComponent } from '@piying-lib/angular-core';
15+
import { CssPrefixPipe, MergeClassPipe } from '@piying-lib/angular-daisyui/pipe';
16+
import { ThemeService, useTwClass } from '@piying-lib/angular-daisyui/service';
17+
import { Size } from '@piying-lib/angular-core';
18+
import { AttributesDirective, PiyingViewGroupBase } from '@piying/view-angular';
19+
import { FieldLogicGroup } from '@piying/view-angular-core';
20+
/**
21+
* 标签页组
22+
*
23+
* 用于将表单字段组织成多标签页切换展示,支持多种标签样式和位置布局。
24+
* 适合字段较多需要分类管理、多配置项分页展示的场景,如系统设置、表单分组等。
25+
*/
26+
@Component({
27+
selector: 'app-radio-fgc',
28+
templateUrl: './component.html',
29+
imports: [NgTemplateOutlet, AttributesDirective, CssPrefixPipe, MergeClassPipe, PurePipe],
30+
})
31+
export class RadioFGC extends PiyingViewGroupBase {
32+
static __version = 2;
33+
34+
static index = 0;
35+
templateRef = viewChild.required('templateRef');
36+
readonly StrOrTemplateComponent = StrOrTemplateComponent;
37+
38+
name = `pc-radio-${RadioFGC.index++}`;
39+
/** 当前激活的标签页索引 */
40+
activatedIndex = model(0);
41+
radioClass = input(useTwClass('pb-4'));
42+
/** 切换前的回调函数 */
43+
beforeChange = input<(index: number) => any>();
44+
45+
isUnion$$ = computed(() => {
46+
return (
47+
this.field$$().form.control instanceof FieldLogicGroup &&
48+
(this.field$$().form.control as FieldLogicGroup).type() === 'or'
49+
);
50+
});
51+
52+
labelInputs = (input: any) => {
53+
return {
54+
content: input,
55+
};
56+
};
57+
constructor() {
58+
super();
59+
effect(() => {
60+
if (this.isUnion$$()) {
61+
const index = this.activatedIndex();
62+
const control = this.field$$().form.control as FieldLogicGroup;
63+
control.activateIndex$.set(index);
64+
}
65+
});
66+
}
67+
changeIndex(index: number) {
68+
if (this.beforeChange()) {
69+
this.beforeChange()!(index);
70+
}
71+
this.activatedIndex.set(index);
72+
}
73+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './component';

projects/daisyui/preset/define.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,17 @@ export const PresetDefine = {
181181
},
182182
'readonly-value': {
183183
type: FCCGroup.ReadonlyValueFCC,
184+
actions: [actions.wrappers.set(['label-wrapper'])],
184185
},
185186
'table-group': {
186187
type: ExtComponentGroup.TableFGC,
187188
},
188189
union: {
189190
type: FGCGroup.TabsFGC,
190191
},
192+
'radio-group': {
193+
type: ExtComponentGroup.RadioFGC,
194+
},
191195
},
192196
wrappers: {
193197
// 默认包装器

src/app/const/example.router.define.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { PickerRefDefine } from '@@py/page/component/extension/picker-ref';
55
import { FieldGlobalConfig } from '@@piying-define';
66
import { FunctionLoginDefine } from '../piying/page/component/function/login';
77
import { EditableGroupDefine } from '@@py/page/component/extension/editable-group';
8+
9+
import { RadioGroupDefine } from '@@py/page/component/extension/radio-group';
810
import { MenuTreeDefine } from '@@py/page/component/extension/menu-tree';
911
import { PaginationDefine } from '@@py/page/component/extension/pagination';
1012
import { CheckboxDefine } from '@@py/page/component/field-control/checkbox';
@@ -613,6 +615,20 @@ export const ExampleExtensionRouterConfig = [
613615
},
614616
},
615617
},
618+
{
619+
config: {
620+
title: 'radio-group',
621+
router: { routerLink: './example/extension/radio-group' },
622+
},
623+
define: {
624+
path: 'radio-group',
625+
component: SchemaViewPage,
626+
data: {
627+
schema: () => RadioGroupDefine,
628+
options: () => options,
629+
},
630+
},
631+
},
616632
{
617633
config: {
618634
title: 'menu-tree',
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import * as v from 'valibot';
2+
import { actions, setComponent } from '@piying/view-angular-core';
3+
import { safeDefine } from '@@piying-define';
4+
export default v.pipe(
5+
v.tuple([
6+
v.pipe(
7+
v.union([
8+
v.pipe(
9+
v.object({
10+
k1: v.pipe(v.string(), actions.attributes.patch({ placeholder: 'k1-value' })),
11+
}),
12+
v.title('选择1'),
13+
),
14+
v.pipe(
15+
v.object({
16+
k2: v.pipe(v.string(), actions.attributes.patch({ placeholder: 'k2-value' })),
17+
}),
18+
v.title('选择2'),
19+
),
20+
]),
21+
setComponent('radio-group'),
22+
actions.wrappers.patch(['div']),
23+
),
24+
]),
25+
actions.wrappers.patch(['div']),
26+
actions.class.top('flex gap-4'),
27+
);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import define from './content';
2+
import content from './content?text';
3+
import title from './content?title';
4+
export const Base = {
5+
define: define,
6+
content: content,
7+
title: title,
8+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './base';
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as Group from './example';
2+
3+
import { createCodeExampleObject } from '@@py/util/create-code-example-object';
4+
5+
export const RadioGroupDefine = createCodeExampleObject(Group);

0 commit comments

Comments
 (0)