📅  最后修改于: 2023-12-03 15:19:46.341000             🧑  作者: Mango
ReactJS 蓝图选项卡组件可以帮助程序员快速构建Web应用程序中常见的选项卡功能,使得应用更加直观和易于使用。
npm install react-blueprint-tabs
import React, { useState } from 'react';
import Tabs from 'react-blueprint-tabs';
const MyComponent = () => {
const [selectedTab, setSelectedTab] = useState(0);
const tabs = [
{ title: 'Tab 1', content: <div>Content for tab 1</div> },
{ title: 'Tab 2', content: <div>Content for tab 2</div> },
{ title: 'Tab 3', content: <div>Content for tab 3</div> },
];
return (
<Tabs
tabs={tabs}
selectedTab={selectedTab}
onSelectTab={setSelectedTab}
/>
);
};
export default MyComponent;
tabs
: 一个包含选项卡标题和内容的数组。selectedTab
: 当前选中的选项卡索引。onSelectTab
: 选项卡发生切换时的回调函数。className
: 选项卡组件的CSS类名。tabClassName
: 选项卡标签的CSS类名。tabActiveClassName
: 选项卡标签选中时的CSS类名。tabContentClassName
: 选项卡内容的CSS类名。tabPanelClassName
: 选项卡面板(标签和内容)的CSS类名。trigger
: 选项卡内容的触发方式,可以是'click'或者'mouseover'。animation
: 选项卡内容切换时的动画效果,可以是'slide'或者'fade'。animationDuration
: 动画效果的持续时间(以毫秒为单位)。import React, { useState } from 'react';
import Tabs from 'react-blueprint-tabs';
const MyComponent = () => {
const [selectedTab, setSelectedTab] = useState(0);
const tabs = [
{ title: 'Tab 1', content: <div>Content for tab 1</div> },
{ title: 'Tab 2', content: <div>Content for tab 2</div> },
{ title: 'Tab 3', content: <div>Content for tab 3</div> },
];
const tabStyles = {
backgroundColor: '#7192b1',
color: '#fff',
padding: '10px 20px',
fontWeight: 700,
};
return (
<Tabs
tabs={tabs}
selectedTab={selectedTab}
onSelectTab={setSelectedTab}
className="my-tabs"
tabClassName="my-tab"
tabActiveClassName="my-tab-active"
tabContentClassName="my-tab-content"
tabPanelClassName="my-tab-panel"
trigger="click"
animation="fade"
animationDuration={300}
style={tabStyles}
/>
);
};
export default MyComponent;
import React, { useState } from 'react';
import Tabs from 'react-blueprint-tabs';
const MyComponent = () => {
const [selectedTab, setSelectedTab] = useState(0);
const tabs = [
{ title: 'Tab 1', content: <div>Content for tab 1</div> },
{ title: 'Tab 2', content: <div>Content for tab 2</div> },
{ title: 'Tab 3', content: <div>Content for tab 3</div> },
];
const handleSelectTab = (index) => {
console.log(`Tab ${index + 1} selected!`);
setSelectedTab(index);
};
return (
<Tabs
tabs={tabs}
selectedTab={selectedTab}
onSelectTab={handleSelectTab}
trigger="mouseover"
/>
);
};
export default MyComponent;