YUI Tutorial not working - yui

Why does this code from this YUI3 example not work for me?
HTML:
<!-- The original body content is above -->
<div id="form_container">
<form class="yui3-widget-bd" id="theme_form" action="#" method="get">
<fieldset>
<h3>Update Theme</h3>
<label for="font_size">Font size:</label>
<input type="text" size="3" id="font_size" value="16px">
<label for="heading_color">Heading color:</label>
<input type="text" size="12" id="heading_color" value="#005A9C">
<label for="link_hover">Link hover backgound:</label>
<input type="text" size="12" id="link_hover" value="#ffa">
</fieldset>
<input type="submit">
</form>
</div>
Javascript:
// Create a new YUI instance, requiring stylesheet, overlay, slider, and the
// dd-plugin to make the overlay draggable
YUI({
filter: 'raw'
}).use("stylesheet", "overlay", "slider", "dd-plugin", function(Y) {
var myStyleSheet = new Y.StyleSheet(),
overlayContent = Y.one('#form_container'),
overlay, slider, slider_container, fontSizeInput;
// Create the Overlay, using the form container as the contentBox.
// The form is assigned a class yui-widget-bd that will be automatically
// discovered by Overlay to populate the Overlay's body section.
// The overlay is positioned in the top right corner, but made draggable
// using Y.Plugin.Drag, provided by the dd-plugin module.
overlay = new Y.Overlay({
srcNode: overlayContent,
width: '225px',
align: {
points: [Y.WidgetPositionAlign.TR, Y.WidgetPositionAlign.TR]
},
plugins: [Y.Plugin.Drag]
}).render();
// Slider needs a parent element to have the sam skin class for UI skinning
overlayContent.addClass('yui3-skin-sam');
// Progressively enhance the font-size input with a Slider
fontSizeInput = Y.one('#font_size');
fontSizeInput.set('type', 'hidden');
fontSizeInput.get('parentNode').insertBefore(
Y.Node.create('6 <span></span> 36'), fontSizeInput);
slider_container = fontSizeInput.previous("span");
// Create a Slider to contain font size between 6px and 36px, using the
// page's current font size as the initial value.
// Set up an event subscriber during construction to update the replaced
// input field's value and apply the change to the StyleSheet
slider = new Y.Slider({
length: '100px',
min: 6,
max: 36,
value: parseInt(Y.one('body').getStyle('fontSize')) || 13,
after: {
valueChange: function(e) {
var size = e.newVal + 'px';
this.thumb.set('title', size);
fontSizeInput.set('value', size);
myStyleSheet.set('body', {
fontSize: size
});
}
}
}).render(slider_container);
// The color inputs are assigned keyup listeners that will update the
// StyleSheet if the current input value is a valid CSS color value
// The heading input affects all h1s, h2, and h3s
Y.on('keyup', function(e) {
var color = this.get('value');
console.log(color);
if (isValidColor(color)) {
console.log("Valid color", myStyleSheet);
myStyleSheet.set('h1, h2, h3', {
color: color
});
}
}, '#heading_color');
// The link hover affects the background color of links when they are
// hovered. There is no way other than via stylesheet modification to
// change pseudo-class styles.
Y.on('keyup', function(e) {
var color = this.get('value');
if (isValidColor(color)) {
myStyleSheet.set('a:hover', {
backgroundColor: color
});
}
}, '#link_hover');
// Progressive form enhancement complete, now prevent the form from
// submitting normally.
Y.on('submit', function(e) {
e.halt();
}, '#theme_form');
// A rudimentary validator to make sure we're not trying to set
// invalid color values in StyleSheet.
function isValidColor(v) {
return /^#[0-9a-f]{3}(?:[0-9a-f]{3})?$/i.test(v) || /^rgb\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*\)$/.test(v) || /^[a-z]{3,}$/i.test(v);
}
});
CSS:
/* For supporting browsers, the overlay is rendered semi-transparent with
* fancy rounded corners */
.yui3-overlay {
background: rgba(128,128,128,0.3);
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
padding: 7px;
cursor: move;
}
.yui3-overlay-content {
background: rgba(205,205,205,0.3);
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
padding: 1px;
}
.yui3-overlay form {
background: #f2fbff;
border: 2px solid #fff;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
margin: 0;
padding: 0;
font-size: 13px;
}
.yui3-overlay fieldset {
border: 1px solid #bcd;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
margin: 0;
padding: 20px;
}
.yui3-overlay h3 {
border-bottom: 2px solid #fff;
color: #479;
background: transparent;
margin: 0;
font-size: 175%;
}
.yui3-overlay label {
display: block;
margin: 1.3em 0 0.5ex;
font-weight: bold;
color: #003;
}
.yui3-overlay p {
margin: 2em 0 0;
}
/* override the move cursor for the Slider */
.yui3-overlay .yui3-slider:hover {
cursor: default;
}
I just copied and pasted the code, can anyone help?

Your tag is missing class="yui3-skin-sam yui-skin-sam"

It appears to be working. I copied/pasted your code into this jsfiddle. Change with the slider and header color change field, it seems to update the color and size.

This is not the best forum to do support debugging.
You're welcome to ask in the #yui channel on freenode rather than go through slow, back and forth debugging here.

Related

Size of the map when redenring mapbox in React

I trying to use mapbox GL to render a map in React.
I've diveide my screen in 4(2 col/crow) with Grid with the following css:
.container {
font-family: sans-serif;
margin: 0;
display: grid;
grid-template-rows: 1fr 7fr;
grid-template-columns: auto;
gap: 5px;
grid-template-areas: "cr1 cr2"
"cr1 cr4";
height: 100vh;
width: 200vh;
background-color: chartreuse;
}
.table {
grid-area: cr1 ;
background-color: aqua;
display: flex;
justify-content: center;
align-items: center;
}
.tank-select {
grid-area: cr2;
background-color: grey;
}
.map {
grid-area: cr4;
display: flex;
justify-content:space-around;
align-items:stretch;
background-color: blueviolet;
}
i would like to have the map in the box cr4 with the following code:
<div className="container">
<div className="table">test</div>
<div className="tank-select">test2</div>
<div className="map">
<Map />
</div>
</div>
The map is compute this way:
const mapContainerRef = useRef(null)
const [lng, setLng] = useState(5)
const [lat, setLat] = useState(34)
const [zoom, setZoom] = useState(1.5)
// Initialize map when component mounts
useEffect(() => {
const map = new mapboxgl.Map({
container: mapContainerRef.current,
style: 'mapbox://styles/mapbox/streets-v11',
center: [lng, lat],
zoom: zoom,
})
// Add navigation control (the +/- zoom buttons)
map.addControl(new mapboxgl.NavigationControl(), 'top-right')
map.on('move', () => {
setLng(map.getCenter().lng.toFixed(4))
setLat(map.getCenter().lat.toFixed(4))
setZoom(map.getZoom().toFixed(2))
})
// const marker = new mapboxgl.Marker().setLngLat(TankLocationArray).addTo(map)
//
map.on('load', function () {
map.addSource('route', {
type: 'geojson',
data: '../../assets/data/test.geoJSON',
})
map.addLayer({
id: 'route',
type: 'symbol',
source: 'route',
paint: {
'circle-radius': 10,
'circle-color': '#ff0000',
},
})
})
//
// Clean up on unmount
return () => map.remove()
}, []) // eslint-disable-line react-hooks/exhaustive-deps
return (
<div>
<div className="sidebarStyle">
<div>
Longitude: {lng} | Latitude: {lat} | Zoom: {zoom}
</div>
</div>
<div className="map-container" ref={mapContainerRef} />
</div>
With the css:
.map-container {
position:relative;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.sidebarStyle {
display: inline-block;
position: absolute;
top: 0;
left: 0;
margin: 12px;
background-color: #404040;
color: #ffffff;
z-index: 1 !important;
padding: 6px;
font-weight: bold;
}
When i change the map-container position from relative to absolute, the map would take the whole screen, otherwise it's not visible.
I do not know how to style to get the map to appear only in the box .map(cr4).
thanks for the help
solved the issue using React Map GL library.
works really fine. https://www.npmjs.com/package/react-map-gl

how to draw excel style data bars in angular?

I want to add databars behind values in the selected column in my grid like the Data Bars Conditional Formatting option in Excel.
This answer show me the thing using jquery data table, Can anyone give me the idea for this in angular 6.
Note: I am not using any 3rd party grid, I have created this grid from my own.
It should look something like this.
Not sure in what scenario you want to add this, but have a look at this:
https://css-tricks.com/css3-progress-bars/
This is classic HTML and CSS "trick" to create a bar which you can define length of.
The basics of it is that you have a "wrapper" element that defines the maximum length, and a "bar" element inside that you set width: [0-100]% and a background color of that.
This would be an example on how to create a 50% wide blue bar.
.wrapper {
width: 100%;
}
.bar {
background: blue;
height: 5px;
}
<div class="wrapper">
<div class="bar" style="width: 50%"></div>
</div>
Use that to create an angular component that you can send you width to, something like this:
import { Component, Input } from '#angular/core';
#Component({
selector: 'app-bar',
template: `
<div class="wrapper">
<div class="bar" [style.width]="width"></div>
</div>
`,
styles: [`
.wrapper {
width: 100%;
}
.bar {
background: blue;
height: 5px;
}
`]
})
export class BarComponent {
#Input() width: number;
}
This will do the job.
#Component({
selector: 'my-app',
template: `
<div class="holder">
<div class="bar" *ngFor="let item of data">
<div #bar class="{{item >= 0 ? 'positive' : 'negative'}}">
<div class="size" [style.width.px]="getWidth(item, bar)">
{{item}}
</div>
</div>
</div>
</div>
`
})
class AppComponent {
maxValue = 100;
data: Number[] = [
10,20,30,-45,90,-90,-80,50,100
]
getWidth(dataItem: number, bar: HTMLElement):number {
return (parseInt(bar.offsetWidth) / this.maxValue) * Math.abs(dataItem);
}
}
CSS:
.holder {
border: 1px solid black;
margin: 10px;
padding: 5px;
width: 200px;
}
.bar {
border: 1px solid grey;
padding: 3px;
margin: 10px 5px;
text-align: center;
}
.positive {
color: blue;
width: 90px;
margin-left: 90px;
}
.negative {
color: red;
width: 90px;
margin-right: 90px;
.size {
margin-left: auto
}
}
.size {
background: green;
}
You can use primeNg data table, and their cell formatting feature, we can format each cell based on certain condition like changing the color or painting it, this may help you.
PrimeNg Cell Style

Display hex color created by sass

I have a simple page here:
http://www.ttmt.org.uk/color/
The center blocks color is saved as a variable in sass
The color of the blocks either side are created with sass's lighten and darken.
Is it possible to display the actual hex number of these lighter and darker colors that sass has created.
The color's hex are displayed in the output css but I'd like to be able to do it dynamically and display the hex color in the block.
I have the colors in scss file
$base-blue: #267EC8;
// Blue
.at-blue{
background-color: $base-blue;
}
.at-blue-lighter{
background-color: lighten($base-blue, 20%);
}
.at-blue-light{
background-color: lighten($base-blue, 10%);
}
.at-blue-dark{
background-color: darken($base-blue, 10%);
}
.at-blue-darker{
background-color: darken($base-blue, 20%);
}
Then I'm using the class name in the html
<div class="my_Box at-blue-lighter" >.at-blue-lighter<span></span></div>
<div class="my_Box at-blue-light" >.at-blue-light<span></span></div>
<div class="my_Box at-blue" >.at-blue <span></span></div>
<div class="my_Box at-blue-dark" >.at-blue-dark<span></span></div>
<div class="my_Box at-blue-darker" >.at-blue-darker<span></span></div>
And styling the box in separate scss file
.my_Box{
text-align: center;
height: 120px;
float: left;
padding: 10px;
margin: 0 30px 0 0;
width: 120px;
span{
display: block;
font-size: 1.2em;
margin: 10px 0 0 0;
}
}
You can use content to show it : http://jsfiddle.net/A9rML/
$color : rgb(38, 126, 200);
div{
background-color: $color;
&:after{
content: "#{$color}";
font-size: 42px;
color: white;
}
width: 200px;
height: 200px;
}

span width property is being disabled

Hi I am teaching myself some backbone from tutorials, and I want to create a table like display element using spans.
So I added a width element into my span in the template. (I know it isn't the best place to put it, but it should take priority over stylesheet properties, and is just to get an idea during development).
<script type="text/template" id="loadedwith-template">
<span style="width:100" class="library"><%= library.name %></span>
<input style="width:100" class='input' type="text" />
<button class="delete_lw" >delete</button>
</script>
However when I look at it in the browser, the element shows up as before without the width setting applied.
"Inspect element" in Chrome shows the width property, but is disabled (has a line like html strikethrough on it). This is the last thing shown in element styles before the computed styles section.
There is another stylesheet referencing the span. Is there anything causing the width to be disabled? The other stylesheet is as follows (borrowed from the backbone tutorial). (The span is inside a list).
a { color: #2929FF; }
a:visited { color: #777; }
a:hover {
color: #8F8FFF;
text-decoration: none;
}
body, button { font: 100%/1.4 "Helvetica Neue", Helvetica, Arial, sans-serif; }
body {
background: #FFF;
color: #444;
padding: 25px 50px;
}
button, .delete, .swap {
border: 0;
border-radius: 5px;
color: #FFF;
cursor: pointer;
font-weight: bold;
line-height: 1;
text-align: center;
text-transform: uppercase;
}
button:hover, .delete:hover, .swap:hover { opacity: 1; }
button {
background: #2929FF;
font-size: 0.75em;
padding: 7px 12px;
opacity: .75;
}
h1 {
font-size: 1.25em;
letter-spacing: -0.5px;
}
p {
color: #777;
font: italic 0.75em/1.2 "Georgia", Palatino, "Times New Roman", Times, serif;
}
span {
display: inline-block;
margin-right: 10px;
}
ul { padding-left: 0; }
.delete, .swap {
font-size: 0.625em;
opacity: .25;
padding: 3px 10px;
position: relative;
top: -3px;
}
.delete { background: #FF29D0; }
.swap { background: #FF6529; }
You need to specify a unit of measurement
Specifying CSS units is a requirement for non-zero values. Browsers may try to guess what you meant, but it would still be a broken stylesheet according to the standard.
I.e. there is no "default unit" in CSS, it's just that the browser may try to help you out, although it may as well just ignore your statement that doesn't specify units as an invalid one.
Try style="width:100px"
You should specify a unit, like px:
style="width: 100px"

Jquery Masonry with fixed height

I have a list of items that I want to display all with the same height, but different widths and dynamically generated. I want them all to display in a way to use up as much white space as possible. I thought masonry would help, but it seems to be making weird gutters in between.
Is there an option in jquery-masonry or an alternative plugin that I should use instead?
HTML:
<div class="tagbox">
<div>test</div>
<div>technology</div>
<div>search</div>
<div>a longer test item</div>
<div>another test</div>
<div>development</div>
</div>
Styles:
display: block;
float: left;
margin-bottom: 5px;
margin-right: 5px;
padding: 10px;
text-decoration: none;
white-space: nowrap;
Javascript:
$('.tagbox').masonry({
itemSelector: 'div',
isFitWidthBooleanfalse: true,
gutterWidth: 0,
columnWidth: function (containerWidth) {
return containerWidth / 5;
}
});

Resources