update 7 files

master
amir hosein gorji 3 years ago
parent 2a74360a2d
commit 54319326bb
  1. 1
      package.json
  2. 70
      src/components/ReactTable3/BasicTable.js
  3. 24
      src/components/ReactTable3/Buttons.js
  4. 3
      src/components/ReactTable3/columns.js
  5. 76
      src/components/ReactTable3/index.js
  6. 10
      src/components/ReactTable3/index.scss
  7. 15407
      yarn.lock

@ -25,6 +25,7 @@
"sass": "^1.45.0", "sass": "^1.45.0",
"sweetalert2": "^11.3.4", "sweetalert2": "^11.3.4",
"tw-elements": "^1.0.0-alpha8", "tw-elements": "^1.0.0-alpha8",
"use-draggable-scroll": "^0.1.0",
"web-vitals": "^2.1.2" "web-vitals": "^2.1.2"
}, },
"scripts": { "scripts": {

@ -11,7 +11,7 @@ import {
useRowSelect, useRowSelect,
useColumnOrder, useColumnOrder,
useExpanded, useExpanded,
useResizeColumns useResizeColumns,
} from "react-table"; } from "react-table";
import { COLUMNS } from "./columns"; import { COLUMNS } from "./columns";
@ -24,14 +24,13 @@ import MOCK_DATA from "./MOCK_DATA.json";
export function SelectColumnFilter({ export function SelectColumnFilter({
column: { filterValue, setFilter, preFilteredRows, id, render }, column: { filterValue, setFilter, preFilteredRows, id, render },
}) { }) {
const options = React.useMemo(() => { const options = React.useMemo(() => {
const options = new Set() const options = new Set();
preFilteredRows.forEach(row => { preFilteredRows.forEach((row) => {
options.add(row.values[id]) options.add(row.values[id]);
}) });
return [...options.values()] return [...options.values()];
}, [id, preFilteredRows]) }, [id, preFilteredRows]);
// Render a multi-select box // Render a multi-select box
return ( return (
@ -42,43 +41,33 @@ export function SelectColumnFilter({
name={id} name={id}
id={id} id={id}
value={filterValue} value={filterValue}
onChange={e => { onChange={(e) => {
setFilter(e.target.value || undefined) setFilter(e.target.value || undefined);
}} }}
> >
<option className="text-xs" value="">همه</option> <option className="text-xs" value="">
همه
</option>
{options.map((option, i) => ( {options.map((option, i) => (
<option key={i} value={option} className="text-xs"> <option key={i} value={option} className="text-xs">
{(() => { {(() => {
if (option === 1) { if (option === 1) {
return ( return "وضعیت عادی";
"وضعیت عادی"
);
} else if (option === 2) { } else if (option === 2) {
return ( return "اعلان سطح هشدار";
"اعلان سطح هشدار"
);
} else if (option === 3) { } else if (option === 3) {
return ( return "بررسی و پیگیری";
"بررسی و پیگیری"
);
} else if (option === 4) { } else if (option === 4) {
return ( return "وضعیت بحرانی";
"وضعیت بحرانی"
);
} else { } else {
return ( return " وضعیت پایدار";
" وضعیت پایدار"
);
} }
})()}{" "} })()}{" "}
</option> </option>
))} ))}
</select> </select>
</label> </label>
) );
} }
const BasicTable = () => { const BasicTable = () => {
@ -232,7 +221,6 @@ const BasicTable = () => {
{">>"} {">>"}
</button> </button>
</div> </div>
</div> </div>
{/* */} {/* */}
{/* toggle columns */} {/* toggle columns */}
@ -286,7 +274,9 @@ const BasicTable = () => {
{page.map((row, idx) => { {page.map((row, idx) => {
prepareRow(row); prepareRow(row);
return ( return (
<tr {...row.getRowProps()} <React.Fragment>
<tr
{...row.getRowProps()}
// className={isEven(idx) ? "bg-gray-600" : "bg-white"} // className={isEven(idx) ? "bg-gray-600" : "bg-white"}
> >
{row.cells.map((cell) => { {row.cells.map((cell) => {
@ -302,6 +292,14 @@ const BasicTable = () => {
); );
})} })}
</tr> </tr>
{row.isExpanded ? (
<tr>
<td colSpan={headerGroups[0].headers.length}>
{renderRowSubComponent({ row: row.values })}
</td>
</tr>
) : null}
</React.Fragment>
); );
})} })}
</tbody> </tbody>
@ -372,5 +370,13 @@ const BasicTable = () => {
</> </>
); );
}; };
function renderRowSubComponent({ row }) {
return (
<div className="pl-2 pr-5 bg-blue-200">
نام: {row.name}
<br />
<button className="bg-blue-400">ویرایش</button>
</div>
);
}
export default BasicTable; export default BasicTable;

@ -1,20 +1,26 @@
import arrowIcon from './arrow-icon.svg'; import arrowIcon from "./arrow-icon.svg";
import more from './more.svg'; import more from "./more.svg";
import edit from './edit.svg'; import edit from "./edit.svg";
import { useState } from 'react'; import { useState } from "react";
export function Buttons({ row }) {
export function Buttons({ }) {
const [activeDetails, setActiveDetails] = useState(null); const [activeDetails, setActiveDetails] = useState(null);
return ( return (
<div className="flex flex-row items-center justify-end"> <div className="flex flex-row items-center justify-end">
<button <button
className="flex flex-row items-center justify-around p-2 rounded border border-gray-300 mx-1" className="flex flex-row items-center justify-around p-2 rounded border border-gray-300 mx-1"
onClick={ () => setActiveDetails(!activeDetails) }> onClick={() => setActiveDetails(!activeDetails)}
{...row.getToggleRowExpandedProps()}
>
جزیات جزیات
<img src={arrowIcon} alt="" className={`w-3 cursor-pointer mr-2 ${activeDetails ? "rotate-60" : "rotate-90"}`} /> <img
src={arrowIcon}
alt=""
className={`w-3 cursor-pointer mr-2 ${
activeDetails ? "rotate-60" : "rotate-90"
}`}
/>
</button> </button>
<div className="p-2 rounded border border-gray-300 cursor-pointer mx-1"> <div className="p-2 rounded border border-gray-300 cursor-pointer mx-1">
<img src={edit} alt="" className="w-4" /> <img src={edit} alt="" className="w-4" />

@ -10,7 +10,6 @@ import { Buttons } from "./Buttons";
import { EditButtons } from "./EditButtons"; import { EditButtons } from "./EditButtons";
export const COLUMNS = [ export const COLUMNS = [
{ {
Header: "نام و نام خانوادگی", Header: "نام و نام خانوادگی",
Footer: "نام و نام خانوادگی", Footer: "نام و نام خانوادگی",
@ -52,7 +51,7 @@ export const COLUMNS = [
Footer: "سطح اهمیت", Footer: "سطح اهمیت",
accessor: "order-level", accessor: "order-level",
Cell: OrderLevel, Cell: OrderLevel,
Filter: SelectColumnFilter, // Filter: SelectColumnFilter,
// new // new
}, },
{ {

@ -1,5 +1,6 @@
import React from "react"; import React, { useRef } from "react";
import BasicTable from "./BasicTable"; import BasicTable from "./BasicTable";
// import useDraggableScroll from "use-draggable-scroll";
const ReactTable3 = ({ breadCrumbs, subTitle, title }) => { const ReactTable3 = ({ breadCrumbs, subTitle, title }) => {
return ( return (
@ -40,13 +41,82 @@ const ReactTable3 = ({ breadCrumbs, subTitle, title }) => {
<h2 className="text-sm">{subTitle}</h2> <h2 className="text-sm">{subTitle}</h2>
</div> </div>
</div> </div>
<Tabbar />
<BasicTable /> <BasicTable />
</div> </div>
); );
}; };
window.isDown = false;
export default ReactTable3; export default ReactTable3;
function Tabbar({}) {
const ref = useRef(null);
// const { onMouseDown } = useDraggableScroll(ref);
const tabs = [
"تست۱",
"تست۱",
"تست۱",
"تست۱",
"تست۱",
"تست۱",
"تست۱",
"تست۱",
"تست۱",
"تست۱",
"تست۱",
"تست۱",
"تست۱",
"تست۱",
"تست۱",
"تست۱",
"تست۱",
"تست۱",
"تست۱",
"تست۱",
];
return (
<ul
className="tabbar flex no-scrollbar border-b border-gray-200 dark:border-gray-700 overflow-x-scroll scrolling-touch"
onMouseDown={(e) => {
const slider = window.document.querySelector(".tabbar");
window.isDown = true;
window.startX = e.pageX - slider.offsetLeft;
window.scrollLeft = slider.scrollLeft;
}}
onMouseLeave={(e) => {
window.isDown = false;
}}
onMouseUp={(e) => {
window.isDown = false;
}}
onMouseMove={(e) => {
const slider = window.document.querySelector(".tabbar");
if (!window.isDown) return;
e.preventDefault();
const x = e.pageX - slider.offsetLeft;
const walk = (x - window.startX) * 1;
slider.scrollLeft = window.scrollLeft - walk;
}}
>
{tabs.map((el) => (
<li className="mr-2 ">
<span
onClick={(e) => {
if (window.isDown) return e.preventDefault();
///do here
}}
aria-current="page"
className="inline-block py-4 px-4 text-sm font-medium text-center text-blue-600 bg-gray-100 rounded-t-lg active dark:bg-gray-800 dark:text-blue-500"
>
<span className="p-2">
{el} <span className="p-2">x</span>
</span>
</span>
</li>
))}
</ul>
);
}
ReactTable3.defaultProps = { ReactTable3.defaultProps = {
breadCrumbs: [ breadCrumbs: [

@ -4,3 +4,13 @@
.customeClass1 .customeClass2 span { .customeClass1 .customeClass2 span {
display: none !important; display: none !important;
} }
.no-scrollbar {
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
}
.tabbar{
cursor: pointer;
}
.active2 ,.active2 li a{
cursor: move !important;
}

15407
yarn.lock

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save