How can I use Chakra UI _after Pseudo-Class to create a dark layer in front of my video? (Hero section) - css

I'm trying to create this layer effect in front of a video using Next.js and Chakra UI. Example made in Figma:
Code:
function Hero() {
const videoRef = useRef();
useEffect(() => {
setTimeout(()=>{
videoRef.current.play()
},1000)
}, []);
return (
<Box
display="flex"
alignItems="flex-end"
justifyContent="center"
width="100%"
height="100%"
>
<Box
position="relative"
top="0"
left="0"
zIndex="10"
_after={{bgGradient:"linear(180deg, rgba(6, 0, 11, 0.29) 70.65%, #06000B 100%)"}}
>
<video
ref={videoRef}
loop
autoplay
muted
/* controls */
preload="auto"
>
<source src="/hero.mp4" type="video/mp4"/>
</video>
</Box>
<Button
variant="outline"
color="#f3f3f3"
position="absolute"
zIndex="20"
marginBottom="50px"
bgGradient="linear(91.32deg,rgba(255, 255, 255, 0.2) 0%, rgba(255, 255, 255, 0.05) 98.96%)"
_hover={{
bgGradient:'linear(to-r, rgba(2, 43, 67, 1), rgba(41, 128, 185, 0.64))',
boxShadow:"4px 4px 30px -1px rgba(41, 128, 185, 0.72)",}}
>
CONHEÇA A COMUNIDADE
</Button>
</Box>
)
}
I saw some examples using ::before, but no one using chakra UI and everyone made with an image. Can anyone help me with this, please?

I think you can do this two ways:
Using background color and opacity on the video
The way you were doing, with the before/after, but as absolute with 100% width and height, I'll cover this approach below
function Hero() {
const videoRef = useRef();
useEffect(() => {
setTimeout(()=>{
videoRef.current.play()
},1000)
}, []);
return (
<Box
display="flex"
alignItems="flex-end"
justifyContent="center"
width="100%"
height="100%"
>
<Box
position="relative"
top="0"
left="0"
zIndex="10"
_after={{
bgGradient:"linear(180deg, rgba(6, 0, 11, 0.29) 70.65%, #06000B 100%)",
width: "100%",
height: "100%",
position: "absolute",
content: "",
top: 0,
left: 0
}}
>
<video
ref={videoRef}
loop
autoplay
muted
/* controls */
preload="auto"
>
<source src="/hero.mp4" type="video/mp4"/>
</video>
</Box>
<Button
variant="outline"
color="#f3f3f3"
position="absolute"
zIndex="20"
marginBottom="50px"
bgGradient="linear(91.32deg,rgba(255, 255, 255, 0.2) 0%, rgba(255, 255, 255, 0.05) 98.96%)"
_hover={{
bgGradient:'linear(to-r, rgba(2, 43, 67, 1), rgba(41, 128, 185, 0.64))',
boxShadow:"4px 4px 30px -1px rgba(41, 128, 185, 0.72)",}}
>
CONHEÇA A COMUNIDADE
</Button>
</Box>
)
}

Related

How to center-align a custom SVG icon in a Material-UI IconButton

I'm trying to produce an icon button that looks like this:
So far what I've got is this:
Here's the code:
import { SvgIcon, IconButton } from '#material-ui/core';
import {ReactComponent as homemadePlayIcon} from "./play-icon.svg"
<IconButton onClick={this.playIconButtonClick} disableRipple={true} style={{color: "rgb(0,0,0,0)", width: '35px', height: '35px', backgroundColor: '#f5f5f5', boxShadow: "3px 3px 10px rgba(0, 0, 0, 0.2)"}}>
<SvgIcon component={homemadePlayIcon} />
</IconButton>
How do I center-align the icon inside the icon button?
Thank you,
James
I got the desired result by using #svgr with the --icon option (to preserve the viewbox property of the SVG) and by including the generated component inside the IconButton as follows:
import { IconButton } from '#material-ui/core';
import PlayIcon from "./icons/PlayIcon.js"
<IconButton onClick={this.playIconButtonClick} disableRipple={true} style={{color: "rgb(0,0,0,0)", width: '35px', height: '35px', backgroundColor: '#f5f5f5', boxShadow: "3px 3px 10px rgba(0, 0, 0, 0.2)"}}>
<PlayIcon />
</IconButton>
Edit that with this:
<IconButton onClick={this.playIconButtonClick} disableRipple={true} style={{color: "rgb(0,0,0,0)", width: '35px', height: '35px', backgroundColor: '#f5f5f5', boxShadow: "3px 3px 10px rgba(0, 0, 0, 0.2)", display: "flex", justifyContent: "center", alignItems: "center"}}>

TestCafe: testing border property of element using testcafe

I am trying to test the border on an image using testcafe using getStyleProperty('border') and it always returns undefined. Other properties like box-shadow work fine.
HTML:
<img id="imgEdit" class="img-editable" [src]="imageUrl" style="border: 12px
solid rgb(0, 0, 0);" alt="editable image" />
const image = Selector('#imgEdit');
const imageBorder = await image.getStyleProperty('border');
imageBorder is always undefined.
border in CSS is considered a Shorthand property. This is the reason why you cannot find the border property.
If you console.log(image.style), you will see the actual border* CSS properties that represent the style="border: 12px
solid rgb(0, 0, 0);" in your HTML.
'border-bottom-color': 'rgb(0, 0, 0)',
'border-bottom-left-radius': '0px',
'border-bottom-right-radius': '0px',
'border-bottom-style': 'solid',
'border-bottom-width': '12px',
'border-collapse': 'separate',
'border-image-outset': '0px',
'border-image-repeat': 'stretch',
'border-image-slice': '100%',
'border-image-source': 'none',
'border-image-width': '1',
'border-left-color': 'rgb(0, 0, 0)',
'border-left-style': 'solid',
'border-left-width': '12px',
'border-right-color': 'rgb(0, 0, 0)',
'border-right-style': 'solid',
'border-right-width': '12px',
'border-top-color': 'rgb(0, 0, 0)',
'border-top-left-radius': '0px',
'border-top-right-radius': '0px',
'border-top-style': 'solid',
'border-top-width': '12px',
I am not sure which border property you want to test for, but here is a working example
image.getStyleProperty('border-bottom-color'); outputs rgb(0, 0, 0)

How to bind custom style in b-col (bootstrap-vue) element?

I need to add custom style to my <b-col /> element like below:
<b-container fluid class="bootstrap-container">
<b-row id="plan-execution">
<b-col :style="executionProgress" >Hello!</b-col>
</b-row>
</b-container>
In the executionProgress variable it stores my previously calculated styles eg:
background: linear-gradient(to right, rgba(0, 255, 0, 0.2) 0% , rgba(0, 255, 0, 0.2) 55.00%, rgba(0, 255, 0, 0.0) 57.00%) no-repeat
(The style is calculated depending on the data collected from the API)
I tried: :style="", v-bind:style="" but no effect.
In code below binding style works perfect
<table class="sah-table">
<tr id="plan-execution">
<td :style="executionProgress">Hello!</span></td>
</tr>
<table>
Short question: How I can bind my previously populated style to <b-col /> element?
Binding :style as string doesn't seem to work on Bootstrap Vue components. You can pass styles to them using an object, with camel-cased CSS properties (i.e. marginTop, backgroundImage, etc...) and string values. In your case:
executionProgress: {
background: 'linear-gradient(to right, rgba(0, 255, 0, 0.2) 0% , rgba(0, 255, 0, 0.2) 55.00%, rgba(0, 255, 0, 0.0) 57.00%) no-repeat'
}
See it working:
new Vue({
el: '#app',
template: '#appTemplate',
data: () => ({
executionProgress: {
background: 'linear-gradient(to right, rgba(0, 255, 0, 0.2) 0% , rgba(0, 255, 0, 0.2) 55.00%, rgba(0, 255, 0, 0.0) 57.00%) no-repeat'
}
})
})
.container {
background-color: #eee;
}
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css" />
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap-vue#latest/dist/bootstrap-vue.min.css" />
<script src="//polyfill.io/v3/polyfill.min.js?features=es2015%2CMutationObserver" crossorigin="anonymous"></script>
<script src="//unpkg.com/vue#latest/dist/vue.min.js"></script>
<script src="//unpkg.com/bootstrap-vue#latest/dist/bootstrap-vue.min.js"></script>
<script id="appTemplate" type="text/template">
<b-container class="bv-example-row">
<b-row>
<b-col>1 of 3</b-col>
<b-col>2 of 3</b-col>
<b-col :style="executionProgress">3 of 3</b-col>
</b-row>
</b-container>
</script>
<div id="app"></div>
A quick test shows us string notation on Vue components works, so this is a Bootstrap Vue specific problem:
Vue.component('testComponent', {
template: '#testTemplate',
props: {
style: {
type: String | Object,
default: ''
}
}
})
new Vue({
el: '#app',
template: '#appTemplate',
data: () => ({
stringStyle: 'background: linear-gradient(to right, rgba(0, 255, 0, 0.2) 0% , rgba(0, 255, 0, 0.2) 55.00%, rgba(0, 255, 0, 0.0) 57.00%) no-repeat'
})
})
body {
margin: 0;
}
<script src="//unpkg.com/vue#latest/dist/vue.min.js"></script>
<script id="appTemplate" type="text/template">
<test-component :style="stringStyle" />
</script>
<script id="testTemplate" type="text/template">
<div :style="style">
<slot>test</slot>
</div>
</script>
<div id="app"></div>
Edit: Filed it as a Bootstrap Vue bug here.
I solved my problem a little differently than #Andrei Gheorghiu suggested.
I used "normal" <div class="col" /> instead of <b-col /> and works.
My solution:
<div class="container sah-table">
<div id="plan-execution" class="row">
<div class="col-sm-12" :style="executionProgress">Hello</div>
</div>
</div>
my executionProgress variable I calculate:
calculateExecutionProgress: function(progress: number) {
let alpha = '0.2'
this.executionProgress = 'background: linear-gradient(to right, rgba(0, 255, 0, ' + alpha + ') 0% , rgba(0, 255, 0, ' + alpha + ') ' + (Math.min(progress,1) * 100).toFixed(2) + '%, rgba(0, 255, 0, 0.0) ' + ((Math.min(progress + 0.02, 1)) * 100).toFixed(2) + '%) no-repeat';
console.log(this.executionProgress)
},
and it works too.
I don't like not knowing what I'm doing wrong, I have two solutions now :)

How to clip border in react-native application?

Here's the image of what I want to achieve with the green button in the layout.
Notice the border above the view B? I want the border of the bottom bar to have a curve around it.
So to do this I've created views structure -
import React from 'react'
import { Text, View } from 'react-native'
class OkScreen extends React.Component {
static navigationOptions = {
header: null
}
render () {
return (
<View
style={{
flexDirection: 'column',
alignSelf: 'stretch',
flexGrow: 1
}}
>
<View
style={{
backgroundColor: 'yellow',
flexGrow: 1
}}
/>
<View
style={{
borderWidth: 1
}}
/>
<View
style={{
backgroundColor: 'white',
flexDirection: 'row',
justifyContent: 'space-evenly',
alignItems: 'center',
height: 150,
borderTopWidth: 10,
borderTopColor: 'white'
}}
>
<View
style={{
borderWidth: 10,
alignItems: 'center',
justifyContent: 'center',
height: 152,
width: 152,
borderRadius: 76,
bottom: 40
}}
>
<View
style={{
height: 150,
width: 150,
borderRadius: 75,
backgroundColor: 'green',
alignItems: 'center',
justifyContent: 'center',
borderWidth: 10,
borderColor: 'white'
}}
>
<Text
style={{
fontSize: 40
}}
>
B
</Text>
</View>
</View>
</View>
</View>
)
}
}
export default OkScreen
This approach did not work and it ends up looking like this -
What approaches should I take to make this work? Any suggestion(s) would be appreciated.
You can add a white circular view behind the white view containing the button, give this circle the border needed, and give the button a zIndex = 3 and the containing view zIndex = 2.
use position: absolute to position views on top of each other, adjust it with top, bottom, left, right. A tip: use the StyleSheet component and keep all styles there and don't rely on points when setting width, height, etc.. use '%' or const {width, height} Dimensions.get('window') and use them to make your app responsive
You can do this on the yellow element instead using radial-gradient and linear-gradient like below (not sure about the support in react native):
.yellow {
height:100px;
background:
linear-gradient(#000,#000) right bottom/calc(50% - 50px) 3px no-repeat,
linear-gradient(#000,#000) left bottom /calc(50% - 50px) 3px no-repeat,
radial-gradient(circle at 50% 100%,transparent 49px,#000 50px,#000 52px,yellow 53px);
}
.green {
width:80px;
height:80px;
margin: -40px auto;
background:green;
border-radius:50%;
}
<div class="yellow">
</div>
<div class="green">
</div>
You can also consider a mix of border and box-shadow to approximate this:
.yellow {
height:100px;
background:yellow;
border-bottom:2px solid;
}
.green {
width:100px;
height:100px;
border:2px solid transparent;
border-top-color:#000;
box-sizing:border-box;
margin: -17px auto;
padding:2px;
background:green content-box;
box-shadow:0 0 0 10px #fff inset;
border-radius:50%;
}
<div class="yellow">
</div>
<div class="green">
</div>

Corner radius applied only to specific corners

I've this tabs that I wanted to make rounded only on top-right and top-left corners. But it ended up rounding all 4 corners.
What I did:
<mx:TabNavigator id="myTabNav" x="58" y="61" width="584" height="200" creationComplete="setColors(event)" styleName="myTabStyle">
<pages:One label="ThisOne" id="one" name="One"/>
<pages:Two label="Twoooooooooooh" id="two" width="584" name="two" />
<pages:Three label="Threeeeeeeeh" id="three" width="583" name="three" />
</mx:TabNavigator>
and
my pageStyles.css file is:
.myTabStyle {
tabStyleName: "myTabs";
corner-radius:15;
}
.myTabs {
backgroundColor: #FF0080;
corner-radius:10;
focusRoundedCorners: "tl tr";
skin:ClassReference('mx.skins.spark.ButtonSkin');
chromeColor: #FF0080; /* this is the tab widget itself, not the content */
border-style:outset;
}
As you can see I have the "focusRoundedCorners" to point to top-right and top-left but no luck. What I got is:
What am I doing wrong guys??
Thanks in advance.
Have a look at this tool http://www.wabysabi.com/flex/enhancedbuttonskin/
I would guess that the focus part of the focusRoundedCorners refers to how it should be when it has focus only..
So here is the solution.
You can write you own button skin or use the one here http://www.wabysabi.com/flex/enhancedbuttonskin/
named EnhancedButtonSkin.as (right-click, View-Source).
Then declare your TabNavigator component and specify its tabStyleName.
<mx:TabNavigator y="0" height="100%" right="0" left="0" id="navigator" tabStyleName="tab">
And now the css:
<fx:Style>
.tab
{
upSkin:ClassReference('com.EnhancedButtonSkin');
overSkin:ClassReference('com.EnhancedButtonSkin');
downSkin:ClassReference('com.EnhancedButtonSkin');
disabledSkin:ClassReference('com.EnhancedButtonSkin');
selectedUpSkin:ClassReference('com.EnhancedButtonSkin');
selectedOverSkin:ClassReference('com.EnhancedButtonSkin');
selectedDownSkin:ClassReference('com.EnhancedButtonSkin');
selectedDisabledSkin:ClassReference('com.EnhancedButtonSkin');
cornerRadii: 5, 5, 0, 0;
borderColors: #CC0000, #000000;
overBorderColors: #003399, #003399;
selectedBorderColors: #666666, #FFFFFF;
borderThickness: 1;
borderAlpha: 1;
fillColors: #CC3300, #F98900;
fillAlphas: 1, 1;
fillColorRatios: 0, 255;
overFillColors: #999999, #FFFFFF;
overFillAlphas: 1, 1;
overFillColorRatios: 0, 255;
selectedFillColors: #999999, #FFFFFF;
selectedFillAlphas: 1, 1;
selectedFillColorRatios: 111, 255;
highlightAlphas: 0, 0;
color: #000000;
textRollOverColor: #000000;
fontSize: 13;
}
</fx:Style>
This css will display:

Resources