Large numbers on calculator screen expanding past boundaries - css

I have created a calculator in create-react-app and I'm having an issue with the numbers flowing off the screen.
For example, when you type 11111111111111111111111111111111 the numbers will continue outside of the calculator output. I would like for the large numbers to shrink down and contain themselves within the space. How can this be achieved?
I have tried implementing https://github.com/kennethormandy/react-fittext as a dependency but it only appears to make my numbers smaller. The numbers still continue off the screen even with this implemented. I have included a current sandbox version of the project, so that you may see what I'm referring to. https://codesandbox.io/s/silly-haslett-8vf8s
You can find where I have used the above dependency in the output display component.
This is the CSS I use to style the calculator output
.output {
grid-column-start: span 4;
color: $white;
display: flex;
justify-content: flex-end;
align-items: center;
word-wrap: break-word;
}
#answer{
margin-right: 12px;
font-size: 5vh;
font-family: 'Lexend Tera', sans-serif;
}
and this is the component class in question.
import React from 'react';
import FitText from '#kennethormandy/react-fittext'
class OutputDisplay extends React.Component{
render(props){
return <p className='output'><span id='answer'><FitText compressor={0.1}>{this.props.placeThisOnScreen}</FitText></span></p>
}
}
export default OutputDisplay;

You can hide overflowed text and set text direction to rtl:
#answer {
overflow: hidden;
> div {
direction: rtl;
}
}
With breaking string:
#answer {
width: 100%;
display: block;
word-wrap: break-word;
white-space: normal;
}

You should use CSS word-wrap: normal and define the size of the calculator screen (output) window according to your needs.

Related

CSS Modules - `compose` defined on `media-query` overrides styling outside of `media-query`

I have a project where css modules works without an issue and recently I started incorporating responsiveness on it.
Our current setup is that we have a typography.css where we define several properties for each type of letter size and we do compose to import that setup where we require it.
My current use-case is the following.
/* somefile.module.css */
.header {
display: flex;
align-items: center;
justify-content: space-between;
composes: s-text from '../../styles/shared/typography.css';
}
#media screen and (max-width: 600px) {
.header {
composes: xs-text from '../../styles/shared/typography.css';
}
}
/* typography.css */
.s-text {
font-size: 14px;
letter-spacing: -0.01px;
line-height: 16px;
}
.xs-text {
font-size: 11px;
letter-spacing: -0.006px;
line-height: 14px;
}
Once I started using the media-query, on screen sizes larger than 600px I'm still seeing the composes: xs-text from '../../styles/shared/typography.css';
I had the same problem and tried different hacks to make it work, but I suggest using SASS with the modules so you could use a basic #mixin to make it work.
Apparently, the composes property works the same as #extend in SCSS which means it is impossible to use it across media queries.

Styling Material UI Button

Hi I just started using Material UI and am having a hard time styling the components. I am building a sign in page and would like my Submit button to be all the way to the bottom right. If someone can help me out that would be greatly appreciated because it seems to be inheriting styles from everywhere else but where I would like to!
I have tried adding
textAlign: 'right'
to buttonStyle and that does not work. I have also tried adding
text-align: right;
to my .form-button CSS.
The only thing that affects anything is removing the .App
Login.js
<div className='form-container'>
...
<Button
style={buttonStyle}
className='form-button'
variant='contained'>
Log-In
</Button>
</div>
...
const buttonStyle = {
backgroundColor: '#527354'
};
App.css
.App {
text-align: center;
}
.form-button {
width: 83px;
height: 36px;
box-shadow: 0px 1px 3px #00000033;
}
.MuiButton-label {
color: var(--primary-white);
font-family: 'Open Sans', sans-serif;
}
.form-container {
max-width: 400px;
margin: 2rem auto;
overflow: hidden;
padding: 0 2rem;
}
Another main goal would be to avoid inline styling because I do prefer keeping it within my style sheet. But if not possible or too overly difficult, I will inline style (as I did with the background-color).
As keikai has mentioned in the comment, you may check the Documentation in this link material-ui.com/styles/basics for overriding style.
For 'it seems to be inheriting styles from everywhere else'
I will suggest you to use styled-components instead of global css import, which mess up everywhere. Try this,
npm install --save styled-components
It creates a css class that only apply to the component.
Sample code:
import styled from 'styled-components'
const MyDiv = styled.div`// can be span, section, etc
// add your style here for the div
your div style(optional)
// your class css inside the div
.form-container {
max-width: 400px;
margin: 2rem auto;
overflow: hidden;
padding: 0 2rem;
}
// add more class if you have any
`
Then wrap your component with
// your newly created styled div
<MyDiv>
// component that needs your style
<MyComponent />
</MyDiv>
Your style will only be applied to MyDiv and MyComponent, and nothing else.
It may took awhile to get used to it, but it is extremely useful.

Override CSS in React

I am using Wolox's chat widget
https://github.com/Wolox/react-chat-widget
And I am trying to make a horizontal row of multiple chat widgets along the bottom of the screen. I am trying to override the class .rcw-widget-container
.rcw-widget-container {
bottom: 0;
display: -ms-flexbox;
display: flex;
-ms-flex-direction: column;
flex-direction: column;
margin: 0 20px 20px 0;
max-width: 370px;
position: fixed;
right: 0;
z-index: 1;
}
I have two chat Widget's that I want to put side by side, but I want to do it inline with React. Because my number of widgets will grow depending on how many user chats I open. So the right positioning needs to be dynamic. I just don't know how to accomplish this. Or if it's possible
https://codesandbox.io/s/vvnjyr9r30
EDIT
Something like this may work, but I don't think I am getting the syntax right.
.chat1 .rcw-widget-container {
right: 350px;
}
.chat2 .rcw-widget-container {
right: 400px;
}
Component
<Widget className="chat1" handleNewUserMessage={(e) => this.handleNewUserMessage(e, new Date().getTime())} />
<Widget className="chat2" handleNewUserMessage={(e) => this.handleNewUserMessage(e, new Date().getTime())} />
as I can understand probably you are looking for something like this:
In this case you can try:
.App {
font-family: sans-serif;
text-align: center;
display: flex;
flex-direction: row;
}
.rcw-widget-container {
border: 2px red solid;
position: initial;
}
Also, try to reorder the imports in index.js to override the styles.
import "react-chat-widget/lib/styles.css";
import "./styles.css";
While not inherently possible in CSS modules alone, the author of the react-toolbox library has actually solved this particular problem very nicely
Read their github docs which are more in depth on the subject at https://github.com/react-toolbox/react-toolbox#customizing-components
A list of the themeable classes for a particular component is given on the component demo page on their site too

ionic 4 "ion-option" text wrap

I am working with ionic 4 and i am having a problem trying to do a text wrap inside a "ion-select"
my select looks like this:
if i change my css directly on google chrome ( Style section on the "inspect element" menu) to "white-space: pre-wrap"
It looks like this:
and this is what i want to get.
on my HTML code i have this:
<ion-item>
<ion-label>Dirección de Entrega<a style="color: brown;">*</a></ion-label>
<ion-select [(ngModel)]="ordHerder.addressId" popover >
<ion-option style="white-space: pre-wrap !important;" *ngFor="let item of register_data.directions" value="{{item.recId}}" text-wrap>{{item.direction}}</ion-option>
</ion-select>
</ion-item>
and my css:
shopping-car-delivery {
.alert-ios .alert-radio-label{ white-space: pre-wrap !important;}
.alert-md .alert-radio-label{ white-space: pre-wrap !important;}
.alert-wp .alert-radio-label{ white-space: pre-wrap !important;}
}
Thanks :)
just add this in your app.scss if you are using ionic 4
.alert-radio-label.sc-ion-alert-md {
white-space: pre-line !important;
}
.alert-radio-label.sc-ion-alert-ios {
white-space: pre-line !important;
}
Adding this to app.scss worked:
ion-label {
white-space: normal !important;
}
Fixed it by overriding alert-radio-label.sc-ion-alert-md , alert-radio-label.sc-ion-alert-ios and updating whitespace to pre-line in page.scss
.alert-radio-label.sc-ion-alert-md {
padding-left: 52px;
padding-right: 26px;
padding-top: 13px;
padding-bottom: 13px;
flex: 1;
color: var(--ion-color-step-850, #262626);
font-size: 14px;
text-overflow: ellipsis;
white-space: pre-line;
}
Also, reduced font-size to 14px, since my text was around 35-40 characters.
.
If none of the above solutions works try root level css changes like below
:root {
ion-popover ion-select-popover ion-radio-group ion-item ion-label{
white-space: pre-line !important;
}
}
the css white-space should be extended to pre-line so your .scss would be
shopping-car-delivery {
.alert-ios .alert-radio-label{ white-space: pre-line !important;}
.alert-md .alert-radio-label{ white-space: pre-line !important;}
.alert-wp .alert-radio-label{ white-space: pre-line !important;}
}
if you are with Ionic 4 then just use class="ion-text-wrap" for wrapping text anywhere in element.
Ionic 4 CSS Classes Reference :- https://ionicframework.com/docs/layout/css-utilities
For Ionic 3 you can use class="text-wrap"
By default, select uses the AlertController API to open up the overlay
of options in an alert. The interface can be changed to use the
ActionSheetController API or PopoverController API by passing
action-sheet or popover, respectively, to the interface property.
To customize the ion-select options with interface="popover" in ionic, do the following:
Solution: Add the code in global.scss(Ionic4) and outside page-app tags in app.scss(Ionic3) so that the following css is accessible outside the component
.popover-content ion-list ion-label
{
font-size:12px !important;
}
Detailed Explanation:
The problem is that options inside ion-select are added as a Popover/Alert/Actionsheet.
The HTML code for showing the ion-select interface is produced outside the component i.e. outside the ion-router-outlet component.
So, any code you put inside your component's scss file to change looks of ion-select options will not reflect in the browser.
Example: How DOM looks like: (Ionic 4)
Ionic 3
This will change the look of ion-select option throughout the App
To customize it for different pages, I did it by adding and removing a custom class from the main app selector
ionViewDidEnter()
{
let appRoot:any=document.getElementById('myAPP');
this.renderer.setElementClass(appRoot,'customIonSelectCSS',true); //add
}
ionViewDidEnter()
{
let appRoot:any=document.getElementById('myAPP');
this.renderer.setElementClass(appRoot,'customIonSelectCSS',false); //remove
}
ion-select is using the alert to show the options, so you need to override the default styles
Step1:
.alert-tappable.sc-ion-alert-md.sc-ion-alert-ios {
display: contents !important;
}
by default, display: flex; change it to the display: contents !important;
Step2:
.alert-radio-label { white-space: pre-wrap !important; }
by default, white-space: nowrap; change it to white-space: pre-line !important;

CSS How to achieve word cloud?

I'm trying to create a word cloud type output with only CSS. Basically, I have a div box and a X number of text elements which need to go inside the box. However, they need to be of different font size. For example, let's say I have this:
.box { display: flex; width: 40vw; height: 30vw; overflow: hidden; }
.text1 { font-size: 5vw; }
.text2 { font-size: 4vw; }
.text3 { font-size: 3.5vw; }
.text4 { font-size: 3vw; }
I can position the text elements inside the box but I have a few questions regarding the layout. My lack of thorough CSS knowledge prevents me from telling if this is possible at all with just CSS or not:
How can I avoid collision of the text elements?
How can I ensure they stay within the boundaries of the box?
I believe it's not possible to make Word Cloud using CSS only, you need to have Javascript function or lib like WordCloud2.js that handle element positioning.
Demo:
https://timdream.org/wordcloud/#wikipedia:Cloud
References:
https://github.com/timdream/wordcloud2.js
https://github.com/timdream/wordcloud

Resources