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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NODE_LI] renders <p> #43

Open
guanacone opened this issue Oct 30, 2023 · 3 comments
Open

[NODE_LI] renders <p> #43

guanacone opened this issue Oct 30, 2023 · 3 comments

Comments

@guanacone
Copy link

guanacone commented Oct 30, 2023

[NODE_LI]: (children) => {
              return (
                <li className="flex items-center">
                  <span className="text-lg">
                    <IconDone />
                  </span>
                  {/* {children?.[0].props.children[0]} */}
                  {children}
                </li>
              );
            },

children is rendered with a wrapping <p> tag which causes design issues. How can this be avoided.

Other question, how do you render different <li> depending if parent is <ul> or <ol>?

@guanacone
Copy link
Author

guanacone commented Oct 30, 2023

Found the answer to the first question in issue#36

[NODE_LI]: (children) => {
              if (Children.count(children) === 1) {
                const child = Children.toArray(children)[0];
                if (isValidElement(child)) {
                  // Check if child is a valid React element
                  if (child.type === "p") {
                    return <li>{child.props.children}</li>;
                  }
                }
              }
              return null;
            }

@claus
Copy link
Owner

claus commented Oct 31, 2023

how do you render different <li> depending if parent is <ul> or <ol>?

Can you tell me more about what you want to achieve? There is only one kind of <li>.. do you want to add a className or similar?

@guanacone
Copy link
Author

My intention is to render a different <li> depending if parent is <ul> or <ol>. My approach is the following:

[NODE_LI]: (children) => {
            const childElements = Children.map(children, (child) => {
              if (isValidElement(child)) {
                const isULItem = child.props.children[0] === "UL Item";
                const textStyleClass = isULItem
                  ? "text-sm md:text-md 2xl:text-base"
                  : "text-purple text-sm md:text-md 2xl:text-base";

                if (child.type === "p") {
                  return (
                    <li
                      key={child.key}
                      className={`py-2 md:py-4 2xl:py-6 ${textStyleClass}`}
                    >
                      <span>{child.props.children}</span>
                    </li>
                  );
                }
              }
              return null;
            });

            return <>{childElements}</>;
          },
          ```

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

No branches or pull requests

2 participants