Skip to content

Instantly share code, notes, and snippets.

@dallas-x
Created March 21, 2021 23:45
Show Gist options
  • Select an option

  • Save dallas-x/a8924278193142c43bdc0912074ae4a6 to your computer and use it in GitHub Desktop.

Select an option

Save dallas-x/a8924278193142c43bdc0912074ae4a6 to your computer and use it in GitHub Desktop.
antd table
import React from "react";
import ReactDOM from "react-dom";
import EventsSection from "./EventsSection";
function App() {
return (
<div className="App">
<EventsSection />
</div>
);
}
export default App;
import React, { useState, useContext } from "react";
import EventTable from "./EventTable";
const EventsSection = (events) => {
const [columns, setColumns] = useState(events);
const [modal, setModal] = useState(false);
const updateTable = (selectedColumns) => {
setColumns(selectedColumns);
};
const toggleModal = () => setModal(!modal);
console.log(columns);
return (
<div>
<div className="table">
<button onClick={this.toggleModal}> Modify Table</button>
{modal ? (
<EventTable>
<div>
<h1>Select Columns</h1>
<div className="buttons">
{console.log("buildout some column options")}
<button
onClick={this.updateTable([
{
title: "ID",
dataIndex: "key",
key: "id",
},
{
title: "Title",
dataIndex: "title",
key: "title",
},
{
title: "FirstName",
dataIndex: "firstName",
key: "firstName",
},
{
title: "LastName",
dataIndex: "lastName",
key: "lastName",
},
])}
>
update
</button>
<button onClick={this.toggleModal}>Cancel</button>
</div>
</div>
</EventTable>
) : null}
</div>{" "}
<thead>
<tr>
{columns.map((column) => (
<th key="column"> {column} </th>
))}
</tr>
</thead>
</div>
);
};
export default EventsSection;
import React, { useEffect, useRef } from "react";
import { createPortal } from "react-dom";
const EventTable = ({ children }) => {
const elRef = useRef(null);
if (!elRef.current) {
const div = document.createElement("div");
elRef.current = div;
}
useEffect(() => {
const modalRoot = document.getElementById("modal");
modalRoot.appendChild(elRef.current);
return () => modalRoot.removeChild(elRef.current);
}, []);
return createPortal(<div>{children}</div>, elRef.current);
};
export default EventTable;
import React from "react";
import EventsSection from "./EventsSection";
const eventsData = [
{
key: 1,
title: "Bulletproof EP1",
firstName: "james",
lastName: "cordon",
},
];
const Home = () => {
return <EventsSection events={eventsData} />;
};
export default Home;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
crossorigin="anonymous"
/>
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!-- <script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-b5kHyXgcpbZJO/tY9Ul7kGkf1S0CWuKcCD38l8YkeH8z8QjE0GmW1gYU5S9FOnJ0"
crossorigin="anonymous"
></script> -->
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
ReactDOM.render(<App />, document.getElementById("root"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment