Styling React Calendar Component with Symfony UX - reactjs

I am trying to render a styled react calendar (see here https://blog.logrocket.com/react-calendar-tutorial-build-customize-calendar/#styling-your-calendar) in Symfony. I am following the tutorial found here: https://symfony.com/bundles/ux-react/current/index.html.
The calendar component itself appears to render fine. See below.
However, there is no css styling present.
Here is the code for the calendar:
// assets/react/controllers/MyComponent.jsx
import React, { useState } from 'react';
import Calendar from 'react-calendar';
import './calendar.css'
export default function () {
const [date, setDate] = useState(new Date());
return (
<div className='app'>
<div className='calendar-container'>
<Calendar
onChange={setDate}
value={date}
locale="en-EN"
/>
</div>
<p className='text-center'>
<span className='bold'>Selected Date:</span>{' '}
{date.toDateString()}
</p>
</div>
);
}
Here is the css code:
.react-calendar {
width: 400px;
max-width: 100%;
background-color: #fff;
color: #222;
border-radius: 8px;
box-shadow: 0 12px 24px rgba(0, 0, 0, 0.2);
font-family: Arial, Helvetica, sans-serif;
line-height: 1.125em;
}
.react-calendar__navigation button {
color: #6f48eb;
min-width: 44px;
background: none;
font-size: 16px;
margin-top: 8px;
}
.react-calendar__navigation button:enabled:hover,
.react-calendar__navigation button:enabled:focus {
background-color: #f8f8fa;
}
.react-calendar__navigation button[disabled] {
background-color: #f0f0f0;
}
abbr[title] {
text-decoration: none;
}
/* .react-calendar__month-view__days__day--weekend {
color: #d10000;
} */
.react-calendar__tile:enabled:hover,
.react-calendar__tile:enabled:focus {
background: #f8f8fa;
color: #6f48eb;
border-radius: 6px;
}
.react-calendar__tile--now {
background: #6f48eb33;
border-radius: 6px;
font-weight: bold;
color: #6f48eb;
}
.react-calendar__tile--now:enabled:hover,
.react-calendar__tile--now:enabled:focus {
background: #6f48eb33;
border-radius: 6px;
font-weight: bold;
color: #6f48eb;
}
.react-calendar__tile--hasActive:enabled:hover,
.react-calendar__tile--hasActive:enabled:focus {
background: #f8f8fa;
}
.react-calendar__tile--active {
background: #6f48eb;
border-radius: 6px;
font-weight: bold;
color: white;
}
.react-calendar__tile--active:enabled:hover,
.react-calendar__tile--active:enabled:focus {
background: #6f48eb;
color: white;
}
.react-calendar--selectRange .react-calendar__tile--hover {
background-color: #f8f8fa;
}
.react-calendar__tile--range {
background: #f8f8fa;
color: #6f48eb;
border-radius: 0;
}
.react-calendar__tile--rangeStart {
border-top-right-radius: 0;
border-bottom-right-radius: 0;
border-top-left-radius: 6px;
border-bottom-left-radius: 6px;
background: #6f48eb;
color: white;
}
.react-calendar__tile--rangeEnd {
border-top-left-radius: 0;
border-bottom-left-radius: 0;
border-top-right-radius: 6px;
border-bottom-right-radius: 6px;
background: #6f48eb;
color: white;
}
Here is a screenshot of the folder/file structure:
Here is my webpack.config.js
const Encore = require('#symfony/webpack-encore');
// Manually configure the runtime environment if not already configured yet by the "encore" command.
// It's useful when you use tools that rely on webpack.config.js file.
if (!Encore.isRuntimeEnvironmentConfigured()) {
Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'dev');
}
Encore
// directory where compiled assets will be stored
.setOutputPath('public/build/')
// public path used by the web server to access the output path
.setPublicPath('/build')
// only needed for CDN's or subdirectory deploy
//.setManifestKeyPrefix('build/')
/*
* ENTRY CONFIG
*
* Each entry will result in one JavaScript file (e.g. app.js)
* and one CSS file (e.g. app.css) if your JavaScript imports CSS.
*/
.addEntry('app', './assets/app.js')
// enables the Symfony UX Stimulus bridge (used in assets/bootstrap.js)
.enableStimulusBridge('./assets/controllers.json')
// When enabled, Webpack "splits" your files into smaller pieces for greater optimization.
.splitEntryChunks()
// will require an extra script tag for runtime.js
// but, you probably want this, unless you're building a single-page app
.enableSingleRuntimeChunk()
/*
* FEATURE CONFIG
*
* Enable & configure other features below. For a full
* list of features, see:
* https://symfony.com/doc/current/frontend.html#adding-more-features
*/
.cleanupOutputBeforeBuild()
.enableBuildNotifications()
.enableSourceMaps(!Encore.isProduction())
// enables hashed filenames (e.g. app.abc123.css)
// .enableVersioning(Encore.isProduction())
.enableVersioning()
// configure Babel
// .configureBabel((config) => {
// config.presets.push('#babel/preset-react');
// })
// enables and configure #babel/preset-env polyfills
.configureBabelPresetEnv((config) => {
config.useBuiltIns = 'usage';
config.corejs = '3.23';
})
// enables Sass/SCSS support
//.enableSassLoader()
// uncomment if you use TypeScript
//.enableTypeScriptLoader()
// uncomment if you use React
.enableReactPreset()
// uncomment to get integrity="..." attributes on your script & link tags
// requires WebpackEncoreBundle 1.4 or higher
//.enableIntegrityHashes(Encore.isProduction())
// uncomment if you're having problems with a jQuery plugin
//.autoProvidejQuery()
;
module.exports = Encore.getWebpackConfig();
And here is my app.js:
/*
* Welcome to your app's main JavaScript file!
*
* We recommend including the built version of this JavaScript file
* (and its CSS file) in your base layout (base.html.twig).
*/
////////////////////////////////////////
//
// FOR REACT
//
// https://symfony.com/bundles/ux-react/current/index.html
import { registerReactControllerComponents } from '#symfony/ux-react';
// Registers React controller components to allow loading them from Twig
//
// React controller components are components that are meant to be rendered
// from Twig. These component then rely on other components that won't be called
// directly from Twig.
//
// By putting only controller components in `react/controllers`, you ensure that
// internal components won't be automatically included in your JS built file if
// they are not necessary.
registerReactControllerComponents(require.context('./react/controllers', true, /\.(j|t)sx?$/));
//
////////////////////////////////////////
// any CSS you import will output into a single css file (app.css in this case)
import './styles/app.css';
// compile new js file
// import './javascript/method1.js';
// start the Stimulus application
import './bootstrap';
Please let me know if there is anything else I can do to help. When running npm run dev, it does seem to recognize the import './calendar.css' as valid. I am not sure what to do here and haven't found anything similar online yet. Thank you.

Related

How to refer to individual style rules from a "*.module.scss" file in another .scss file?

I have this .button rule in Cta.module.scss-
.button {
$bg-color: white;
$text-color: variables.$color-text-cta;
background-color: $bg-color;
color: $text-color;
display: inline-block;
padding: variables.$padding-block-sm variables.$padding-inline-sm;
border: 0.056rem solid transparent;
border-radius: 0.278rem;
box-shadow: rgba(0, 0, 0, 0.239) 0 0.111rem 0.556rem;
#include mixins.cta-hover($bg-color, $text-color);
}
I want to override some properties for this .button class in IntroSection/index.module.scss, which I could do pretty easily if I was using styled-components; something like-
import {Button} from 'Cta/Cta.styles.js';
const Section = styled.section`
${Button} {
...
}
`;
I have no idea how (or if) we can achieve such a thing using scss modules. I tried a similar approach in index.module.scss-
#use '../../comps/Cta/Cta.module';
.section {
Cta.button {
padding: variables.$padding-block-md variables.$padding-inline-md !important;
&:first-of-type {
margin-right: variables.$margin-sm;
}
}
But it doesn't seem to work. What's the correct approach to achieve the result I want?
Below is what Cta.jsx contains in it-
import React from 'react';
import styles from './Cta.module.scss';
export default function Cta({ children, backgroundColor }) {
const classForBgColor = styles['button--' + backgroundColor];
return (
<button className={`${styles.button} ${classForBgColor || ''}`}>
{children}
</button>
);
}

"Maximum call stack size exceeded" after upgrading to alpha version of antd

Using npm I updated my antd dependency to 4.17.0-alpha.0. When I tried to run my react app after I updated it, it throws an error.
The error:
./src/App.less (./node_modules/css-loader/dist/cjs.js??ref--5-oneOf-8-1!./node_modules/postcss-loader/src??postcss!./node_modules/resolve-url-loader??ref--5-oneOf-8-3!./node_modules/less-loader/dist/cjs.js??ref--5-oneOf-8-4!./src/App.less)
Maximum call stack size exceeded
The App.less (I believe there's nothing wrong with this):
#import "~antd/lib/style/themes/default.less";
#import "~antd/dist/antd.less";
#import "~antd/dist/antd.compact.less"; // Introduce the official compact less style entry file
.login-form-container {
height: 80vh;
.login-form {
padding: 30px 0;
background-color: #fff;
.button {
width: 100%;
}
}
}
.footer {
background-color: #primary-color;
.text {
color: #fff;
}
}
.title {
padding: 0;
margin: 0;
}
#notif {
margin: 0;
padding: 0;
}
.header-icon {
font-size: 18px;
color: #black;
}
.page-header {
margin: 5px;
}
.content-container {
background-color: #fff;
padding: 15px;
min-height: 70vh;
margin: 10px 25px;
}
(P.S.) The reason why I want to update to the alpha version because of the Drawer component. The Drawer component has an extra prop which is available only in the latest alpha version. Here's the Drawer Documentation. Maybe I missed something.
I am new to Ant Design.
Install new alpha release to fix it.
npm install --save antd#4.17.0-alpha.2

How to Desktop View, Tablet View ,Mobile view change inside a browser ReactJS

I am new to Reactjs . How to add 3 views inside a browser,by automatically change view.
Reference Page Link
You can wrap all your content with a div and control the width of that div.
// App.js
import { useState } from 'react';
import './App.css';
function App() {
const [state, setState] = useState('desktop');
return (
<div className="App">
<button onClick={() => setState('desktop')}>Desktop</button>
<button onClick={() => setState('tablet')}>Tablet</button>
<button onClick={() => setState('phone')}>Phone</button>
<div className={`container ${state}`}>Your content here</div>
</div>
);
}
export default App;
/*App.css*/
.App {
height: 100%;
background-image: -webkit-linear-gradient(0deg, #766dff 0%, #88f3ff 100%);
}
/* General styling */
button {
padding: 0.5rem;
margin: 1rem;
border-radius: 10px;
cursor: pointer;
border: none;
}
.container {
/* General styling */
background-color: whitesmoke;
padding: 1rem;
border-radius: 5px;
margin-top: 1rem;
transition: all 1s;
/* Center the container */
margin-left: auto;
margin-right: auto;
}
.desktop {
width: 90%;
}
.tablet {
width: 768px;
}
.phone {
width: 480px;
}
/* index.css */
/* To make full width and height */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html,
body,
#root {
height: 100%;
}
The above answer is correct. You can simply give a width to the main container to 100% and place your other container with other elements inside of it, also specify width using #mediaqueries(" https://www.w3schools.com/css/css_rwd_mediaqueries.asp "). This way, you can control the elements inside the main container. I can say for sure that you need to try it by yourself and see how everything works, use devtools(there is toogle device toolbar).

How do you style nested css in react?

I have nested selectors in my css file. I'm new to React and trying to make it work with my js file. Does anyone have any tips?
I found: https://blog.logrocket.com/the-best-styling-in-react-tutorial-youve-ever-seen-676f1284b945
It seems to be helpful but does not mention how to deal with nested css. For example, I have &:before and &:after, #include signUpActive, among others. This is really some confusing stuff.
.img {
overflow: hidden;
z-index: 2;
position: absolute;
&:before {
content: '';
position: absolute;
transition: transform 1.2s ease-in-out;
}
&:after {
content: '';
position: absolute;
}
#include signUpActive {
&:before {
transform: translate3d(640px,0,0);
}
}
&__text {
z-index: 2;
position: absolute;
transition: transform 1.2s ease-in-out;
&.m--up {
#include signUpActive {
transform: translateX(260px*2);
}
}
&.m--in {
transform: translateX(260px * -2);
#include signUpActive {
transform: translateX(0);
}
}
}
&__btn {
overflow: hidden;
z-index: 2;
position: relative;
&:after {
content: '';
z-index: 2;
position: absolute;
}
&.m--in {
transform: translateY(36px*-2);
#include signUpActive {
transform: translateY(0);
}
}
&.m--up {
#include signUpActive {
transform: translateY(36px*2);
}
}
}
}
}
It is actually not "nested CSS". But it is a SASS/SCSS code. Both SASS and SCSS have similar purposes, with several slight differences. Please check here for more detail: https://www.geeksforgeeks.org/what-is-the-difference-between-scss-and-sass/ . Personally, I would suggest SCSS over SASS by considering it is less strict than SASS.
If you like to use just normal CSS, then just write and import CSS scripts to your react. It will be no problem. You should not follow that "nested CSS" way which is SASS/SCSS ( I would not recommend that actually ).
Let assume you stick with SASS/SCSS. If you are using "CRA" ( create react application ), it is just as simple as import your .scss file to react component like the following:
import React from "react";
import ReactDOM from "react-dom";
import "./styles.scss";
function App() {
return (
<div className="App">
<div className="panel">
<h2>Panel</h2>
<div className="panel__inner">
<h3>Inner panel</h3>
</div>
</div>
</div>
);
}
While the styles.scss is just a normal SCSS code at same directory, like follow:
#import "./scss-mixins/mixins.scss"; //Using relative path to the .scss file
.App {
font-family: sans-serif;
text-align: center;
.panel {
padding: 15px;
background: #f9f9f9;
&__inner {
padding: 10px;
background: green;
}
}
}
Just ensure that you have node-sass in your package. Otherwise you should do npm install node-sass --save. Please read more at official documentation here: https://facebook.github.io/create-react-app/docs/adding-a-sass-stylesheet.
You can check working example at: https://codesandbox.io/s/x2z4ly6y2z

Run on android with react-native-web

I'm new to React and React Native, I want to build a cross platform app which would use native components on mobile platforms.
I installed and initialized a react-native-app and install react-native-web and I wonder how to start my boilerplate code on android emulator, the documentation doesn't tell how.
Use these commands to get Demo Code
npm install -g create-react-native-app
create-react-native-app AwesomeProject
cd AwesomeProject
npm start or react-native start
Once you Get familiar to basics. I recommend you boilerplate code you must check out .
1. https://github.com/cubixlabs/ReactCube
2. https://github.com/GeekyAnts/NativeBase
3. https://github.com/shoutem/ui
Web View Component index.js
// #flow
import React from "react";
import PropTypes from "prop-types";
import {
WebView as WebViewRn
} from "react-native";
export default class WebView extends React.PureComponent {
static propTypes = {
source: PropTypes.object
};
static defaultProps = {
source: {
html: `
<html>
<header>
<style>
html, body {
height: 100%;
}
html {
display: table;
margin: auto;
}
body {
text-align: center;
display: table-cell;
vertical-align: middle;
}
</style>
</header>
<body>
<p>No valid HTML provided</p>
<p>source props is missing</p>
</body>
</html>
`
}
};
render() {
const {
source,
...rest
} = this.props;
return <WebViewRn source = {
source
} { ...rest
}
/>;
}
}
Component : Styles.js
// #flow
import {
StyleSheet
} from 'react-native';
import {
Colors
} from '../../theme';
export default StyleSheet.create({
container: {
flex: 1,
backgroundColor: Colors.primary.backgroundColor
}
});
Container Class index.js
// #flow
/*
Disable selection style
style="-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;"
Word wrap and break word style
style="word-wrap: break-word;"
*/
import {
connect
} from "react-redux";
import React, {
Component
} from "react";
import {
WebView
} from "../../components";
class Terms extends Component {
render() {
return <WebView source = {
{
html
}
}
/>;
}
}
const html = `
<!DOCTYPE html>
<html lang="en">
<head>
<style>
.container {
margin: 0 auto;
}
h2 {
color: #000;
margin-bottom: 15px;
font-size: 30px;
font-weight: 700;
font-family: 'Roboto', sans-serif;
line-height: 1.2;
margin-top: 25px;
}
p {
font-family: 'Roboto', sans-serif;
text-align: left;
line-height: 26px;
font-weight: 300;
font-style: normal;
color: #000;
font-size: 18px;
}
</style>
</head>
<body>
<div class="container" style="-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;">
<h2>Disclaimer</h2>
<p>Always make sure to double check recipe and component ingredients (and where they are produced) if you have any health
related issues to avoid particular foods. Please make sure to consult a doctor and always double check labels. Please
notify us of any errors on the recipes itself. We strive to make information as acurate as possible for convenience, however
we disclaim any warranty on it.</p>
<p>Always consult a licensed physician or licesned nutritionalist for all medical, dietary and allergen issues. All information
on our site “as is” has no warranty on it of any kind. Either expressed or implied. </p>
<p>Rich thomas LLC and its partners disclaim all warranties expressed or implied including without limitation those of merchanitbility
or fitness for a particular purpose and non fringement or arsiing from a course of dealing, usage, or trade practice.
Rich Thomas LLC shall not be liable for any indirect, special, consequential, or incidental damages arising from any information
present.</p>
</div>
</body>
</html>`;
const mapStateToProps = () => ({});
const actions = {};
export default connect(mapStateToProps, actions)(Terms);

Resources