【发布时间】:2021-01-21 11:24:24
【问题描述】:
在此代码中,有两张卡片,当点击卡片时,它将被标记为选中。点击卡片,点击下一步按钮时,它将根据所选卡片重定向。
在此代码中,当单击一张卡片时,它同时被选中,这也是一个问题。只有点击按钮才会重定向到所选卡片的页面。
用于三个页面的路由:CardSelectOptionPage、SuccessPage、FailurePage。
UI 设计:Antd 设计。
这里是代码沙盒链接:https://codesandbox.io/s/select-card-moloe?file=/src/index.js
import { Button, Card, Col, Image, Row, Typography } from "antd";
import React, { useState } from "react";
import { icons } from "../assets/icons";
import "./CardSelectOption.scss";
const CardSelectOption = () => {
const [clicked, setClicked] = useState(false);
const chooseOptions = [
{
title: "Yes",
description: "I need to redirect into one Page (Successfull Page)",
icon: clicked ? icons.check : icons.EmptyBox,
},
{
title: "No",
description: "I need to redirect into another Page (UnSuccessfull Page)",
icon: clicked ? icons.check : icons.EmptyBox,
},
];
return (
<Row className="select_page_container">
<Col xl={18} md={18} sm={24} xs={24} className="select_page_header">
<h1>Select One Option</h1>
</Col>
<Row className="select_card_section">
{chooseOptions.map((option, index) => (
<Col xl={8} lg={8} sm={24} key={index} className="select_cards">
<Card onClick={() => setClicked(!clicked)} className="card">
<Row className="card_body">
<Col xl={7} lg={6} md={6} sm={24} xs={24} className="icon_part">
<Image src={option.icon} preview={false} />
</Col>
<Col xl={17} md={18} sm={24} xs={24} className="card_content">
<Col xl={16} lg={16} md={16} className="title">
<Typography.Title level={4}>
{option.title}
</Typography.Title>
</Col>
<Col xl={22} md={22} sm={24} xs={24} className="description">
<Typography.Text>{option.description}</Typography.Text>
</Col>
</Col>
</Row>
</Card>
</Col>
))}
</Row>
<Col xl={12} md={12} sm={24} xs={24} className="submit_button">
<Button size="large" type="primary">
Next
</Button>
</Col>
</Row>
);
};
export default CardSelectOption;
【问题讨论】:
标签: javascript reactjs react-router antd