Apply CSS selectors only for 1 page with Next.js/React and FullPage.js - css

I am using a library called FullPage.js (https://github.com/alvarotrigo/react-fullpage) on my Next.js project. They have an existant CSS class and I'd like to override the dots on the side. However, I wanna to override the css for only ONE PAGE and it's the following CSS Selector. How do I do it?
Help and thanks in advance!
global.css
#fp-nav > ul > li:last-child > a {
display:none
}
Page1.jsx
import ReactDOM from "react-dom";
import "fullpage.js/vendors/scrolloverflow"; // Optional. When using scrollOverflow:true
import ReactFullpage from "#fullpage/react-fullpage";
import "./global.css";
class MySection extends React.Component {
render() {
return (
<div className="section">
<h3>{this.props.content}</h3>
</div>
);
}
}
const Page1 = () => (
<ReactFullpage
navigation
sectionsColor={["#282c34", "#ff5f45", "#0798ec"]}
render={({ state, fullpageApi }) => {
return (
<div>
<MySection content={"Slide down! from Page 1"} />
<MySection content={"Keep going! from Page 1"} />
<MySection content={"Slide up! from Page 1"} />
</div>
);
}}
/>
);
export default Page1;
Page2.jsx
import ReactDOM from "react-dom";
import "fullpage.js/vendors/scrolloverflow"; // Optional. When using scrollOverflow:true
import ReactFullpage from "#fullpage/react-fullpage";
import "./global.css";
class MySection extends React.Component {
render() {
return (
<div className="section">
<h3>{this.props.content}</h3>
</div>
);
}
}
const Page2 = () => (
<ReactFullpage
navigation
sectionsColor={["#282c34", "#ff5f45", "#0798ec"]}
render={({ state, fullpageApi }) => {
return (
<div>
<MySection content={"Slide down! from Page 2"} />
<MySection content={"Keep going! from Page 2"} />
<MySection content={"Slide up! from Page 2"} />
</div>
);
}}
/>
);
export default Page2;

I found an answer,
I just added an query selector with DOM in a useEffect()
Look at the code below
import ReactDOM from "react-dom";
import ReactFullpage from "#fullpage/react-fullpage";
class MySection extends React.Component {
render() {
return (
<div className="section name1">
<h3>{this.props.content}</h3>
</div>
);
}
}
const FullpageWrapper = () => {
React.useEffect(() => { //ADD THIS AND IT WILL WORK :)
document.querySelector(`#fp-nav > ul > li:last-child > a`).style.display = "none";
}, []);
return (
<ReactFullpage
className="name1"
navigation
sectionsColor={["yellow", "#ff5f45", "#0798ec"]}
render={({ state, fullpageApi }) => {
return (
<div>
<MySection className="name1" content={"Slide down!"} />
<MySection className="name1" content={"Keep going!"} />
<MySection className="name1" content={"Slide up!"} />
</div>
);
}}
/>
);
};
export default FullpageWrapper;

Related

How can I mix between a ssr component and a client component in Nextjs 13?

The point is to implement a dynamic SSR component can be re-rendered by a search input.
I solved this by creating a layout.tsx file on my specific router then import children which made me dynamic render ssr component by the client component:
Layout.tsx
import React, { Suspense } from "react";
import Search from "./Search";
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<div className="layout">
<Search />
{children}
</div>
);
}
Search.tsx
"use client";
import { FormEvent, useState } from "react";
import { useRouter } from "next/navigation";
export default function Search() {
const [text, setText] = useState<string>("")
const router: any = useRouter();
const handleSubmit = (e: FormEvent<HTMLFormElement>) => {
e.preventDefault();
setText('')
router.push(`/definition/${text}`)
}
return (
<form onSubmit={handleSubmit} className='search'>
<input onChange={(e) => setText(e.target.value)}
value={text} type="text"
placeholder={"write to search"} />
</form>
);
} );
}

Send value from one component to another when onclick in react

I tried to send show_request value to TopMenu component, which is external component, but it did not pass. In TopMenu, If I output show_request on console it responses undefined
import React, { useState } from "react";
import TopMenu from "../../components/top-menu/top-menu";
import { projects } from "./project.data";
import "./projects.scss";
const Projects = () => {
return (
<div className="projects-page">
<div className="request"
onClick={() => <TopMenu show_request={true} />}
>
DROP REQUEST
</div>
</div>
);
};
export default Projects;
I did this, and I thought show_request=true in TopMenu
<div className="request"
onClick={() => <TopMenu show_request={true} />}
>
DROP REQUEST
</div>
My code In TopMenu
const TopMenu = ({ show_request }) => {
console.log(show_request); // It should be show_request=true, but it is undefined
}

React Typerscript How to pass a function to my class from another function file?

I'm new to React Typerscript, and I'm trying to figure out how to pass useModal function from RsvpPage to EventDescriptionPage.
`
import Modal from "./Modal";
import useModal from "./UseModal";
class EventDescriptionPage extends Component<any,any> {
constructor(props:any){
super(props);
}
render(){
return (
<div onClick={this.props.useModal}>
<button className='button' onClick={this.props.toggle}> RSVP </button>
<Modal isOpen={this.props.isOpen} toggle={this.props.toggle}></Modal>
</div>
</header>
</div>
);
}
}
export default EventDescriptionPage;
`
`
import EventDescriptionPage from "./EventDescriptionPage";
import Modal from "./Modal";
import useModal from "./UseModal";
function RsvpPage(){
const { isOpen, toggle } = useModal();
return (
<div>
<EventDescriptionPage/>
</div>
);
}
export default RsvpPage;
`
`
import { useState } from "react";
export default function UseModal() {
const [isOpen, setisOpen] = useState(false);
const toggle = () => {
setisOpen(!isOpen);
};
return {
isOpen,
toggle
};
}
`
`
import React, { ReactNode } from "react";
import "./Modal.css";
interface ModalType {
children?: ReactNode;
isOpen: boolean;
toggle: () => void;
}
export default function Modal(props: ModalType) {
return (
<>
{props.isOpen && (
<div className="modal-overlay" onClick={props.toggle}>
<div onClick={(e) => e.stopPropagation()} className="modal-box">
{props.children}Abaabaabaaba
</div>
</div>
)}
</>
);
}
`
I think my syntax is not right, but I'm not sure how to access useModal() function in RsvpPage.esx file.

How can I nest InnerBlocks inside InnerBlocks (custom plugins)

I am building a custom Wordpress site with a bunch of new plugins. I have a couple of plugins that use InnerBlocks, which work fine. However, for some of these plugins I would like to add InnerBlocks inside the child plugin. When I am in editing mode, I can render the InnerBlocks, but when saving and reloading, the data of the InnerBlocks disappear. I have tried to read through the core/columns and core/column code, but it's built significantly different than my code and therefore difficult to understand. But, since colums and column can be nested, I should be able to do the same.
These are my files:
// gallery/edit.js
/**
* WordPress dependencies
*/
import { __ } from "#wordpress/i18n";
import { useBlockProps } from "#wordpress/block-editor";
import { useSelect } from "#wordpress/data";
import { useEffect } from "#wordpress/element";
import { InnerBlocks } from "#wordpress/block-editor";
const Edit = (props) => {
const { setAttributes, clientId } = props;
const { innerBlockCount } = useSelect((select) => ({
innerBlockCount: select("core/block-editor").getBlockCount(clientId),
}));
useEffect(() => {
setAttributes({ innerBlockCount });
}, [innerBlockCount]);
const ALLOWED_BLOCKS = ["dyrlaegetorvet/gallery-image"];
const blockProps = useBlockProps();
return (
<div {...blockProps}>
<section class="p-0">
<div class="flex-editor__gallery">
<InnerBlocks
orientation="horizontal"
allowedBlocks={ALLOWED_BLOCKS}
/>
</div>
</section>
</div>
);
};
export default Edit;
// gallery-image/edit.js
/**
* WordPress dependencies
*/
import { __ } from "#wordpress/i18n";
import {
useBlockProps,
InnerBlocks,
} from "#wordpress/block-editor";
const Edit = (props) => {
const blockProps = useBlockProps();
return (
<div {...blockProps}>
<div class="p-4">
<div class="tpl-image aspect-w-3 aspect-h-4">
<InnerBlocks
placeholder="Insert an image"
allowedBlocks={["core/image"]}
/>
</div>
</div>
</div>
);
};
export default Edit;

React Router not displaying my components

I have read all the other questions with the same issue, but it just doesn't work for me.
index.html
<body>
<h1>Index</h1>
<div id="app"></div>
</body>
client/app.jsx
import React from 'react';
import { render } from 'react-dom';
import { Router, Route, IndexRoute, browserHistory } from 'react-router';
import { Accounts, STATES } from 'meteor/std:accounts-ui';
import { MainLayout } from '../imports/ui/layouts/main.jsx';
import { IndexPage } from '../imports/ui/components/index.jsx';
import { NotFoundPage } from '../imports/ui/components/errors/not-found.jsx';
Meteor.startup( () => {
render(
<Router history={ browserHistory }>
<Route path="/" component={ MainLayout }>
<IndexRoute component={ IndexPage } />
<Route path="signin" component={ Accounts.ui.LoginForm } formState={ STATES.SIGN_IN } />
<Route path="signup" component={ Accounts.ui.LoginForm } formState={ STATES.SIGN_UP } />
</Route>
<Route path="*" component={ NotFoundPage } />
</Router>,
document.getElementById('app')
);
});
imports/ui/layouts/main.jsx
import { Component } from 'react';
export default class MainLayout extends Component {
render() {
return (
<div>
<h2>Main Layout</h2>
{this.props.children}
</div>
);
}
}
imports/ui/components/index.jsx
import { Component } from 'react';
export default class IndexPage extends Component {
render() {
return (
<div>Index Page</div>
);
}
}
imports/ui/components/errors/not-found.jsx
import { Component } from 'react';
export default class NotFoundPage extends Component {
render() {
return (
<div>404 - Not found!</div>
);
}
}
So, going to any URL except /signin or /signup does not show anything but what's in index.html (i.e. react does not render anything)
Moreoever, /signin does not render MainLayout at all.
I have tried looking around, re-read the docs, etc. I don't see anything wrong with my code, and there is no error whatsoever. So, why isn't it working?
(Note: I have Meteor 1.3.2.4 with all latest npm modules and packages installed yesterday.)
Well, I went walking outside (it's finally sunny and warm!) and came back. The only difference I saw between my code and the example here was the export statement... or export default to be more precise.
Changing from
import { MainLayout } from '../imports/ui/layouts/main.jsx';
to
import MainLayout from '../imports/ui/layouts/main.jsx';
was my mistake.

Resources