Welcome to the LianaCrew React exercise. The purpose of this exercise is to demonstrate a suitable level of competence using React.
[email protected]+
[email protected]+
★ Convert src/exercise/index.html
into React. Provide the following components, declared in their own separate files, using roughly the same structure:
- A component that renders a
<header>
-element. The content should be supplied via atext
-prop. - A component that renders a
<form>
-element. The content should be supplied aschildren
. - A component that renders a
<label>
-element containing an<i>
-element. It has the following props:name
: Passed to thefor
-attribute of<label>
.type
: Passed to one of the CSS classes of<i>
. This controls what icon (email
,pencil
,user
) is rendered.text
: The main text content after<i>
.
- A component that renders inputs. It has the following props:
name
: Passed to thename
-attribute of the input.id
: Passed to theid
-attribute of the input. This should default toprops.name
, above.value
: Passed as thevalue
-attribute of the input. This should default toundefined
.type
: Determines the type of input rendered:text
: Renders an<input type="text">
-input.textarea
: Renders an<textarea>
-input.submit
: Renders an<input type="submit">
-input. This input does not useprops.name
orprops.id
.
Clicking on <submit>
should print out the current form values via the console
.
Feel free to add other properties to your components to accomplish this. Use src/solution/app.js
as your starting point.
Important note: You should accomplish your task strictly via React! You should not manipulate the DOM with, for example, jQuery or the Selector API in any way!
npm install
to retrieve module dependencies.- Run
npx webpack-cli serve
to run the development server. - Navigate to
localhost:3000
. - Provide your solution under
src/solution/
- Changes should update automatically.
The following tasks are NOT REQUIRED, but will be considered as further proof of your expertise. The tasks should be done in order, as they depend on each other.
- Provide the following constraints:
- Your
email
-input should only accept email addresses of the correct format ([email protected]
). - Your
message
-input should have a maximum length of 255 characters. - When clicking on
<submit>
, theconsole
output should show an error instead of the usual output if the constraints fail.
- Your
- Provide an optional input:
- Modify your "input component" to be able to render
<select>
-inputs whenprops.type === 'select'
. - Include the above
<select>
in your<form>
with a few options (for example: Topic). This input should be empty by default. - When clicking on
<submit>
, your "optional input" should not appear in theconsole
output unless given.
- Modify your "input component" to be able to render
- Provide validation feedback:
- Modify your
text
andtextarea
-type inputs to have therequired
-attribute. - Based on task #1, when clicking on
<submit>
, check if your<form>
is:- Valid: Display the message "Everything OK!" under the
<submit>
-button. - NOT valid: Modify your
<label>
component to display an error message for each individual input that is incorrect.
- Valid: Display the message "Everything OK!" under the
- Based on task #2, your
select
-type input should not affect the validation.
- Modify your