Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module for consumption in Netlify CMS #12

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

hermanbanken
Copy link

I'm experimenting in enriching the Netlify CMS (if you don't know it, look it up, I think it is awesome 馃槃). It offers some basic Markdown editing, but no rich table editing support (just editableContent).

I saw your repo and it looked a lot like the awesome tables in Notion, so I thought I could give it a go. After finding the fork of @jeff-r-koyaltech I fiddled a bit more to be able to include it from NextJS & Netlify CMS, and to be able to read the updated state from it.

Notably, it was a hell of a lot of work to be able to include the styles. The only way to get the stylesheet to not interfere with the rest of the CMS was to use a shadowroot via https://github.com/Wildhoney/ReactShadow, but this didn't really play nice with the style system. So I opted for outputting a <style> element with the actual styles (which then get scoped by ReactShadow). There may be better ways, but I didn't get it working otherwise 馃槄

Proof:

Screenshot 2022-04-24 at 12 08 09

Snippet required:

import root from 'react-shadow';
import React, { Ref } from "react";
import dynamic from 'next/dynamic';
import type { TableWrapper } from "editable-react-table";

export function TableWidget(opts: any = {}) {
  return {
    name: "table",
    controlComponent: TableControlComponent,
    previewComponent: TableControlComponent,
    ...opts,
  }
}

export const TableComponent = {
  id: 'table',
  label: 'Table',
  widget: 'table',
  type: 'table',
} as any;

enum DataTypes {
  NUMBER= 'number',
  TEXT= 'text',
  SELECT= 'select',
}

export const Table = dynamic<Parameters<typeof TableWrapper>[0]>(
  () => import("editable-react-table").then(({ TableWrapper }) => TableWrapper), {
  ssr: false, // required because otherwise it complained about `window` being undefined
});

class TableControlComponent extends React.Component<{ /* todo */ }> {
  render() {
    return <root.div className="table" mode="open" style={{border:"1px solid #82888d", display:"block"}}>{
      <div id="root">
        <Table dispatch={console.log} initialState={{
          columns: [{
            id: 'firstName',
            label: 'First Name',
            accessor: 'firstName',
            minWidth: 100,
            dataType: DataTypes.TEXT,
            options: [],
          },
          {
            id: 'lastName',
            label: 'Last Name',
            accessor: 'lastName',
            minWidth: 100,
            dataType: DataTypes.TEXT,
            options: [],
          }],
          data: [{
            ID: 0,
            firstName: "John",
            lastName: "Doe",
          }],
          skipReset: false,
        }}></Table>
      </div>
    }</root.div>
  }
}

and how I hooked it up to Netlify CMS:

  CMS.registerEditorComponent(TableComponent);
  CMS.registerWidget([TableWidget()] as any); // unexposed parameter format

jeff-r-koyaltech and others added 18 commits February 26, 2022 09:19
)

* Add some package.json metadata for publishing

* Release as a module

* Document the koyal-tech publish process

* Use rollup to ship libraries

* sample app

* Working example

* accidentally removed this, rollup needs it

* Faker is fat. Remove it.

* Introduce TableWrapper. Getting more stable-ish.

* bug fixes (bump to 0.1.2)
- rollup main vs module issue
- got columns passing correctly as a prop

* mockup component gallery

Co-authored-by: Jeff R <jeff-r-koyaltech@users.noreply.github.com>
@hermanbanken
Copy link
Author

hermanbanken commented Apr 24, 2022

You might not be interested in this PR, please feel free to close it as it ain't done and you might not be willing to maintain it anyway. Anyhow, I wanted to show it and do this small write-up as a way to say 馃檹 thank you 鉂わ笍 for the nice table functionality and styling (I definitely want to build upon your UX as it feels great in your samples; and I'm no frontender by nature).

I might spend some more time polishing it, extract updated states (so I can write the table state to Netlify CMS components), etc.

@jeff-r-koyaltech
Copy link

Very nice! I ended up not using this in the project where I thought that I would. I also discovered that 90% of what I wanted was already exposed and customizable in https://react-table.tanstack.com/ , so my motivation for contributing to and maintaining this library has decreased a little. Nonetheless, it was a helpful context for getting familiar with dependent technologies that make it work. 馃挭馃徏馃檹馃徏

@archit-p archit-p force-pushed the master branch 2 times, most recently from 4955049 to dad8078 Compare December 22, 2023 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants