Components are not draggable in Angular2 for Dart when bind objects using ngFor - dart

I've created a component which is a draggable element.
#Component(
selector: 'draggable-component',
styles: const ['.element-to-drag {background-color: yellow; border: 1px solid blue; height: 50px; width: 50px;}'],
template: '''
<div class="element-to-drag"
draggable="true"
(dragstart)="onDragStart(\$event)"
(dragend)="onDragEnd(\$event)">
</div>''')
class DraggableComponent {
void onDragStart(MouseEvent e) {
print('onDragStart');
}
void onDragEnd(MouseEvent e) {
print('onDragEnd');
}
}
When I use it as a single element it fires drag start event and COULD BE dragged to the drop zone.
When I create it using ngFor of primitives list (numbers) all elements fire drag start event and COULD BE dragged to the drop zone.
But when I create it using ngFor of objects list all elements fire drag start event but COULD NOT BE dragged to the drop zone (they are not dragged).
Here is an example:
#Component(
selector: 'my-app',
directives: const [DraggableComponent, NgFor],
styles: const ['.container {border: 1px solid red;; height: 100px; width: 100px;}'],
template: '''
<div>
<div class="container"></div>
<h3>Single</h3>
<draggable-component></draggable-component>
<h3>Primitives</h3>
<draggable-component *ngFor="#example of examplesPrimitives"></draggable-component>
<h3>Objects</h3>
<draggable-component *ngFor="#example of examples"></draggable-component>
</div>
''')
class AppComponent {
get examples => [
{"name": 1},
{"name": 2},
{"name": 3},
{"name": 4} ];
get examplesPrimitives => [ 1,2,3,4,5];
}
How can I make bindings of objects draggable?

It was Angular2 wit Dart bug. Angular2 with TypeScript works fine in the same case.
An issue was created in Angular repository:
https://github.com/angular/angular/issues/6975

Related

How to add a dropdown menu with Logout option using ant d in React typescript

Here is the sample code, i have a avatar and onclick of it i want to show a small dropdown with logout option and possibly username.
import { Avatar, Layout } from 'antd';
<StyledAvatar size="small"> {initials} </StyledAvatar>
const StyledAvatar = styled(Avatar)`
margin-left: ${({ theme }: { theme: Theme }) => theme.paddings.small}px;
color: black;
background-color: white;
font-weight: bold;
`;
<Dropdown
overlay={menu}
trigger={["click"]}
placement="bottomLeft"
>
<div onClick={e => e.preventDefault()}>
<Avatar size="large" icon={<UserOutlined />} />
</div>
</Dropdown>
We put the avatar component inside the Dropdown component.

How to change default font size for ag-grid row cells in react js?

I am using ag-grid table for first time. I am not able to change the default font size of row cells(Not header portion). I want to change the font size of row cells(row data). I am using ag-theme-alpine.
Here is the code which I am using.
import React, { Component } from 'react';
import { render } from 'react-dom';
import { AgGridReact } from 'ag-grid-react';
import 'ag-grid-community/dist/styles/ag-theme-alpine.css';
class App extends Component {
constructor(props) {
super(props);
this.state = {
columnDefs: [
{headerName: 'Make', field: 'make'},
{headerName: 'Model', field: 'model'},
{headerName: 'Price', field: 'price'}
],
rowData: [
{make: 'Toyota', model: 'Celica', price: 35000},
{make: 'Ford', model: 'Mondeo', price: 32000},
{make: 'Porsche', model: 'Boxter', price: 72000}
]
}
}
render() {
return (
<div
className="ag-theme-alpine"
style={{ height: '500px', width: '100%',fontSize:'20px' }}
>
<AgGridReact
columnDefs={this.state.columnDefs}
rowData={this.state.rowData}>
</AgGridReact>
</div>
);
}
}
render(<App />, document.getElementById('root'));
Please suggest a good solution.
You can do this in the ColDef by setting the cellStyle property in ColDef. You can set the font size as follows
columnDefs: [
{
headerName: 'Make',
field: 'make',
cellStyle: {fontSize: '11px'}
}
]
You can override the font size via CSS. Ag-Grid's CSS sets the font at the row level, and unfortunately it has an !important tag. Providing a higher selector specificity should do the trick:
div.ag-theme-alpine div.ag-row {
font-size: 12px !important;
}
You can set font-size and other parameters globally by customizing a theme: React Data Grid: Customising Themes
Define the style parameters in the styles.scss file like this:
.ag-theme-alpine {
#include ag-theme-alpine((
font-size: 10px,
));
}

Changing bgcolor of Input pre and post tabs

I've been looking but can't locate the key reference that enables me to update the Inputs pre/post tab.
<Input
addonAfter=".com" // <-- I want to change this bg color
defaultValue="100"
style={{
width: '110px',
backgroundColorAddonAfter: 'red' //HERE, whats the key name?
}}
/>;
The pre/post tabs are the 'greyish' areas that http: and .com in them. I want to change those colors.
There are two ways to achieve this:
Override CSS class
You can override all post and pre tabs colors.
/* import ./App.css */
/* first and last are red */
.ant-input-group-addon {
background-color: red;
}
.ant-input-group-addon:first-child {
background-color: purple;
}
.ant-input-group-addon:last-child {
background-color: blue;
}
Style your own component with Input.Group
Here we use Input.Group which groups components as done with addonBefore and addonAfter, you need to make your own PreComponent and PostComponent :
<Input.Group compact>
<PreComponent color="pink">{'http://'}<PreComponent/>
<Input style={{ width: '30%' }} defaultValue="my site" />
<PostComponent color="red">.com<PostComponent/>
</Input.Group>;
Check the demo to grasp what needs to be done:

Has anyone managed to get the Chartjs to work in AngularDart?

Update: SOLVED. I was missing the script include for Chartjs in the index.html file, Oops:
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.min.js"></script>
It works with just Dart following the example, but it doesn't seem to work with AngularDart.
I am using a fresh Angular web application with modifications based on the Dart example.
I added to app_component.html the same DIV element with one exception and that is a local-variable so I can access it via ViewChild:
<div>
<p>Canvas</p>
<div class="wrapper">
<canvas #theCanvas id="canvas" height="450" width="600"></canvas>
</div>
</div>
I then added the styles to app_component.css (plus a border to see the canvas). I can even draw to a rectangle and see it:
div.wrapper {
margin: 0 auto;
max-width: 800px;
text-align: center;
font-style: italic;
border: #6bc5ff 1px solid;
}
I then added the same chart code from the Dart example to the app_commponent.dart file:
Angular imports...
import 'package:chartjs/chartjs.dart';
#Component(
selector: 'my-app',
styleUrls: const ['app_component.css'],
templateUrl: 'app_component.html',
directives: const [materialDirectives, HelloDialog],
providers: const [materialProviders],
)
class AppComponent implements AfterContentInit, AfterViewInit {
#ViewChild('theCanvas')
ElementRef canvas;
CanvasElement canvasEl;
math.Random rnd = new math.Random();
List<String> months = <String>[
"January", "February", "March", "April", "May", "June"];
ngAfterContentInit() {
canvasEl = canvas.nativeElement;
}
ngAfterViewInit() {
var data = new LinearChartData(labels: months, datasets: <ChartDataSets>[
new ChartDataSets(
label: "My First dataset",
backgroundColor: "rgba(220,220,220,0.2)",
data: months.map((_) => rnd.nextInt(100)).toList()),
new ChartDataSets(
label: "My Second dataset",
backgroundColor: "rgba(151,187,205,0.2)",
data: months.map((_) => rnd.nextInt(100)).toList())
]);
var config = new ChartConfiguration(
type: 'line', data: data, options: new ChartOptions(responsive: true));
Chart chart = new Chart(canvasEl, config);
}
}
I added the dependency to pubspec.yaml:
chartjs:
Which in turn included the js dependency. As I mentioned I can make draw calls, like drawing lines, so I know the canvas works.
Dartium's console shows an error:
Uncaught Unhandled exception:
Not a valid JS object
#0 JsNative.callConstructor (dart:js:1461)
#1 Chart.Chart (package:chartjs/chartjs.dart_js_interop_patch.dart:31:30)
#2 AppComponent.ngAfterViewInit (package:DeuronNG/app_component.dart:59:23)
...
Does anyone know if I missed something or what the JS error means?
I was missing the script include for Chartjs in the index.html file, Oops:
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.min.js"></script>

How to bind repeating nested templates to complex models

Eventually I want to bind templates to a tree model, but to understand how binding works beyond object properties (simple or chained), lists, and maps, I've created a two-level set of repeating templates bound to a corresponding Dart model. Each item in the outer list contains an inner list.
o1
a
b
o2
c
d
When I select an inner item (for example 'd'), the click handler highlights the item and appends an Inner object 'e' to the 'o2' Outer object's list. Inspecting the model in the debugger shows that 'e' has been added to the model, but it is not being added as an 'li' element to the HTML list. How do I revise my code so that the inner template detects the change?
HTML
<polymer-element name="nested-templates">
<template>
<style>
:host { display: block; height: 100%; }
ul { margin: 0; padding: 0; }
li { font-size: 0.85rem; padding-left: 0.75rem; }
li:hover { background: lightgrey; cursor: pointer; }
li.selected { color: red; }
</style>
<div>
<template repeat="{{o in outer}}">
<strong>{{o.name}}</strong>
<ul>
<template repeat="{{i in o.inner}}">
<li id="{{i.name}}" on-click="{{innerClickHandler}}">{{i.name}}</li>
</template>
</ul>
</template>
</div>
</template>
<script type="application/dart" src="nested_templates.dart"></script>
Dart
import 'dart:html';
import 'package:polymer/polymer.dart';
#CustomTag('nested-templates')
class NestedTemplates extends PolymerElement {
#observable List<Outer> outer = toObservable([
new Outer('o1', [ new Inner('a'), new Inner('b')]),
new Outer('o2', [ new Inner('c'), new Inner('d')])
], deep: true);
void innerClickHandler(Event e, Map detail, HtmlElement target) {
target.classes.add('selected');
outer[1].inner.add(new Inner('e'));
}
NestedTemplates.created() : super.created();
}
class Inner extends Observable {
String name;
Inner(this.name);
}
class Outer extends Observable {
String name;
List<Inner> inner;
Outer(this.name, this.inner);
}
pubspec.yaml
dependencies:
...
polymer: 0.10.1+1
polymer_expressions: 0.11.0
...
dependency_overrides:
polymer_expressions: '0.11.0'
You need toObservable() for your inner too
new Outer('o1', toObservable([ new Inner('a'), new Inner('b')])),

Resources