css properties are not applied - html

I am trying to apply some style to my webpage. In my Festival.module.css
i've got this:
.button {
background-color: purple ;/* Green */
border: none;
color: cblack;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
}
.flightbutton{
background-color : rgb(205, 5, 255);
}
And here is my festival.js file, where i try to apply the style from Festival.module.css file, but it is not working:
import { List, Avatar, Space } from 'antd';
import { MessageOutlined, LikeOutlined, StarOutlined } from '#ant-design/icons';
import{Link} from 'react-router-dom'
import React from 'react'
import moment from 'moment'
import styles from './Festival.module.css';
const IconText = ({ icon, text }) => (
<Space>
{React.createElement(icon)}
{text}
</Space>
);
const Festivals = (props) => {
return(
<List
itemLayout="vertical"
size="large"
pagination={{
onChange: page => {
console.log(page);
},
pageSize: 3,
}}
dataSource={props.data}
renderItem={item => (
<List.Item
key={item.title}
actions={[
<IconText icon={StarOutlined} text="156" key="list-vertical-star-o" />,
<IconText icon={LikeOutlined} text="156" key="list-vertical-like-o" />,
<IconText icon={MessageOutlined} text="2" key="list-vertical-message" />,
]}
actions={[
<button key={0} >Accommodation</button> ,
<button className = {styles.flightbutton} key = {1} type="button">Flight</button> ,
]}
extra={
<img
width={272}
alt="logo"
src={item.image_src}
/>
}
>
<List.Item.Meta
title={<a href={`${item.id}`}>{item.name}</a>}
description={moment(item.start_date).format("[The Festival will start on ]MM DD YYYY [at] hh:mm[.\n]").concat(moment(item.end_date).format("[\nThe end day is: ]MM DD YYYY")) }
/>
{item.content}
</List.Item>
)}
/>
)
}
export default Festivals;
Although i applied classname="flightbuton", i don't see any changes in stile of the button. what can i do?

I think you're not applying styles.button to your button element.
You can do something like this:-
<button className = {`${styles.button} ${styles.flightbutton}`} key = {1} type="button">Flight</button>

In your component you can import like below
import './Festival.module.css';
and then just apply the css to the element like
<button className="flightbutton" key = {1} type="button">Flight</button>
Hope this helps.

Related

React custom element is in DOM, but not visible

I am trying to create an element in React, but I cannot get it to be visible. It shows up in the Elements tab of the Chrome developer console, but when I hover over it there it doesn't even show a location. I have other custom elements that work fine, it is this in particular that is not rendering. Here is the code defining the element:
import React from "react";
import ReactDom from "react-dom";
const Modal = (props) => {
const [domReady, setDomReady] = React.useState(false)
React.useEffect(() => {
setDomReady(true)
})
return domReady?ReactDom.createPortal(
<>
<div className="modal">
TEST
</div>
<div onClick={() => {}} className="backdrop">
</div>
</>,
document.getElementById('modal-root')
):null
}
export default Modal;
Here is the CSS that affects it, though it is worth noting that even without this CSS I see nothing:
.modal {
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
border-radius: 6px;
background-color: white;
padding: 1rem;
text-align: center;
width: 30rem;
z-index: 10;
position: fixed;
top: 0;
left: 0;
}
.backdrop {
position: fixed;
z-index: 1;
background-color: rgba(0, 0, 0, 0.75);
width: 100%;
height: 100vh;
top: 0;
left: 0;
}
Edit: Here is the file which uses the component:
import { useState } from 'react';
//import Loading from '../Loading/Loading';
import './Income.css';
import { useNavigate } from 'react-router-dom';
import IncomeRow from '../../components/IncomeRow/IncomeRow';
import Button from '../../components/Button/Button';
import Modal from '../../components/Modal/Modal';
const Income = () => {
//Initializing
const navigate = useNavigate();
// modal visibility states
const [editModalVisible, setEditModalVisibility] = useState(false);
const [deleteModalVisible, setDeleteModalVisibility] = useState(false);
const [addModalVisible, setAddModalVisibility] = useState(false);
// show modal to edit income
const onEditClick = () => {
setEditModalVisibility(true);
}
const onDismissEditModal = () => {
setEditModalVisibility(false);
}
//returning JSX
return (
<>
<div className='Incomes'>
{/* TODO: make these autogenerate from database */}
<IncomeRow name="income 1" source="Company 1" date="1/1/2022" amount={123.45} id="1" editFunction={onEditClick}/>
<IncomeRow name="income 2" source="Company 2" date="7/31/2022" amount={420.69} id="2"editFunction={onEditClick}/>
</div>
<Button text="Add Income"/>
<Modal dismissModal={onDismissEditModal}/>
</>
);
}
export default Income
Here is App.js, which holds the base of the layout:
import React, { useState} from 'react';
import './App.css';
import Navbar from './components/Navbar/Navbar';
import 'bootstrap/dist/css/bootstrap.min.css';
//import { ThemeContext, themes } from './context/themeContext';
import { Outlet, useNavigate} from 'react-router-dom';
function App() {
return (
<div className="App">
<Navbar/>
<div className='body'>
<div id='modal-root'>
<Outlet/>
</div>
</div>
</div>
);
}
export default App;

How to change checkbox checked color with react?

There is a checkbox component:
import React, { InputHTMLAttributes } from "react";
import styled, { css } from "styled-components";
export const CheckBox: React.FC<InputHTMLAttributes<HTMLInputElement>> = (
props
) => {
return <Input type="checkbox" {...props} />;
};
const Input = styled.input`
${({ theme }) => css`
border: 1px solid white;
&:checked {
background-color: green;
border-color: green;
}
`}
`;
I want to set its checked color to another but doesn't work. It's still the default blue background color.
I hope:
Before
After
You can create own your component for that but it takes a lot of time.
Checkout into sandbox

Displaying images within ReactJS Card

I am working on a project which will feature a leaderboard with player icons, name and scores.
Here is my initial design that im trying to implement.
Im using cards to hold each element and will eventually will be inserting data from my DB, however rn I'm just trying to get the design skeleton together all smooth. I can get the text working and aligned fine but cant figure out how to it with text. Before I was just using the cards for text and the images as its own element, it worked fine til I tried to put more than one row.
Now when I'm trying to put the image in as a card, it's just printing info about the image instead of the actual image. I'm quite new to React so sorry if its a simple solution. I've been playing with this all day and cant find a solution that works for me.
Heres the code so far! Thanks so much for taking the time to read and any advice is greatly appreciated!
Index.js
import React from 'react';
import ReactDOM from 'react-dom';
import styled from 'styled-components';
import dogicon from './assets/doggo.png'
import './index.css';
export const Grid = styled.div`
`;
export const Row = styled.div`
display: flex;
background-color: #c3b0d3;
display: block ruby;
`;
export const Col = styled.div`
flex: ${(props) => props.size};
`;
const CardStyle = styled.div`
display: block ruby;
padding-left: 30px;
padding-right: 30px;
`;
console.log(dogicon);
const LeaderboardHeader = () => {
return (
<div className="leadheader">
<h2>LEADERBOARD</h2>
</div>
)
}
class Card extends React.Component {
render(){
return (
<div className="card">
<p>{this.props.name}</p> <p>{this.props.score}</p> <p>{this.props.icon}</p>
</div>
)
}
}
class App extends React.Component {
// fires before component is mounted
constructor(props) {
// makes this refer to this component
super(props);
// set local state
this.state = {
name: "PLAYER 1",
score: "200",
icon: require('./assets/doggo.png'),
};
}
render() {
const {name} = this.state;
const{score} = this.state;
const{icon} = this.state;
return (
<div className="container">
<LeaderboardHeader />
<Grid>
<Row>
<CardStyle>
<Col size={1}>
<Card icon={icon}/>
</Col>
</CardStyle>
<CardStyle>
<Col size={1}>
<Card name ={name} />
<Card name ={name} />
<Card name ={name} />
</Col>
</CardStyle>
<CardStyle>
<Col size={1}>
<Card score={score} />
<Card score={score} />
<Card score={score} />
</Col>
</CardStyle>
</Row>
</Grid>
</div>
)
}
}
ReactDOM.render(
<App />,
document.getElementById('root')
);
Index.css
#import url('https://fonts.googleapis.com/css2?family=Passion+One&display=swap');
body {
font: 50px;
font-family: 'Passion One', cursive;
margin: 20px;
background: #7E549F; overflow: hidden;
text-align: center;
}
.container{
width: 550px;
}
.leadheader {
margin-top: 100px;
background-color: #422D53;
color: #C3B0D3;
text-align: center;
width: 100%;
height: 50px;
font-size: 45px;
text-align: center;
border-radius: 5px 5px 0 0;
margin: 0;
padding-bottom: 25px;
}
.card {
background-color: #C3B0D3;
color: #2A1D34;
margin: 0 auto;
padding: 100px 0;
font-size: 40px;
}
You should use that image data in the src attribute of an <img> tag. Since you are using <p>{this.props.icon}</p> it is coerced to string, hence displaying the text value of the image.
So, this would be the final result:
class Card extends React.Component {
render(){
return (
<div className="card">
<p>{this.props.name}</p> <p>{this.props.score}</p> <img src={this.props.icon} />
</div>
)
}
}

How to get my button to trigger an element

I am using nextjs to compile my code and antd framework. I am unable to style the positioning of my button, also I want my start button to trigger a set of buttons but for some reason it does not work. Below is my code
import React, { Component } from "react";
import Layout from "./Layout";
import { Radio } from "antd";
export default class PositiveAffirmation extends Component {
state = {
changeButton: false
};
toggleChangeButton = e => {
this.setState({
changeButton: e.target.value
});
};
render() {
const { changeButton } = this.state;
return (
<Layout>
<Radio.Group
defaultValue="false"
buttonStyle="solid"
onChange={this.changeButton}
className="radio-buttons"
>
<Radio.Button value={true}>Start</Radio.Button>
<Radio.Button value={false}>Stop</Radio.Button>
</Radio.Group>
{changeButton && (
<Button.Group size={size}>
<Button type="primary">Happy</Button>
<Button type="primary">Sad</Button>
<Button type="primary">Fullfiled</Button>
</Button.Group>
)}
<style jsx>{`
Radio.Button {
font-size: 100px;
margin-left: 20px;
margin-top: 5px;
margin-bottom: 5px;
display: flex;
justify-content: center;
}
`}</style>
</Layout>
);
}
}
you are calling just wrong fn change onChange={this.changeButton} to onChange={this.toggleChangeButton}

Ant Design: Vertical submenu pop up grow from bottom to top

Is it possible to display the popup of a vertical submenu "the other way around" ? I have one SubMenu item in a fixed Sidebar at the bottom of my page. It contains links for the users profile and the logout link. But since it is at the bottom of the page the submenu will open and part of it is outside the of the page.
Here is a screenshot of the current situation.
I searched for options the documentation but I couldn't find a suitable solution for the problem. So basically what I want to achieve is growing the popup from bottom to top and not top to bottom.
Here is the source for the Sidebar component. It is quite a early stage so there are still other improvements to the code to do.
import React from 'react';
import { connect } from 'react-redux';
import { Layout, Menu, Icon } from 'antd';
import { withRouter } from 'react-router-dom';
import styled from 'styled-components';
import { toggleSidebar } from '../../actions/ui';
import { logoutUser } from '../../actions/user';
const { Sider } = Layout;
const SubMenu = Menu.SubMenu;
const Logo = styled.div`
height: 32px;
background: rgba(255, 255, 255, 0.2);
margin: 16px;
`;
const UserMenu = styled(SubMenu)`
position: fixed;
text-align: center;
bottom: 0;
cursor: pointer;
height: 48px;
line-height: 48px;
color: #fff;
background: #002140;
z-index: 1;
transition: all 0.2s;
`;
const mapStateToProps = state => ({
ui: state.ui
});
const mapDispatchToProps = dispatch => {
return {
toggleSidebar: () => dispatch(toggleSidebar()),
logoutUser: () => dispatch(logoutUser())
};
};
class Sidebar extends React.Component {
componentDidMount() {}
render() {
const { ui, logoutUser } = this.props;
return (
<Sider
collapsed={ui.sidebarCollapsed}
//onCollapse={toggleSidebar} // toggle is disabled
style={{
overflow: 'auto',
height: '100vh',
position: 'fixed',
left: 0
}}
>
<Logo />
<Menu theme="dark" defaultSelectedKeys={['1']} mode="inline">
<UserMenu
key="sub1"
placement="topLeft"
title={
<span>
<Icon type="user" />
<span>User</span>
</span>
}
>
<Menu.Item onClick={logoutUser} key="3">
Logout
</Menu.Item>
<Menu.Item key="4">Profile</Menu.Item>
</UserMenu>
</Menu>
</Sider>
);
}
}
export default withRouter(
connect(
mapStateToProps,
mapDispatchToProps
)(Sidebar)
);
Is there a way to achieve this ?
Yes it should be possible. <Menu>uses the rc-menu package, and supports all the properties from this package, even if they are not documented in the and.design doc page.
Menu position is guided by the builtinPlacements property, which in turn uses https://github.com/yiminghe/dom-align, which gives you lot of flexibility in how to position the elements.