1657000800
Trong hướng dẫn này, chúng tôi sẽ chỉ cho bạn cách xây dựng biểu đồ phân tán trong ứng dụng React Js. Để thêm biểu đồ phân tán trong React, chúng tôi sẽ sử dụng plugin biểu đồ React Google.
Nói chung, biểu đồ phân tán hiển thị các giá trị lý tưởng cho hai biến cho một tập dữ liệu. Tuy nhiên, nếu các điểm được mã hóa, một biến bổ sung có thể được hiển thị.
Hướng dẫn về biểu đồ google này sẽ chỉ cho bạn cách minh họa dữ liệu cân nặng và tuổi thông qua các biểu đồ trên biểu đồ phân tán.
Tốt nhất, hướng dẫn nhanh này là tốt nhất cho người mới bắt đầu. Chúng tôi sẽ hướng dẫn bạn từng bước và hướng dẫn bạn cách xây dựng thành phần biểu đồ phân tán trong React.
Chúng tôi sẽ bắt đầu hướng dẫn này bằng cách thực hiện lệnh npx create-react-app; bạn phải thêm tên dự án mà bạn chọn.
Nó sẽ tạo ra một dự án React mới mà chúng ta sẽ tạo một thành phần biểu đồ.
npx create-react-app react-chart
Đi tới thư mục ứng dụng.
cd react-chart
Trong React, bạn có thể sử dụng biểu đồ của Google để xây dựng một thành phần biểu đồ. Chúng tôi sẽ cài đặt plugin React Google biểu đồ để tạo biểu đồ phân tán.
Do đó, sử dụng một trong hai lệnh để cài đặt thư viện biểu đồ.
# npm
npm install react-google-charts
# yarn
yarn add react-google-charts
Nếu bạn không biết các sắc thái của CSS, thì bạn có thể sử dụng thư viện Bootstrap trong React.
Sự hợp nhất thần thánh của React và Bootstrap làm tăng đáng kể tính nhất quán trong phát triển giao diện người dùng. Do đó, hãy sử dụng lệnh được cung cấp để cài đặt thư viện.
npm install bootstrap
Trong bước tiếp theo, bạn cần truy cập tệp App.js và nhập bootstrap.
import '../node_modules/bootstrap/dist/css/bootstrap.min.css';
Để tạo biểu đồ phân tán trong React, trước tiên bạn phải tạo `components`
thư mục cũng như tạo tệp ScatterChart.js trong thư mục.
Bây giờ, bạn phải thêm mã trong các thành phần / ScatterChart.js .
import React, { Component } from 'react'
import Chart from 'react-google-charts'
const scatterData = [
['Age', 'Weight'],
[8, 12],
[4, 5.5],
[11, 14],
[4, 5],
[3, 3.5],
[6.5, 7],
]
const scatterOptions = {
title: 'Age vs. Weight comparison',
hAxis: { title: 'Age', minValue: 0, maxValue: 15 },
vAxis: { title: 'Weight', minValue: 0, maxValue: 15 },
legend: 'none',
}
class ScatterChart extends Component {
render() {
return (
<div>
<h2>React Scatter Chart Example</h2>
<Chart
width={'700px'}
height={'420px'}
chartType="ScatterChart"
loader={<div>Loading Chart</div>}
data={scatterData}
options={scatterOptions}
rootProps={{ 'data-testid': '1' }}
/>
</div>
)
}
}
export default ScatterChart
Trong bước này, bạn phải mở App.js chính , Trong tệp này, bạn phải xác định hoặc nhập thành phần ScatterChart.
Bạn phải đảm bảo rằng thẻ ScatterChart được gọi bên trong hàm App ().
import React from 'react'
import '../node_modules/bootstrap/dist/css/bootstrap.min.css'
import ScatterChart from './components/ScatterChart'
function App() {
return (
<div className="container mt-5">
<ScatterChart />
</div>
)
}
export default App
Hãy để chúng tôi gọi ứng dụng React bằng cách khởi động máy chủ phát triển React.
Để làm điều đó, đây là lệnh mà chúng ta sẽ sử dụng để chạy ứng dụng.
npm start
Trong hướng dẫn này, chúng ta đã học cách xây dựng một biểu đồ phân tán đơn giản; tuy nhiên, gói biểu đồ phản ứng của google cho phép bạn thêm nhiều tính năng hơn và một chút thay đổi trong biểu đồ phân tán.
Bạn cũng có thể thay đổi hình dạng với các điểm phân tán hoạt hình; Ngoài ra, bạn có thể thêm hỗ trợ thiết kế material design. Bạn có thể kiểm tra nó ở đây để biết thêm về nó.
Nguồn: https://www.positronx.io/how-to-create-scatter-chart-in-react-js-with-google-chart/
1657000800
Trong hướng dẫn này, chúng tôi sẽ chỉ cho bạn cách xây dựng biểu đồ phân tán trong ứng dụng React Js. Để thêm biểu đồ phân tán trong React, chúng tôi sẽ sử dụng plugin biểu đồ React Google.
Nói chung, biểu đồ phân tán hiển thị các giá trị lý tưởng cho hai biến cho một tập dữ liệu. Tuy nhiên, nếu các điểm được mã hóa, một biến bổ sung có thể được hiển thị.
Hướng dẫn về biểu đồ google này sẽ chỉ cho bạn cách minh họa dữ liệu cân nặng và tuổi thông qua các biểu đồ trên biểu đồ phân tán.
Tốt nhất, hướng dẫn nhanh này là tốt nhất cho người mới bắt đầu. Chúng tôi sẽ hướng dẫn bạn từng bước và hướng dẫn bạn cách xây dựng thành phần biểu đồ phân tán trong React.
Chúng tôi sẽ bắt đầu hướng dẫn này bằng cách thực hiện lệnh npx create-react-app; bạn phải thêm tên dự án mà bạn chọn.
Nó sẽ tạo ra một dự án React mới mà chúng ta sẽ tạo một thành phần biểu đồ.
npx create-react-app react-chart
Đi tới thư mục ứng dụng.
cd react-chart
Trong React, bạn có thể sử dụng biểu đồ của Google để xây dựng một thành phần biểu đồ. Chúng tôi sẽ cài đặt plugin React Google biểu đồ để tạo biểu đồ phân tán.
Do đó, sử dụng một trong hai lệnh để cài đặt thư viện biểu đồ.
# npm
npm install react-google-charts
# yarn
yarn add react-google-charts
Nếu bạn không biết các sắc thái của CSS, thì bạn có thể sử dụng thư viện Bootstrap trong React.
Sự hợp nhất thần thánh của React và Bootstrap làm tăng đáng kể tính nhất quán trong phát triển giao diện người dùng. Do đó, hãy sử dụng lệnh được cung cấp để cài đặt thư viện.
npm install bootstrap
Trong bước tiếp theo, bạn cần truy cập tệp App.js và nhập bootstrap.
import '../node_modules/bootstrap/dist/css/bootstrap.min.css';
Để tạo biểu đồ phân tán trong React, trước tiên bạn phải tạo `components`
thư mục cũng như tạo tệp ScatterChart.js trong thư mục.
Bây giờ, bạn phải thêm mã trong các thành phần / ScatterChart.js .
import React, { Component } from 'react'
import Chart from 'react-google-charts'
const scatterData = [
['Age', 'Weight'],
[8, 12],
[4, 5.5],
[11, 14],
[4, 5],
[3, 3.5],
[6.5, 7],
]
const scatterOptions = {
title: 'Age vs. Weight comparison',
hAxis: { title: 'Age', minValue: 0, maxValue: 15 },
vAxis: { title: 'Weight', minValue: 0, maxValue: 15 },
legend: 'none',
}
class ScatterChart extends Component {
render() {
return (
<div>
<h2>React Scatter Chart Example</h2>
<Chart
width={'700px'}
height={'420px'}
chartType="ScatterChart"
loader={<div>Loading Chart</div>}
data={scatterData}
options={scatterOptions}
rootProps={{ 'data-testid': '1' }}
/>
</div>
)
}
}
export default ScatterChart
Trong bước này, bạn phải mở App.js chính , Trong tệp này, bạn phải xác định hoặc nhập thành phần ScatterChart.
Bạn phải đảm bảo rằng thẻ ScatterChart được gọi bên trong hàm App ().
import React from 'react'
import '../node_modules/bootstrap/dist/css/bootstrap.min.css'
import ScatterChart from './components/ScatterChart'
function App() {
return (
<div className="container mt-5">
<ScatterChart />
</div>
)
}
export default App
Hãy để chúng tôi gọi ứng dụng React bằng cách khởi động máy chủ phát triển React.
Để làm điều đó, đây là lệnh mà chúng ta sẽ sử dụng để chạy ứng dụng.
npm start
Trong hướng dẫn này, chúng ta đã học cách xây dựng một biểu đồ phân tán đơn giản; tuy nhiên, gói biểu đồ phản ứng của google cho phép bạn thêm nhiều tính năng hơn và một chút thay đổi trong biểu đồ phân tán.
Bạn cũng có thể thay đổi hình dạng với các điểm phân tán hoạt hình; Ngoài ra, bạn có thể thêm hỗ trợ thiết kế material design. Bạn có thể kiểm tra nó ở đây để biết thêm về nó.
Nguồn: https://www.positronx.io/how-to-create-scatter-chart-in-react-js-with-google-chart/
1617110327
ByteCipher is one of the leading React JS app development Companies. We offer innovative, efficient and high performing app solutions. As a ReactJS web development company, ByteCipher is providing services for customized web app development, front end app development services, astonishing react to JS UI/UX development and designing solutions, reactJS app support and maintenance services, etc.
#reactjs development company usa #reactjs web development company #reactjs development company in india #reactjs development company india #reactjs development india
1659852060
Curly is a template language that completely separates structure and logic. Instead of interspersing your HTML with snippets of Ruby, all logic is moved to a presenter class.
Installing Curly is as simple as running gem install curly-templates
. If you're using Bundler to manage your dependencies, add this to your Gemfile
gem 'curly-templates'
Curly can also install an application layout file, replacing the .erb file commonly created by Rails. If you wish to use this, run the curly:install
generator.
$ rails generate curly:install
In order to use Curly for a view or partial, use the suffix .curly
instead of .erb
, e.g. app/views/posts/_comment.html.curly
. Curly will look for a corresponding presenter class named Posts::CommentPresenter
. By convention, these are placed in app/presenters/
, so in this case the presenter would reside in app/presenters/posts/comment_presenter.rb
. Note that presenters for partials are not prepended with an underscore.
Add some HTML to the partial template along with some Curly components:
<!-- app/views/posts/_comment.html.curly -->
<div class="comment">
<p>
{{author_link}} posted {{time_ago}} ago.
</p>
{{body}}
{{#author?}}
<p>{{deletion_link}}</p>
{{/author?}}
</div>
The presenter will be responsible for providing the data for the components. Add the necessary Ruby code to the presenter:
# app/presenters/posts/comment_presenter.rb
class Posts::CommentPresenter < Curly::Presenter
presents :comment
def body
SafeMarkdown.render(@comment.body)
end
def author_link
link_to @comment.author.name, @comment.author, rel: "author"
end
def deletion_link
link_to "Delete", @comment, method: :delete
end
def time_ago
time_ago_in_words(@comment.created_at)
end
def author?
@comment.author == current_user
end
end
The partial can now be rendered like any other, e.g. by calling
render 'comment', comment: comment
render comment
render collection: post.comments
Curly components are surrounded by curly brackets, e.g. {{hello}}
. They always map to a public method on the presenter class, in this case #hello
. Methods ending in a question mark can be used for conditional blocks, e.g. {{#admin?}} ... {{/admin?}}
.
Curly components can specify an identifier using the so-called dot notation: {{x.y.z}}
. This can be very useful if the data you're accessing is hierarchical in nature. One common example is I18n:
<h1>{{i18n.homepage.header}}</h1>
# In the presenter, the identifier is passed as an argument to the method. The
# argument will always be a String.
def i18n(key)
translate(key)
end
The identifier is separated from the component name with a dot. If the presenter method has a default value for the argument, the identifier is optional – otherwise it's mandatory.
In addition to an identifier, Curly components can be annotated with attributes. These are key-value pairs that affect how a component is rendered.
The syntax is reminiscent of HTML:
<div>{{sidebar rows=3 width=200px title="I'm the sidebar!"}}</div>
The presenter method that implements the component must have a matching keyword argument:
def sidebar(rows: "1", width: "100px", title:); end
All argument values will be strings. A compilation error will be raised if
You can define default values using Ruby's own syntax. Additionally, if the presenter method accepts arbitrary keyword arguments using the **doublesplat
syntax then all attributes will be valid for the component, e.g.
def greetings(**names)
names.map {|name, greeting| "#{name}: #{greeting}!" }.join("\n")
end
{{greetings alice=hello bob=hi}}
<!-- The above would be rendered as: -->
alice: hello!
bob: hi!
Note that since keyword arguments in Ruby are represented as Symbol objects, which are not garbage collected in Ruby versions less than 2.2, accepting arbitrary attributes represents a security vulnerability if your application allows untrusted Curly templates to be rendered. Only use this feature with trusted templates if you're not on Ruby 2.2 yet.
If there is some content you only want rendered under specific circumstances, you can use conditional blocks. The {{#admin?}}...{{/admin?}}
syntax will only render the content of the block if the admin?
method on the presenter returns true, while the {{^admin?}}...{{/admin?}}
syntax will only render the content if it returns false.
Both forms can have an identifier: {{#locale.en?}}...{{/locale.en?}}
will only render the block if the locale?
method on the presenter returns true given the argument "en"
. Here's how to implement that method in the presenter:
class SomePresenter < Curly::Presenter
# Allows rendering content only if the locale matches a specified identifier.
def locale?(identifier)
current_locale == identifier
end
end
Furthermore, attributes can be set on the block. These only need to be specified when opening the block, not when closing it:
{{#square? width=3 height=3}}
<p>It's square!</p>
{{/square?}}
Attributes work the same way as they do for normal components.
Sometimes you want to render one or more items within the current template, and splitting out a separate template and rendering that in the presenter is too much overhead. You can instead define the template that should be used to render the items inline in the current template using the collection block syntax.
Collection blocks are opened using an asterisk:
{{*comments}}
<li>{{body}} ({{author_name}})</li>
{{/comments}}
The presenter will need to expose the method #comments
, which should return a collection of objects:
class Posts::ShowPresenter < Curly::Presenter
presents :post
def comments
@post.comments
end
end
The template within the collection block will be used to render each item, and it will be backed by a presenter named after the component – in this case, comments
. The name will be singularized and Curly will try to find the presenter class in the following order:
Posts::ShowPresenter::CommentPresenter
Posts::CommentPresenter
CommentPresenter
This allows you some flexibility with regards to how you want to organize these nested templates and presenters.
Note that the nested template will only have access to the methods on the nested presenter, but all variables passed to the "parent" presenter will be forwarded to the nested presenter. In addition, the current item in the collection will be passed, as well as that item's index in the collection:
class Posts::CommentPresenter < Curly::Presenter
presents :post, :comment, :comment_counter
def number
# `comment_counter` is automatically set to the item's index in the collection,
# starting with 1.
@comment_counter
end
def body
@comment.body
end
def author_name
@comment.author.name
end
end
Collection blocks are an alternative to splitting out a separate template and rendering that from the presenter – which solution is best depends on your use case.
While collection blocks allow you to define the template that should be used to render items in a collection right within the parent template, context blocks allow you to define the template for an arbitrary context. This is very powerful, and can be used to define widget-style components and helpers, and provide an easy way to work with structured data. Let's say you have a comment form on your page, and you'd rather keep the template inline. A simple template could look like:
<!-- post.html.curly -->
<h1>{{title}}</h1>
{{body}}
{{@comment_form}}
<b>Name: </b> {{name_field}}<br>
<b>E-mail: </b> {{email_field}}<br>
{{comment_field}}
{{submit_button}}
{{/comment_form}}
Note that an @
character is used to denote a context block. Like with collection blocks, a separate presenter class is used within the block, and a simple convention is used to find it. The name of the context component (in this case, comment_form
) will be camel cased, and the current presenter's namespace will be searched:
class PostPresenter < Curly::Presenter
presents :post
def title; @post.title; end
def body; markdown(@post.body); end
# A context block method *must* take a block argument. The return value
# of the method will be used when rendering. Calling the block argument will
# render the nested template. If you pass a value when calling the block
# argument it will be passed to the presenter.
def comment_form(&block)
form_for(Comment.new, &block)
end
# The presenter name is automatically deduced.
class CommentFormPresenter < Curly::Presenter
# The value passed to the block argument will be passed in a parameter named
# after the component.
presents :comment_form
# Any parameters passed to the parent presenter will be forwarded to this
# presenter as well.
presents :post
def name_field
@comment_form.text_field :name
end
# ...
end
end
Context blocks were designed to work well with Rails' helper methods such as form_for
and content_tag
, but you can also work directly with the block. For instance, if you want to directly control the value that is passed to the nested presenter, you can call the call
method on the block yourself:
def author(&block)
content_tag :div, class: "author" do
# The return value of `call` will be the result of rendering the nested template
# with the argument. You can post-process the string if you want.
block.call(@post.author)
end
end
If you find yourself opening a context block just in order to use a single component, e.g. {{@author}}{{name}}{{/author}}
, you can use the shorthand syntax instead: {{author:name}}
. This works for all component types, e.g.
{{#author:admin?}}
<p>The author is an admin!</p>
{{/author:admin?}}
The syntax works for nested contexts as well, e.g. {{comment:author:name}}
. Any identifier and attributes are passed to the target component, which in this example would be {{name}}
.
Although most code in Curly presenters should be free of side effects, sometimes side effects are required. One common example is defining content for a content_for
block.
If a Curly presenter class defines a setup!
method, it will be called before the view is rendered:
class PostPresenter < Curly::Presenter
presents :post
def setup!
content_for :title, post.title
content_for :sidebar do
render 'post_sidebar', post: post
end
end
end
In order to have {{
appear verbatim in the rendered HTML, use the triple Curly escape syntax:
This is {{{escaped}}.
You don't need to escape the closing }}
.
If you want to add comments to your Curly templates that are not visible in the rendered HTML, use the following syntax:
{{! This is some interesting stuff }}
Presenters are classes that inherit from Curly::Presenter
– they're usually placed in app/presenters/
, but you can put them anywhere you'd like. The name of the presenter classes match the virtual path of the view they're part of, so if your controller is rendering posts/show
, the Posts::ShowPresenter
class will be used. Note that Curly is only used to render a view if a template can be found – in this case, at app/views/posts/show.html.curly
.
Presenters can declare a list of accepted variables using the presents
method:
class Posts::ShowPresenter < Curly::Presenter
presents :post
end
A variable can have a default value:
class Posts::ShowPresenter < Curly::Presenter
presents :post
presents :comment, default: nil
end
Any public method defined on the presenter is made available to the template as a component:
class Posts::ShowPresenter < Curly::Presenter
presents :post
def title
@post.title
end
def author_link
# You can call any Rails helper from within a presenter instance:
link_to author.name, profile_path(author), rel: "author"
end
private
# Private methods are not available to the template, so they're safe to
# use.
def author
@post.author
end
end
Presenter methods can even take an argument. Say your Curly template has the content {{t.welcome_message}}
, where welcome_message
is an I18n key. The following presenter method would make the lookup work:
def t(key)
translate(key)
end
That way, simple ``functions'' can be added to the Curly language. Make sure these do not have any side effects, though, as an important part of Curly is the idempotence of the templates.
Both layouts and content blocks (see content_for
) use yield
to signal that content can be inserted. Curly works just like ERB, so calling yield
with no arguments will make the view usable as a layout, while passing a Symbol will make it try to read a content block with the given name:
# Given you have the following Curly template in
# app/views/layouts/application.html.curly
#
# <html>
# <head>
# <title>{{title}}</title>
# </head>
# <body>
# <div id="sidebar">{{sidebar}}</div>
# {{body}}
# </body>
# </html>
#
class ApplicationLayout < Curly::Presenter
def title
"You can use methods just like in any other presenter!"
end
def sidebar
# A view can call `content_for(:sidebar) { "some HTML here" }`
yield :sidebar
end
def body
# The view will be rendered and inserted here:
yield
end
end
In order to make a Rails helper method available as a component in your template, use the exposes_helper
method:
class Layouts::ApplicationPresenter < Curly::Presenter
# The components {{sign_in_path}} and {{root_path}} are made available.
exposes_helper :sign_in_path, :root_path
end
Presenters can be tested directly, but sometimes it makes sense to integrate with Rails on some levels. Currently, only RSpec is directly supported, but you can easily instantiate a presenter:
SomePresenter.new(context, assigns)
context
is a view context, i.e. an object that responds to render
, has all the helper methods you expect, etc. You can pass in a test double and see what you need to stub out. assigns
is the hash containing the controller and local assigns. You need to pass in a key for each argument the presenter expects.
In order to test presenters with RSpec, make sure you have rspec-rails
in your Gemfile. Given the following presenter:
# app/presenters/posts/show_presenter.rb
class Posts::ShowPresenter < Curly::Presenter
presents :post
def body
Markdown.render(@post.body)
end
end
You can test the presenter methods like this:
# You can put this in your `spec_helper.rb`.
require 'curly/rspec'
# spec/presenters/posts/show_presenter_spec.rb
describe Posts::ShowPresenter, type: :presenter do
describe "#body" do
it "renders the post's body as Markdown" do
assign(:post, double(:post, body: "**hello!**"))
expect(presenter.body).to eq "<strong>hello!</strong>"
end
end
end
Note that your spec must be tagged with type: :presenter
.
Here is a simple Curly template – it will be looked up by Rails automatically.
<!-- app/views/posts/show.html.curly -->
<h1>{{title}}<h1>
<p class="author">{{author}}</p>
<p>{{description}}</p>
{{comment_form}}
<div class="comments">
{{comments}}
</div>
When rendering the template, a presenter is automatically instantiated with the variables assigned in the controller or the render
call. The presenter declares the variables it expects with presents
, which takes a list of variables names.
# app/presenters/posts/show_presenter.rb
class Posts::ShowPresenter < Curly::Presenter
presents :post
def title
@post.title
end
def author
link_to(@post.author.name, @post.author, rel: "author")
end
def description
Markdown.new(@post.description).to_html.html_safe
end
def comments
render 'comment', collection: @post.comments
end
def comment_form
if @post.comments_allowed?
render 'comment_form', post: @post
else
content_tag(:p, "Comments are disabled for this post")
end
end
end
Caching is handled at two levels in Curly – statically and dynamically. Static caching concerns changes to your code and templates introduced by deploys. If you do not wish to clear your entire cache every time you deploy, you need a way to indicate that some view, helper, or other piece of logic has changed.
Dynamic caching concerns changes that happen on the fly, usually made by your users in the running system. You wish to cache a view or a partial and have it expire whenever some data is updated – usually whenever a specific record is changed.
Because of the way logic is contained in presenters, caching entire views or partials by the data they present becomes exceedingly straightforward. Simply define a #cache_key
method that returns a non-nil object, and the return value will be used to cache the template.
Whereas in ERB you would include the cache
call in the template itself:
<% cache([@post, signed_in?]) do %>
...
<% end %>
In Curly you would instead declare it in the presenter:
class Posts::ShowPresenter < Curly::Presenter
presents :post
def cache_key
[@post, signed_in?]
end
end
Likewise, you can add a #cache_duration
method if you wish to automatically expire the fragment cache:
class Posts::ShowPresenter < Curly::Presenter
...
def cache_duration
30.minutes
end
end
In order to set any cache option, define a #cache_options
method that returns a Hash of options:
class Posts::ShowPresenter < Curly::Presenter
...
def cache_options
{ compress: true, namespace: "my-app" }
end
end
Static caching will only be enabled for presenters that define a non-nil #cache_key
method (see Dynamic Caching.)
In order to make a deploy expire the cache for a specific view, set the version
of the view to something new, usually by incrementing by one:
class Posts::ShowPresenter < Curly::Presenter
version 3
def cache_key
# Some objects
end
end
This will change the cache keys for all instances of that view, effectively expiring the old cache entries.
This works well for views, or for partials that are rendered in views that themselves are not cached. If the partial is nested within a view that is cached, however, the outer cache will not be expired. The solution is to register that the inner partial is a dependency of the outer one such that Curly can automatically deduce that the outer partial cache should be expired:
class Posts::ShowPresenter < Curly::Presenter
version 3
depends_on 'posts/comment'
def cache_key
# Some objects
end
end
class Posts::CommentPresenter < Curly::Presenter
version 4
def cache_key
# Some objects
end
end
Now, if the version
of Posts::CommentPresenter
is bumped, the cache keys for both presenters would change. You can register any number of view paths with depends_on
.
Curly integrates well with the caching mechanism in Rails 4 (or Cache Digests in Rails 3), so the dependencies defined with depends_on
will be tracked by Rails. This will allow you to deploy changes to your templates and have the relevant caches automatically expire.
Thanks to Zendesk for sponsoring the work on Curly.
Author: zendesk
Source code: https://github.com/zendesk/curly
1657120980
Trong hướng dẫn này, chúng tôi sẽ tạo biểu mẫu đăng nhập đáp ứng trong js phản ứng bằng cách sử dụng tailwind css. Chúng ta sẽ thấy trang biểu mẫu đăng nhập đơn giản, các ví dụ về biểu mẫu đăng nhập mạng xã hội với Tailwind CSS & React.
React JS
Tailwind CSS 3.v
Trước tiên, bạn cần thiết lập dự án phản ứng với tailwind css. Bạn có thể cài đặt thủ công hoặc bạn đọc blog bên dưới.
Cách cài đặt Tailwind CSS trong React
Cài đặt & thiết lập Vite + React + Typescript + Tailwind CSS 3
React biểu mẫu đăng nhập đơn giản ui với tailwind css.
Login.jsx
import React from 'react';
export default function Login() {
return (
<div className="relative flex flex-col justify-center min-h-screen overflow-hidden">
<div className="w-full p-6 m-auto bg-white rounded-md shadow-md lg:max-w-xl">
<h1 className="text-3xl font-semibold text-center text-purple-700 underline">
Sign in
</h1>
<form className="mt-6">
<div className="mb-2">
<label
for="email"
className="block text-sm font-semibold text-gray-800"
>
Email
</label>
<input
type="email"
className="block w-full px-4 py-2 mt-2 text-purple-700 bg-white border rounded-md focus:border-purple-400 focus:ring-purple-300 focus:outline-none focus:ring focus:ring-opacity-40"
/>
</div>
<div className="mb-2">
<label
for="password"
className="block text-sm font-semibold text-gray-800"
>
Password
</label>
<input
type="password"
className="block w-full px-4 py-2 mt-2 text-purple-700 bg-white border rounded-md focus:border-purple-400 focus:ring-purple-300 focus:outline-none focus:ring focus:ring-opacity-40"
/>
</div>
<a
href="#"
className="text-xs text-purple-600 hover:underline"
>
Forget Password?
</a>
<div className="mt-6">
<button className="w-full px-4 py-2 tracking-wide text-white transition-colors duration-200 transform bg-purple-700 rounded-md hover:bg-purple-600 focus:outline-none focus:bg-purple-600">
Login
</button>
</div>
</form>
<p className="mt-8 text-xs font-light text-center text-gray-700">
{" "}
Don't have an account?{" "}
<a
href="#"
className="font-medium text-purple-600 hover:underline"
>
Sign up
</a>
</p>
</div>
</div>
);
}
Trang biểu mẫu đăng nhập tạo kiểu bằng cách sử dụng react tailwind v3.
Login.jsx
import React from 'react';
export default function Login() {
return (
<div className="relative flex flex-col justify-center min-h-screen overflow-hidden">
<div className="w-full p-6 m-auto bg-white rounded-md shadow-xl shadow-rose-600/40 ring ring-2 ring-purple-600 lg:max-w-xl">
<h1 className="text-3xl font-semibold text-center text-purple-700 underline uppercase decoration-wavy">
Sign in
</h1>
<form className="mt-6">
<div className="mb-2">
<label
for="email"
className="block text-sm font-semibold text-gray-800"
>
Email
</label>
<input
type="email"
className="block w-full px-4 py-2 mt-2 text-purple-700 bg-white border rounded-md focus:border-purple-400 focus:ring-purple-300 focus:outline-none focus:ring focus:ring-opacity-40"
/>
</div>
<div className="mb-2">
<label
for="password"
className="block text-sm font-semibold text-gray-800"
>
Password
</label>
<input
type="password"
className="block w-full px-4 py-2 mt-2 text-purple-700 bg-white border rounded-md focus:border-purple-400 focus:ring-purple-300 focus:outline-none focus:ring focus:ring-opacity-40"
/>
</div>
<a
href="#"
className="text-xs text-purple-600 hover:underline"
>
Forget Password?
</a>
<div className="mt-6">
<button className="w-full px-4 py-2 tracking-wide text-white transition-colors duration-200 transform bg-purple-700 rounded-md hover:bg-purple-600 focus:outline-none focus:bg-purple-600">
Login
</button>
</div>
</form>
<p className="mt-8 text-xs font-light text-center text-gray-700">
{" "}
Don't have an account?{" "}
<a
href="#"
className="font-medium text-purple-600 hover:underline"
>
Sign up
</a>
</p>
</div>
</div>
);
}
Biểu mẫu đăng nhập phương tiện truyền thông xã hội với phản ứng và gió.
Login.jsx
import React from 'react';
export default function Login() {
return (
<div className="relative flex flex-col justify-center min-h-screen overflow-hidden">
<div className="w-full p-6 m-auto bg-white rounded-md shadow-xl lg:max-w-xl">
<h1 className="text-3xl font-semibold text-center text-purple-700 uppercase">
Sign in
</h1>
<form className="mt-6">
<div className="mb-2">
<label
for="email"
className="block text-sm font-semibold text-gray-800"
>
Email
</label>
<input
type="email"
className="block w-full px-4 py-2 mt-2 text-purple-700 bg-white border rounded-md focus:border-purple-400 focus:ring-purple-300 focus:outline-none focus:ring focus:ring-opacity-40"
/>
</div>
<div className="mb-2">
<label
for="password"
className="block text-sm font-semibold text-gray-800"
>
Password
</label>
<input
type="password"
className="block w-full px-4 py-2 mt-2 text-purple-700 bg-white border rounded-md focus:border-purple-400 focus:ring-purple-300 focus:outline-none focus:ring focus:ring-opacity-40"
/>
</div>
<a
href="#"
className="text-xs text-purple-600 hover:underline"
>
Forget Password?
</a>
<div className="mt-6">
<button className="w-full px-4 py-2 tracking-wide text-white transition-colors duration-200 transform bg-purple-700 rounded-md hover:bg-purple-600 focus:outline-none focus:bg-purple-600">
Login
</button>
</div>
</form>
<div className="relative flex items-center justify-center w-full mt-6 border border-t">
<div className="absolute px-5 bg-white">Or</div>
</div>
<div className="flex mt-4 gap-x-2">
<button
type="button"
className="flex items-center justify-center w-full p-2 border border-gray-600 rounded-md focus:ring-2 focus:ring-offset-1 focus:ring-violet-600"
>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 32 32"
className="w-5 h-5 fill-current"
>
<path d="M16.318 13.714v5.484h9.078c-0.37 2.354-2.745 6.901-9.078 6.901-5.458 0-9.917-4.521-9.917-10.099s4.458-10.099 9.917-10.099c3.109 0 5.193 1.318 6.38 2.464l4.339-4.182c-2.786-2.599-6.396-4.182-10.719-4.182-8.844 0-16 7.151-16 16s7.156 16 16 16c9.234 0 15.365-6.49 15.365-15.635 0-1.052-0.115-1.854-0.255-2.651z"></path>
</svg>
</button>
<button className="flex items-center justify-center w-full p-2 border border-gray-600 rounded-md focus:ring-2 focus:ring-offset-1 focus:ring-violet-600">
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 32 32"
className="w-5 h-5 fill-current"
>
<path d="M16 0.396c-8.839 0-16 7.167-16 16 0 7.073 4.584 13.068 10.937 15.183 0.803 0.151 1.093-0.344 1.093-0.772 0-0.38-0.009-1.385-0.015-2.719-4.453 0.964-5.391-2.151-5.391-2.151-0.729-1.844-1.781-2.339-1.781-2.339-1.448-0.989 0.115-0.968 0.115-0.968 1.604 0.109 2.448 1.645 2.448 1.645 1.427 2.448 3.744 1.74 4.661 1.328 0.14-1.031 0.557-1.74 1.011-2.135-3.552-0.401-7.287-1.776-7.287-7.907 0-1.751 0.62-3.177 1.645-4.297-0.177-0.401-0.719-2.031 0.141-4.235 0 0 1.339-0.427 4.4 1.641 1.281-0.355 2.641-0.532 4-0.541 1.36 0.009 2.719 0.187 4 0.541 3.043-2.068 4.381-1.641 4.381-1.641 0.859 2.204 0.317 3.833 0.161 4.235 1.015 1.12 1.635 2.547 1.635 4.297 0 6.145-3.74 7.5-7.296 7.891 0.556 0.479 1.077 1.464 1.077 2.959 0 2.14-0.020 3.864-0.020 4.385 0 0.416 0.28 0.916 1.104 0.755 6.4-2.093 10.979-8.093 10.979-15.156 0-8.833-7.161-16-16-16z"></path>
</svg>
</button>
<button className="flex items-center justify-center w-full p-2 border border-gray-600 rounded-md focus:ring-2 focus:ring-offset-1 focus:ring-violet-600">
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 32 32"
className="w-5 h-5 fill-current"
>
<path d="M31.937 6.093c-1.177 0.516-2.437 0.871-3.765 1.032 1.355-0.813 2.391-2.099 2.885-3.631-1.271 0.74-2.677 1.276-4.172 1.579-1.192-1.276-2.896-2.079-4.787-2.079-3.625 0-6.563 2.937-6.563 6.557 0 0.521 0.063 1.021 0.172 1.495-5.453-0.255-10.287-2.875-13.52-6.833-0.568 0.964-0.891 2.084-0.891 3.303 0 2.281 1.161 4.281 2.916 5.457-1.073-0.031-2.083-0.328-2.968-0.817v0.079c0 3.181 2.26 5.833 5.26 6.437-0.547 0.145-1.131 0.229-1.724 0.229-0.421 0-0.823-0.041-1.224-0.115 0.844 2.604 3.26 4.5 6.14 4.557-2.239 1.755-5.077 2.801-8.135 2.801-0.521 0-1.041-0.025-1.563-0.088 2.917 1.86 6.36 2.948 10.079 2.948 12.067 0 18.661-9.995 18.661-18.651 0-0.276 0-0.557-0.021-0.839 1.287-0.917 2.401-2.079 3.281-3.396z"></path>
</svg>
</button>
</div>
<p className="mt-8 text-xs font-light text-center text-gray-700">
{" "}
Don't have an account?{" "}
<a
href="#"
className="font-medium text-purple-600 hover:underline"
>
Sign up
</a>
</p>
</div>
</div>
);
}
Nguồn: https://larainfo.com
1623674389
Hire ReactJS app developers for end-to-end services starting from development to customization with AppClues Infotech.
Are you looking for the best company in USA that provides high-quality ReactJS app development services? Having expertise in building robust and real-time mobile apps using React Native Library.
We can fully support your specific business idea with outstanding tech skills and deliver a perfect mobile app on time.
Our ReactJS App Development Services
• Custom ReactJS Development
• ReactJS Consulting
• React UX/UI development and design
• App modernization using React
• React Native mobile development
• Dedicated React development team
• Application migration to React
For more info:
Website: https://www.appcluesinfotech.com/
Email: info@appcluesinfotech.com
Call: +1-978-309-9910
#top reactjs app development company in usa #hire best reactjs app developers #best reactjs app development services #custom reactjs app development agency #how to develop reactjs app #cost to build reactjs application