YUI - Set padding style to drag node - css

I'm trying to set padding style to my drag node. I can set background-color but not padding.
Y.DD.DDM.on('drag:start', function(e) {
var drag = e.target;
drag.get('dragNode').setStyles({
backgroundColor: drag.get('node').getStyle('backgroundColor'),
padding: drag.get('node').getStyle('padding')
});
});
What I'm doing wrong ?

As said here : http://yuilibrary.com/trac-archive/tickets/2528774.html
I have to request all attributes individually with getComputedStyle()
paddingTop: drag.get('node').getComputedStyle('paddingTop'),
paddingBottom: drag.get('node').getComputedStyle('paddingBottom'),
paddingRight: drag.get('node').getComputedStyle('paddingRight'),
paddingLeft: drag.get('node').getComputedStyle('paddingLeft')

Related

Why is element height different in Safari than it is in Chrome, Firefox?

I'm trying to create a "collapsible text" react component that allows a user-determined number of lines to be displayed. I'm using the line-clamp CSS property to do this, for the most part. On the JavaScript side of things, I want to selectively render a button that toggles the effect based on whether the content to be shown is greater in height than the number of lines to be shown multiplied by their line height. This is working fairly well in Firefox and Chrome. I can get the line height of the element after it's rendered, and I can multiply that by the number of lines that the user wants shown to approximate the height of the content. I can use that to set a min-height CSS property, and I can compare that value against the scroll height of the content. The problem is, I'm getting the same value for the scroll height of the content in Firefox and Chrome, but NOT in Safari.
const CollapsibleText = ({
text,
linesToShow,
markdown = false,
containerStyles,
textStyles,
buttonStyles,
handleScroll,
}) => {
const [isActive, setIsActive] = useState(false)
const contentRef = useRef(null)
const [displayButton, setDisplayButton] = useState(false)
const [contentMinimumHeight, setContentMinimumHeight] = useState(null)
const windowSize = useWindowSize()
const linesShown = windowSize.mobile
? parseInt(linesToShow[0])
: parseInt(linesToShow[1])
const handleToggleIsActive = () => {
if (isActive && handleScroll) {
handleScroll()
}
setIsActive(!isActive)
}
useEffect(() => {
const contentLineHeight = parseInt(
window
.getComputedStyle(contentRef.current, null)
.getPropertyValue('line-height')
)
const contentHeight = contentRef.current.scrollHeight
// Adding 5 here to offset rounding that seems to occur in actual pixel values of rendered output, value of 5 is arbitrary.
const linesToShowHeight = contentLineHeight * linesShown + 5
setContentMinimumHeight(linesToShowHeight)
console.log('Content height: ', contentHeight)
console.log('Lines to show height: ', linesToShowHeight)
if (contentHeight > linesToShowHeight) {
setDisplayButton(true)
}
if (contentHeight < linesToShowHeight) {
setDisplayButton(false)
}
}, [windowSize])
return (
<div sx={{ ...containerStyles }}>
<div
sx={{
display: '-webkit-box',
'-webkit-line-clamp': !isActive ? linesToShow : 'none',
lineClamp: !isActive ? linesToShow : 'none',
'-webkit-box-orient': 'vertical',
overflow: 'hidden',
outline: '2px solid red',
textOverflow: 'ellipsis',
minHeight: contentMinimumHeight,
'&:first-child': {
marginTop: '0px',
},
}}
>
{markdown ? (
<div
ref={contentRef}
sx={{
...textStyles,
'& *:first-child': {
marginTop: '0px',
// marginBottom: '0px',
},
}}
dangerouslySetInnerHTML={{
__html: text,
}}
/>
) : (
<p
ref={contentRef}
sx={{
whiteSpace: 'pre-wrap',
...textStyles,
}}
>
{text}{' '}
</p>
)}
</div>
{displayButton && (
<Button
variant="viewMore"
sx={{ marginTop: '20px', ...buttonStyles }}
onClick={handleToggleIsActive}
>
{!isActive ? 'Read more' : 'Read Less'}{' '}
<ChevronDown
styles={{ transform: !isActive ? 'none' : 'rotate(180deg)' }}
/>
</Button>
)}
</div>
)
}
export default CollapsibleText
To determine the content height, I'm using a ref and grabbing the scroll height of the element in question. I get the same value in Chrome and Firefox, but a larger value in Safari, which breaks my ability to selectively render the "toggle" button I'm trying to implement.
I'm comparing the "line height" (with my admittedly very simplistic algorithm) against the content height to determine whether or not to render the button. I get the same measurement in all three browsers, so as far as I can tell Safari is just measuring the scroll height of the content differently than in Chrome and Firefox.
I seemingly have to use a min height because the line-clamp property causes the content to collapse to zero in Safari. Setting the min height allows things to work more or less as predicted where the content is more than the user-defined lines to show prop given to the component.
Screenshots of the console logs for the SAME content in each browser:
Firefox:
Chrome:
Safari:

Add space between Icon and text that is rendered in component prop (React)

I have a RightHeadingContainer that is a styled div:
const RightHeadingContainer = styled.div({
color: 'white',
alignSelf: 'center',
fontSize: 17,
fontWeight: 400,
paddingLeft: '56px',
paddingRight: '56px',
justifyContent: 'flex-end'
})
it is rendering in my Header component:
<RightHeadingContainer>{rightHeading}</RightHeadingContainer>
The rightHeading prop is being passed to my SlidingPanel:
const StyledRightHeadingContainer = styled.div({
fontWeight: 'bold',
display: 'inline-flex',
alignItems: 'center'
})
const Panel = ({ selectedAccName, selectedAccNumber }) => {
return (
<SlidingPanel
rightHeading={
<StyledRightHeadingContainer>
<Member colour='white' size='XL' />
{`${selectedAccName}`} {`${selectedAccNumber}`}
</StyledRightHeadingContainer>
} />
)
}
export default Panel
In my sliding panel I'm passing an icon 'Member' and some variables. At the moment the icon is right against the text of the first variable and am unsure how to add spacing between them. I've tried using flex but get no results I believe because of the rendering through a prop value. How can I add spacing between the two elements without hardcoding it?
You can either use &nbsp Between the text and the icon or add padding/margin in the icon component
Something like
<Member colour='white' size='XL' styles={{paddingRight: ‘10px’}} />
Or
<StyledRightHeadingContainer>
<Member colour='white' size='XL' />
{`${selectedAccName}`} {`${selectedAccNumber}`}
</StyledRightHeadingContainer>

How to use #media to change width in prop styled components

I am not sure if what they called but I have a component which takes its style as an object with its props.
const PricingSection = ({
secDesc,
}) => {
return (
<Text
{...secDesc}
content={intl.formatMessage({ id: 'packages.description' })}
/>
);
};
PricingSection.propTypes = {
secDesc: PropTypes.object
};
PricingSection.defaultProps = {
secDesc: {
width: '50%',
m: 'auto',
textAlign: 'center',
pt: '20px',
color: '#6a7a8d',
lineHeight: '1.5rem',
},
}
I want to apply different witdh for mobile devices. I know how to use #media tag in css but I dont know where to write #media in this component or how achieve what I want.
Instead of passing style object, it would be better if you apply a class to the component for easy maintenance. It'll also solve your problem for width for different size devices as you can add media query for the class in its css file.
Another suggestion would be to use styled-components. They provide great support for adding media queries inside the component file.
Refer:styled-components
you can use 'react-device-detect' and pass the different width from parent component like this:
enter code here
import isMobile from 'react-device-detect'
secDesc: {
width: isMobile ? '50%' : 'your value',
m: 'auto',
textAlign: 'center',
pt: '20px',
color: '#6a7a8d',
lineHeight: '1.5rem',
}
< PricingSection
secDesc={secDesc}
/>

What is the proper way to change only one element in in css but the others remains

I have an element has these CSS properties, applied with Stylesheet option of react-native
const styles = StyleSheet.create({
card: {
marginTop: 30,
marginLeft: 50,
marginRight: 50,
padding: 20,
backgroundColor: '#74C8AF',
borderRadius: 10,
flex: 1,
flexDirection: 'column',
},
})
I want to implement this "card" property to all my cards but just want to alter only backgroundColor property unique to each card. Is there any way to handle this just in one card object, without setting different card objects for each individual?
I tried to change style like this but it discards whole object and only applies backgroundcolor
<Card style={styles.card, {backgroundColor:"#9932cc"}}>
//...
</Card>
use like this
<Card style={[styles.card, {backgroundColor:"#9932cc"}]}>
instead of
<Card style={styles.card, {backgroundColor:"#9932cc"}}>
I usually do something along the lines of:
<View style={this.jewelStyle()} />
jewelStyle = function(options) {
return {
borderRadius: 12,
background: randomColor(),
}
}
Every time View is rendered, a new style object will be instantiated with a random color associated with it. Of course, this means that the colors will change every time the component is re-rendered, which is perhaps not what you want. Instead, you could do something like this:
var myColor = randomColor()
<View style={jewelStyle(myColor)} />
jewelStyle = function(myColor) {
return {
borderRadius: 10,
background: myColor,
}
}

How to use percentage padding top and bottom in React Native?

I am trying to achieve dynamic padding top and bottom. I am aware that paddingTop and paddingBottom with % will use the width of the container and I am fine with that.
Unfortunately when I do set the paddingTop to any value with %, it sets the paddingBottom to the same value. Basically paddingTop: '5%', paddingBottom: '0%' will give me equal 5% paddings on both sides.
If I set paddingBottom to any % value - it's just being added to the value that came form the top. So: paddingTop: '5%', paddingBottom: '10%' results in paddingBottom equal to 15%...
I checked the same solution in a web project and there it works as expected.
The snack presenting the problem:
https://snack.expo.io/BJ9-2t8LB
The problem is on both Android and iOS.
How to solve it?
Apply the value to the child container to be applied, not to the parent container.
I have modified the answer according to the conditions you want. You should send Bottom's territory to the parent's container. Because they interact with each other in their child's container, they must be independent.
import * as React from 'react';
import { Text, View, StyleSheet } from 'react-native';
export default class App extends React.Component {
render() {
return (
<View style={styles.wrapper}>
<View style={styles.inner}>
<View style={{ backgroundColor: 'yellow' }}>
<Text>TOP</Text>
</View>
</View>
<View style={{ backgroundColor: 'red', }}><Text>BOTTOM</Text></View>
</View>
);
}
}
const styles = StyleSheet.create({
wrapper: {
flex:1,
paddingLeft: 24,
paddingRight: 24,
backgroundColor: 'green',
paddingBottom:"5%"
},
inner: {
flex:1,
justifyContent: 'space-between',
backgroundColor: 'blue',
marginTop:"10%"
},
});
That is strange behavior, you should bring it up as an issue to react-native.
In the meantime, a workaround would be applying marginTop and marginBottom to the inner View, instead of paddingTop and paddingBottom to the wrapper View.
const styles = StyleSheet.create({
ayz:{
marginTop:"15%",
backgroundColor:'pink',
alignItems:'center',
justifyContent:'center',
},
asd:{
color:'white',
fontSize:50,
fontWeight:'bold'
}
});

Resources