Tailwindcss fluid grid - css-grid

I generally use this line of css to get a fluid grid for items with 20rem width:
'''
grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr));
'''
Can i use css utility classes to do this oris there any way to extend it so that it can do this ?

There's no utility class that can do this. If you wanted to extend Tailwind and add a custom utility class for grid-template-columns, you could add something like this in your tailwind.config.js:
module.exports = {
theme: {
extend: {
gridTemplateColumns: {
'fluid': 'repeat(auto-fit, minmax(20rem, 1fr))',
}
}
}
}
You could then use the class grid-cols-fluid.

Related

React Native Render HTML bullet list is not centered with text

I'm using react-native-render-html library to display data from Django Rest Framework stored in RichTextUploadingField from django-ckeditor. As basic styling is working properly I have a problem with the <ul> tag - text is not centered with circle/square/number as shown in the image. I tried using renderersProps like:
<RenderHTML renderersProps={{ ul: { markerBoxStyle:{ paddingRight: 3, top: 5 }, markerTextStyle: { color: "red" } } }} />
But it works for specific text size. If I change the text size in style in Django admin, the element and text aren't centered again. Is there any option on how to fix it or what causes the problem?
You could add a custom CSS class to unordered list items only. Then apply your styles to that CSS class.
// this function goes through every list item in <ul> only and adds your custom class ('ul-li' in my case)
const onElement = (el) => {
const { children, name } = el;
if (name === 'ul' && children && children.length) {
children.forEach(listItem => listItem.attribs = {class: 'ul-li'})
}
}
// define your styles for your custom class
const classesStyles = {
"ul-li": {
lineHeight: '21px', // for me adjusting lineHeight did the job
}
}
// in your JSX
<RenderHtml
source={source}
contentWidth={width}
tagsStyles={tagsStyles}
... // other props you may have
domVisitors={{onElement}} // first alter your html
classesStyles={classesStyles} // then apply styles
/>
Sources:
classesstyles
onElement

Shorthand for class names targeted with regex

Due to the nature of using BEM in the project I am working on, I find myself and others using the following in our CSS files:
[class*="something"] { ... }
[class*="__something-else"] { ... }
[class*="--other-stuff"] { ... }
[class*="more-things"] { ... }
[class*="__even-more"] { ... }
Is there an advisable workaround to shorten the above to prevent tedious repetition of the word class, or should we stick by this method?
You need to use preprocessor like LESS or SCSS/Sass.
I use SCSS to demonstrate your idea.
By using #mixin and #content, you can create a class selector's generator function:
#mixin contain($name) {
[class*=#{$name}] {
#content;
}
}
Create a new contain selector:
#include contain(--big) {
font-weight: bold;
font-size: 50px;
}
https://jsfiddle.net/twxia/pLy3bz44/2/
This seems not shorter than only typing [class*=...], but if you use Sass you can generate the #mixin like this:
+contain(--big)
font-weight: bold
font-size: 50px
I think use autocomplete plugin for editor or Sass will sovle your problem :D

Why does this CSS transition event not fire when two classes are added?

CSS
.horizontalTranslate {
-webkit-transition: 3s;
}
.secondClass {
background: red;
}
HTML
<div class='box'></div>
JS
var box = document.querySelector('.box');
box.addEventListener('webkitTransitionEnd', function(evt) {
alert('Finished transition!');
}, false);
function transitionBox() {
// this works
box.className = 'horizontalTranslate';
// this does not work
// box.className = 'secondClass horizontalTranslate';
}
setTimeout(transitionBox, 100);
Why does the transition event not fire when two classes are added rather than one? I've also tried chaining my CSS selector, a la .secondClass.horizontalTranslate { ... }.
The reason is that box.className = 'horizontalTranslate'; is actually removing styling, causing the CSS transition to actually happen. But when I set box.className = 'secondClass horizontalTranslate';, the styling of the DOM node is not changing and no event is fired.
Another way to write transitionBox is this:
function transitionBox() {
box.classList.add('horizontalTranslate');
box.classList.add('blue');
}
If blue changes the styling of box, this works too.

Qt 5 Styling: dynamically load qml files

I am currently trying to extend our application with different style.
For each style I have a separate qml file with e.g. color definitions.
StyleA.qml:
import QtQuick 2.0
QtObject {
property color textColorStandard: 'black'
...
}
In my main.qml I would like to load the right qml file, based on a software property:
import QtQuick 2.0
Item {
id: mainPanel
....
Loader {
id: myDynamicStyle
source: Property.UseThemeA? "StyleA.qml" : "StyleB.qml"
}
...
Item {
id: BackGround
color: myDynamicStyle.textColorStandard
}
}
unfortunately this approach does not work. Is there any other/better way to accomplish styling?
thanks, michael
Using things loaded in Loader is badly typed, I would rather :
First, create a common ancestor Component for all my styles, e.g :
// AbstractStyle.qml
import QtQuick 2.0;
QtObject {
property color textColorStandard;
}
Next, derivate it to create custom styles, e.g :
// StyleA.qml
import QtQuick 2.0;
AbstractStyle {
textColorStandard: "blue";
}
// StyleB.qml
import QtQuick 2.0;
AbstractStyle {
textColorStandard: "green";
}
Then use a strongly typed property in my object that must use a style, e.g:
// main.qml
import QtQuick 2.0
Item {
id: base;
Component { id: compoStyleA; StyleA { } }
Component { id: compoStyleB; StyleB { } }
property AbstractStyle currentStyle : {
var tmp = (Property.UseThemeA ? compoStyleA : compoStyleB); // choose component
return tmp.createObject (base); // instanciate it and return it
}
Rectangle {
color: currentStyle.textColorStandard;
}
}
That way, there are multiple advantages :
your code doesn't use Strings to identify components, so errors are easier to find and to avoid ;
you can't affect an item that doesn't inherit your style base class, so you won't encounter "undefined property" errors and won't need ducktyping to figure out which information you have in your style object ;
you don't have Loader so you won't have to suffer the nasty "context isolation" between inside and outside the Loader ;
all components will be preloaded at runtime, gaining speed at instanciation, and allowing you to see from the start if there are syntax errors in the Styles, instead of seeing it only when changing current style ;
last but not least, property auto-completion will work in QtCreator as the actual type will be known by the IDE !
Did you try using this instead? The loaded object is store into the item property of the loader and no in the loader directly.
Item {
id: BackGround
color: myDynamicStyle.item.textColorStandard
}

embed ui view inside live camera view blackberry 10

i want to add some ui inside camera view blackberry 10
like photobomber samples on github
https://github.com/blackberry/Cascades-Samples/tree/master/photobomber
but i want to overlay the image while the camera is active and save the photo + image inside the photo to memory
can somebody tell me how to do that ?
best regards,
adit
You should opt for DockLayout whenever you want to overlap any controls. Go through the following code, you should get the idea
Page {
content: Container {
gestureHandlers: [
TapHandler {
onTapped: cameraControl.capturePhoto()
}
]
layout: DockLayout {
}
Camera {
id: cameraControl
onCameraOpened: {
cameraControl.startViewfinder();
}
}
Button {
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
text: "Overlapping button"
}
}
onCreationCompleted: {
if (cameraControl.allCamerasAccessible) {
cameraControl.open(CameraUnit.Rear);
}
}
}
To capture photo you can use capturePhoto method of camera control. Go through the documentation to find more methods.
Do note that Camera control should be declared at the top in the container & other controls should be declared below it to overlap controls over it.
Don't forget to provide Camera acess permission in bar-descriptor, to add LIBS += -lcamapi in pro file & to import bb.cascades.multimedia 1.0 in qml.