Skip to content

Commit

Permalink
feat: radio 适配微信 (#989)
Browse files Browse the repository at this point in the history
* feat: radio 适配微信

* feat: radio 适配微信

* feat: radio 适配微信

---------

Co-authored-by: DiamondYuan <fandi.yfd@antgroup.com>
  • Loading branch information
DiamondYuan and DiamondYuan authored Dec 19, 2023
1 parent 9763cff commit 1cec707
Show file tree
Hide file tree
Showing 41 changed files with 655 additions and 74 deletions.
2 changes: 1 addition & 1 deletion compiled/alipay/demo/pages/Radio/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ Page({
this.setData({
checked: checked,
});
}
},
});
46 changes: 23 additions & 23 deletions compiled/alipay/demo/pages/RadioGroup/index.axml
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
<container title="基础用法">
<radio-group
<ant-container title="基础用法">
<ant-radio-group
options="{{ options }}"
onChange="onChange" />
</container>
</ant-container>

<container title="初始值">
<radio-group
<ant-container title="初始值">
<ant-radio-group
defaultValue="banana"
options="{{ options }}"
onChange="onChange" />
</container>
</ant-container>

<container title="横向布局">
<radio-group
<ant-container title="横向布局">
<ant-radio-group
options="{{ options }}"
position="horizontal" />
</container>
</ant-container>

<container title="禁用模式-所有禁用">
<radio-group
<ant-container title="禁用模式-所有禁用">
<ant-radio-group
options="{{ options }}"
disabled />
</container>
</ant-container>

<container title="禁用模式-其中有的禁用">
<radio-group options="{{ optionsWithDisabled }}" />
</container>
<ant-container title="禁用模式-其中有的禁用">
<ant-radio-group options="{{ optionsWithDisabled }}" />
</ant-container>

<container title="控制模式">
<radio-group
value="{{value}}"
<ant-container title="控制模式">
<ant-radio-group
value="{{ value }}"
options="{{ options }}"
onChange="handleChange" />
</container>
</ant-container>

<container title="自定义">
<radio-group
<ant-container title="自定义">
<ant-radio-group
options="{{ options }}"
color="red"
defaultValue="banana">
Expand All @@ -44,5 +44,5 @@
slot-scope="item">
{{ item.index + 1 }} {{ item.value.label }}
</view>
</radio-group>
</container>
</ant-radio-group>
</ant-container>
5 changes: 0 additions & 5 deletions compiled/alipay/demo/pages/RadioGroup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ Page({
onChange: function (value, e) {
console.log(value, e);
},
onSubmit: function (e) {
my.alert({
content: e.detail.value,
});
},
handleChange: function (value) {
this.setData({
value: value,
Expand Down
4 changes: 2 additions & 2 deletions compiled/alipay/demo/pages/RadioGroup/index.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"defaultTitle": "RadioGroup",
"usingComponents": {
"radio-group": "../../../src/Radio/RadioGroup/index",
"container": "../../../src/Container/index"
"ant-radio-group": "../../../src/Radio/RadioGroup/index",
"ant-container": "../../../src/Container/index"
}
}
3 changes: 3 additions & 0 deletions compiled/alipay/src/Radio/RadioGroup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const RadioGroup = (props: IRadioGroupProps) => {
value: props.value,
});
const { triggerEvent } = useComponentEvent(props);


useEvent('onChange', (_, e) => {
const index = e.currentTarget.dataset.index;
const value = props.options[index].value;
Expand All @@ -17,6 +19,7 @@ const RadioGroup = (props: IRadioGroupProps) => {
}
triggerEvent('change', value, e);
});

return {
mixin: {
value,
Expand Down
2 changes: 1 addition & 1 deletion compiled/alipay/src/Radio/index.axml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<view
class="ant-radio-item-fake-{{ componentUtils.getClassName(mixin.value, disabled) }}"
style="{{ mixin.value && !disabled && color ? 'background:' + color : '' }}">
<icon
<ant-icon
a:if="{{ mixin.value }}"
type="CheckOutline"
className="ant-radio-item-fake-{{ componentUtils.getClassName(mixin.value, disabled) }}-icon" />
Expand Down
3 changes: 1 addition & 2 deletions compiled/alipay/src/Radio/index.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"component": true,
"usingComponents": {
"list-item": "../List/ListItem/index",
"icon": "../Icon/index"
"ant-icon": "../Icon/index"
}
}
1 change: 1 addition & 0 deletions compiled/alipay/src/Radio/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
color: @COLOR_TEXT_PRIMARY;
margin-right: 16 * @rpx;


&-container {
display: flex;
align-items: center;
Expand Down
4 changes: 4 additions & 0 deletions compiled/alipay/src/Radio/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ const Radio = (props: IRadioProps) => {

const { triggerEvent } = useComponentEvent(props);


useEvent('onChange', (e) => {
const value = e.detail.value;
if (!isControlled) {
update(value);
}
triggerEvent('change', value, e);
});

return {
mixin: {
value: radioValue,
Expand All @@ -30,7 +32,9 @@ const Radio = (props: IRadioProps) => {
};

mountComponent(Radio, {
value: null,
defaultChecked: null,
color: '',
checked: null,
disabled: false,
});
2 changes: 2 additions & 0 deletions compiled/wechat/app.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"pages": [
"demo/pages/RadioGroup/index",
"demo/pages/Radio/index",
"demo/pages/ImageUploadControl/index",
"demo/pages/ImageUpload/index",
"demo/pages/DatePicker/index",
Expand Down
13 changes: 13 additions & 0 deletions compiled/wechat/demo/pages/Radio/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Page({
data: {
checked: false,
},
onChange: function (value, e) {
console.log(value, e);
},
handleChange: function (checked) {
this.setData({
checked: checked.detail,
});
},
});
8 changes: 8 additions & 0 deletions compiled/wechat/demo/pages/Radio/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"defaultTitle": "Radio",
"usingComponents": {
"radio": "../../../src/Radio/index",
"container": "../../../src/Container/index",
"icon": "../../../src/Icon/index"
}
}
32 changes: 32 additions & 0 deletions compiled/wechat/demo/pages/Radio/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<container title="基础用法">
<radio bind:change="onChange">Radio</radio>
</container>

<container title="初始值">
<radio defaultChecked="{{ true }}">Radio</radio>
</container>

<container title="禁用模式">
<radio disabled>Radio1</radio>
<radio
defaultChecked
disabled>
Radio2
</radio>
</container>

<container title="自定义颜色">
<radio
color="red"
defaultChecked>
Radio
</radio>
</container>

<container title="控制模式">
<radio
checked="{{ checked }}"
bind:change="handleChange">
Radio
</radio>
</container>
Empty file.
24 changes: 24 additions & 0 deletions compiled/wechat/demo/pages/RadioGroup/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Page({
data: {
value: 'banana',
options: [
{ value: 'apple', label: '苹果' },
{ value: 'orange', label: '橘子' },
{ value: 'banana', label: '香蕉' },
],
optionsWithDisabled: [
{ value: 'apple', label: '苹果' },
{ value: 'orange', label: '橘子' },
{ value: 'watermelon', label: '西瓜', disabled: true },
{ value: 'banana', label: '香蕉' },
],
},
onChange: function (value, e) {
console.log(value, e);
},
handleChange: function (value) {
this.setData({
value: value.detail,
});
},
});
7 changes: 7 additions & 0 deletions compiled/wechat/demo/pages/RadioGroup/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"defaultTitle": "RadioGroup",
"usingComponents": {
"ant-radio-group": "../../../src/Radio/RadioGroup/index",
"ant-container": "../../../src/Container/index"
}
}
35 changes: 35 additions & 0 deletions compiled/wechat/demo/pages/RadioGroup/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<ant-container title="基础用法">
<ant-radio-group
options="{{ options }}"
bind:change="onChange" />
</ant-container>

<ant-container title="初始值">
<ant-radio-group
defaultValue="banana"
options="{{ options }}"
bind:change="onChange" />
</ant-container>

<ant-container title="横向布局">
<ant-radio-group
options="{{ options }}"
position="horizontal" />
</ant-container>

<ant-container title="禁用模式-所有禁用">
<ant-radio-group
options="{{ options }}"
disabled />
</ant-container>

<ant-container title="禁用模式-其中有的禁用">
<ant-radio-group options="{{ optionsWithDisabled }}" />
</ant-container>

<ant-container title="控制模式">
<ant-radio-group
value="{{ value }}"
options="{{ options }}"
bind:change="handleChange" />
</ant-container>
18 changes: 18 additions & 0 deletions compiled/wechat/demo/pages/RadioGroup/index.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.icon {
border: 1px solid #CCCCCC;
border-radius: 50vh;
width: 100%;
height: 100%;
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
}
.checked {
background-color: red;
color: #fff;
font-size: 14px;
}
.disabled {
opacity: 0.4;
}
32 changes: 32 additions & 0 deletions compiled/wechat/src/Radio/RadioGroup/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { mountComponent } from '../../_util/component';
import { useMixState } from '../../_util/hooks/useMixState';
import { useEvent } from 'functional-mini/component';
import { useComponentEvent } from '../../_util/hooks/useComponentEvent';
var RadioGroup = function (props) {
var _a = useMixState(props.defaultValue, {
value: props.value,
}), value = _a[0], _b = _a[1], isControlled = _b.isControlled, update = _b.update;
var triggerEvent = useComponentEvent(props).triggerEvent;
useEvent('onChange', function (e) {
var index = e.currentTarget.dataset.index;
var value = props.options[index].value;
if (!isControlled) {
update(value);
}
triggerEvent('change', value, e);
});
return {
mixin: {
value: value,
},
};
};
mountComponent(RadioGroup, {
value: null,
defaultValue: null,
name: '',
disabled: false,
color: '',
position: 'vertical',
options: [],
});
8 changes: 8 additions & 0 deletions compiled/wechat/src/Radio/RadioGroup/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"component": true,
"usingComponents": {
"list": "../../List/index",
"list-item": "../../List/ListItem/index",
"radio": "../index"
}
}
Loading

0 comments on commit 1cec707

Please sign in to comment.