#04 Web Client (HTM5, React.js)

Slides:



Advertisements
Similar presentations
Table, List, Blocks, Inline Style
Advertisements

Introduction to HTML & CSS
CSS Cascading Style Sheets. Objectives Using Inline Styles Working with Selectors Using Embedded Styles Using an External Style Sheet Applying a Style.
HTML Overview - Cascading Style Sheets (CSS). Before We Begin Make a copy of one of your HTML file you have previously created Make a copy of one of your.
Cascading Style Sheets Basics. Why use Cascading Style Sheets? Allows you to set up a series of rules for all pages in a site. The series may be changed.
Recognizing the Benefits of Using CSS 1. The Evolution of CSS CSS was developed to standardize display information CSS was slow to be supported by browsers.
Chapter 2 Introduction to HTML5 Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
Week 4.  Three ways to apply CSS: Inline CSS Internal style sheets ( header style information) External style sheets.
Using Styles and Style Sheets for Design
Cascading Style Sheets CSS.  Standard defined by the W3C  CSS1 (released 1996) 50 properties  CSS2 (released 1998) 150 properties (positioning)  CSS3.
Webpage design for researchers Dr Jim Briggs 1.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
Objectives: 1. Create a Skeleton HTML 2. View a Skeleton File Through a Server and Browser 3. Learn HTML Body Tags for the Display of Text and Graphics.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
Today’s objectives  Review  CSS | Rules | Declarations  HTML Structure document  Class asignment.
CHAPTER 1 HTML & HTML5 I อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
Cascading Style Sheets Orientation Learning Web Design: Chapter 11.
Form Tag How to use Form Tag Something NEW ? PARAMETER Attribute NAME Specifies the name for a form To specify which form to submit with JavaScript, this.
WRT235: Writing in Electronic Environments Basic CSS.
Bare bones slide show. The format is text files, with.htm or.html extension. Hard returns, tabs, and extra spaces are ignored. DO NOT use spaces in file.
Copyright 2007, Information Builders. Slide 1 Understanding Basic HTML Amanda Regan Technical Director June, 2008.
Web Development 101 Presented by John Valance
Cascading Style Sheets CSS.  Standard defined by the W3C  CSS1 (released 1996) 50 properties  CSS2 (released 1998) 150 properties (positioning)  CSS3.
IS-907 Java EE World Wide Web - Overview. World Wide Web - History Tim Berners-Lee, CERN, 1990 Enable researchers to share information: Remote Access.
CSS Cascading Style Sheets A very brief introduction CSS, Cascading Style Sheets1.
Department of Computer Science, Florida State University CGS 3066: Web Programming and Design Spring
Tutorial #1 Using HTML to Create Web Pages. HTML, XHTML, and CSS HTML – HyperText Markup Language The tags the browser uses to define the content of the.
HTML Tutorial. What is HTML HTML is a markup language for describing web documents (web pages) HTML documents are described by HTML tags Each HTML tag.
1 Cascading Style Sheet (CSS). 2 Cascading Style Sheets (CSS)  a style defines the appearance of a document element. o E.g., font size, font color etc…
CSS Introductions. Objectives To take control of the appearance of a Web site by creating style sheets. To use a style sheet to give all the pages of.
Using React, Drupal and Google Chrome to build an interactive kiosk + + =
Week 1: Introduction to HTML and Web Design
Advanced Topics in Concurrency and Reactive Programming: HTML, CSS and DOM Trees Majeed Kassis.
Advanced Topics in Concurrency and Reactive Programming: React
Getting Started With HTML
DHTML.
INTRO TO WEB DEVELOPMENT html
HTML CS 4640 Programming Languages for Web Applications
Angular vs React John
Web Basics: HTML/CSS/JavaScript What are they?
Unit 4 Representing Web Data: XML
Bare boned notes.
CSS: Cascading Style Sheets
HyperText Markup Language
>> Introduction to CSS
Human Computer Interaction
IS 360 Declaring CSS Styles
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
Not Sure how you Should React
Website Design 3
Cascading Style Sheets - Building a stylesheet
Chapter 7 Representing Web Data: XML
JavaScript Introduction
HTML A brief introduction HTML.
Advanced Topics in Concurrency and Reactive Programming: React
15 minute break.
Cascading Style Sheets
Tutorial 3 Working with Cascading Style Sheets
Understand basic HTML and CSS terminology, concepts, and basic operations. Objective 3.01.
Johan Ng and Muhammad Hazzry
Cascading Style Sheets - Building a stylesheet
Web Programming Anselm Spoerri PhD (MIT) Rutgers University
5.00 Apply procedures to organize content by using Dreamweaver. (22%)
Web Client Side Technologies Raneem Qaddoura
Web Programming Anselm Spoerri PhD (MIT) Rutgers University
Web Programming and Design
Build’an’Office add-in- using’modern JavaScript tools and techniques
HTML CS 4640 Programming Languages for Web Applications
Presentation transcript:

#04 Web Client (HTM5, React.js) Client/Server Computing and Web Technologies

Web Page Layers Behavior JavaScript Presentation Cascading Style Sheet Content Hypertext Markup Language

HTML Hypertext: A software system that links topics on the screen to related information and graphics, which are typically accessed by a point-and-click method. Markup Language: A set of markup tags for grouping and describing page content.

Document Object Model Document <html> <head> </head> <body> <h1></h1> <div> ... </div> </body> </html> head body h1 div child elements ... Document Hierarchy: Parents, children and siblings

HTML Elements <tag>Content</tag> An HTML element includes both the HTML tag and everything between the tag (the content). Tags normally come in pairs. The first tag is the start tag, and the second tag is the end tag. HTML has a defined set of tag names (also called keywords) that the browser understands. Most elements can have attributes, which provides additional information about the element. <div class="left-nav"></div>

Essential Element Tags Primary Structure html head body Structural Elements (block) p br h1 – h6 ul ol a img (div) Formatting Elements (inline) em i strong b q blockquote (span) Head Elements title meta link

CSS Stylesheet Cascading Rules defining how an html element will be “presented” in the browser. Targeted to specific elements in the html document. Cascading Rules for resolving conflicts with multiple CSS rules applied to the same elements. For example, if there are two rules defining the color or your h1 elements, the rule that comes last in the cascade order will “trump” the other. Browser CSS Linked CSS Embedded CSS Inline CSS Importance

CSS Syntax selector {property: value;} Declaration Every style is defined by a selector and a declaration. The declaration contains at least one property/value pair. Together they are called a CSS Rule. body {font-family: Arial, Helvetica} p {color: #666666} h1 {font-size: 24px} a {color: blue}

CSS Selector p # . Type Selector Id Selector Class Selector targets an html element by name Id Selector An ID is an html attribute added to a html markup. Reference that ID with a hash (#) #logo { declaration } <img id="logo" src="" alt=""> Class Selector A class is an html attribute added to a html markup. Reference that ID with a period (.) .ingredients {declaration} <ul class="ingredients"> p # .

JavaScript JavaScript as HTML element JavaScript as external resources <script type="text/javascript"> … </script> JavaScript as external resources <script type="text/javascript" src="e.js"></script> Purposes Manipulate HTML DOM via document object document.getElementById("logo")... Handle Event from HTML element <p onclick="do_smth()"> ... </p> Implement application logics, e.g., form validations Refer to Chapter #03 for syntaxes.

Libraries CSS Framework JavaScript Library JavaScript Framework http://www.monolinea.com/css-frameworks-comparison/ CSS Framework Heavyweights: Bootstrap, Foundation Middleweights: Gummy, Groundwork Lightweights: Pure, Base, Kube CSS JavaScript Library DOM manipulation, animation, events, HTTP requests jQuery, minified.js Supports: underscore.js, moment.js JavaScript Framework jQuery, Dojo, Ember.js, AngularJS, ReactJS, VueJS https://medium.com/@noomerzx/ความรู้สึกเมื่ออยากเขียน-javascript-ในปี-2016-92711cf3987 http://en.wikipedia.org/wiki/Comparison_of_JavaScript_frameworks

A Javascript library for building user interfaces ReactJS A Javascript library for building user interfaces

React features JSX Components The virtual DOM JavaScript extension Try it: http://babeljs.io/repl Components Reusable, Maintainable, Testable The virtual DOM

The virtual DOM Reference: https://stackoverflow.com/questions/21109361/why-is-reacts-concept-of-virtual-dom-said-to-be-more-performant-than-dirty-mode

Setup Softwares Quick start node & npm IDE: Web storm, VS Code, Atom, Sublime, vi Quick start npm install -g create-react-app create-react-app my-app cd my-app npm start Reference: https://reactjs.org/tutorial/tutorial.html

React: Start from scratch Prepare and create package.json: npm init -y Install global package: npm install -g babel babel-cli npm install -g webpack-dev-server Add dependencies and plugins: npm install webpack webpack-dev-server --save npm install react react-dom --save npm install babel-core babel-loader --save npm install babel-preset-react babel-preset-es2015 --save Reference: https://www.tutorialspoint.com/reactjs/reactjs_environment_setup.htm

Compiler, Server and Loaders create webpack.config.js var config = { entry: './src/index.js', output: { path:'/', filename: 'bundle.js', }, devServer: { inline: true, port: 8080 module: { loaders: [ { exclude: /node_modules/, loader: 'babel-loader', query: { presets: ['es2015', 'react'] } ] module.exports = config;

Compiler, Server and Loaders edit package.json "scripts": { "start": "webpack-dev-server --hot" "test": "echo \"Error: no test specified\" && exit 1" }, npm start app.jsx main.js index.html <!DOCTYPE html> <html lang = "en"> <head> <meta charset = "UTF-8"> <title>React App</title> </head> <body> <div id = "app"></div> <script src = "index.js"></script> </body> </html> import React from 'react’; class App extends React.Component { render() { return ( <div> Hello World!!! </div> ); } export default App; import React from 'react'; import ReactDOM from 'react-dom'; import App from './app.jsx'; ReactDOM.render( <App />, document.getElementById('app') ); Try to modify in app.jsx and check result at browser

Component based import React from 'react'; class App extends React.Component { render() { return ( <div> <Header/> <Content/> </div> ); } class Header extends React.Component { return ( <div> <h1>Header</h1> </div> ); class Content extends React.Component { <h2>Content</h2> <p>The content text!!!</p> export default App; In practical, Header and Content should be separately created and exported.

Data passing (props vs. state) React has 2 objects of data passing in order to control data into a component Props Pass from parent to child components Immutable Props CANNOT be CHANGED inside a component Single source of the truth Fixed throughout the component State Reside within component Mutable State CAN be CHANGED

Props: pass to a component import React, { Component } from 'react'; class Foo extends Component { render() { return ( <div> <h1> Foo: {this.props.name} </h1></div> ) } } class App extends Component { render() { return ( <div> <Foo name="FooName" /> </div> ); } } export default App; Define a new property ‘name’

State: initial and update class App extends Component { constructor(props){ super(props) this.state = { fooState: "Foo State" } } render() { return ( <div> Message: {this.state.fooState} <br/> </div> ); } } Initial state object Read state object

State: bind method to context class App extends Component { constructor(props){ super(props) this.state = { fooState: "Foo State" } this.updateMessage = this.updateMessage.bind(this) } updateMessage(e) { this.setState( {fooState: "New Foo State: " + e.target.value }) } render() { return ( <div> <div> Message: <input type='text' onChange={this.updateMessage}/> <br/> {this.state.fooState} <br/> </div> </div> ); } } Have to bind method to ‘App’ context, otherwise a new method will not be known Define the method to update state Trig the method

State: automatically bind class App extends Component { constructor(props){ super(props) this.state = { fooState: "Foo State" } } updateMessage = (e) => { this.setState( {fooState: "New Foo State: " + e.target.value }) } render() { return ( <div> <div> Message: <input type='text' onChange={this.updateMessage}/> <br/> {this.state.fooState} <br/> </div> </div> ); } } Arrow function binds a method automatically

State: Parent and child component class Foo extends Component { render() { return ( <div> <h3> Foo: {this.props.name} </h3> {this.props.fooState} </div> ) } } class App extends Component { ... render() { return ( <div> <div> Message: <input type='text' onChange={this.updateMessage}/> <br/> {this.state.fooState} <br/> </div> <Foo name="FooName" fooState={this.state.fooState} updateMessage={this.updateMessage.bind(this)} /> </div> ); } } Read ‘state’ as ‘props’ Pass ‘state’ as ‘props’ Update ‘state’ from parent but it affects to child component

React – AJAX Request Promises: Axios library

HTTP Library: Axios Target API: https://api.github.com/users/wwarodom Example: axios npm install axios --save import React, { Component } from 'react'; import axios from 'axios'; const USER = 'wwarodom'; class Profile extends Component { constructor(props){ super(props) this.state = { data: {} } } componentDidMount() { axios.get(`https://api.github.com/users/${USER}`) .then(response => { this.setState({data: response.data}) console.log(response.data) } ) } Send Http request

Read object Pick a value render() { const dataOption = Object.keys(this.state.data) .map( (key,index) => <option value={index}> {index+1 +'. ' +key+ ': ' + this.state.data[key]} </option> ) return ( <div> <h2> Github Profile</h2> <ul> <li>{this.state.data.url}</li> <li>{this.state.data.login}</li> <li>{this.state.data['blog']}</li> </ul> <dd><select>{dataOption}</select></dd> </div> ); } } export default Profile; Pick a value