-
-
Notifications
You must be signed in to change notification settings - Fork 69
Volunteer Activity Reporting Q2 #1141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sasmi825
wants to merge
3
commits into
DemocracyLab:VAR
Choose a base branch
from
sasmi825:VarQ2
base: VAR
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
941ac88
Initial commit on VolunteerActivityReporting Q2 component - issue 1124
sasmi825 8ecda69
Fix: Make VolunteerActivityReportingQ2 a controlled component and fix…
sasmi825 f408589
Fix: Make VolunteerActivityReportingQ2 a controlled component and fix…
sasmi825 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
civictechprojects/static/css/partials/_VolunteerActivityReportingQ2.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| .VARQ2-wrapper { | ||
| font-family: Arial, sans-serif; | ||
| padding: 1rem; | ||
| max-width: 600px; | ||
| margin: 0 auto; | ||
| } | ||
|
|
||
| .VARQ2-label { | ||
| display: block; | ||
| margin-bottom: 0.5rem; | ||
| font-size: 1rem; | ||
| font-weight: bold; | ||
| } | ||
|
|
||
| .VARQ2-input-container { | ||
| position: relative; | ||
| border: 1px solid #ccc; | ||
| border-radius: 4px; | ||
| padding: 0.5rem; | ||
| transition: border-color 0.2s ease-in-out; | ||
| background-color: #fff; | ||
| } | ||
|
|
||
| .VARQ2-input-container.over-limit { | ||
| border-color: red; | ||
| } | ||
|
|
||
| .VARQ2-input-container.input-focused { | ||
| border-color: #007bff; | ||
| } | ||
|
|
||
| .VARQ2-input { | ||
| width: 100%; | ||
| border: none; | ||
| resize: vertical; | ||
| min-height: 40px; | ||
| font-size: 1rem; | ||
| outline: none; | ||
| padding-bottom: 1.5rem; | ||
| overflow: hidden; | ||
| } | ||
|
|
||
| .VARQ2-input::placeholder { | ||
| color: #aaa; | ||
| } | ||
|
|
||
| .VARQ2-counter-wrapper { | ||
| position: absolute; | ||
| bottom: 0.25rem; | ||
| right: 0.5rem; | ||
| font-size: 0.75rem; | ||
| color: #666; | ||
| } | ||
|
|
||
| /* renamed to match component logic: "isOverLimit" */ | ||
| .VARQ2-char-count.over-limit { | ||
| color: red; | ||
| } | ||
|
|
||
| .VARQ2-error-message { | ||
| color: red; | ||
| font-size: 0.875rem; | ||
| margin-top: 0.25rem; | ||
| } | ||
|
|
||
| @media (min-width: 768px) { | ||
| .VARQ2-wrapper { | ||
| max-width: 900px; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...omponents/componentsBySection/VolunteerActivityReporting/VolunteerActivityReportingQ2.jsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import React from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
|
|
||
| // The component is 'controlled' by its parent | ||
| const VolunteerActivityReportingQ2 = ({ className = '', value, setValue, isOverLimit, onFocus, onBlur, isFocused }) => { | ||
| const charCount = value.length; | ||
|
|
||
| const handleChange = (e) => { | ||
| setValue(e.target.value); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className={`VARQ2-wrapper ${className}`}> | ||
| <label htmlFor="volunteer-activity-summary" className="VARQ2-label"> | ||
| In a few words, describe what you did during the week. | ||
| </label> | ||
| <div | ||
| className={`VARQ2-input-container | ||
| ${isOverLimit ? 'over-limit' : ''} | ||
| ${isFocused ? 'input-focused' : ''}`} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For focus, the |
||
| > | ||
| <textarea | ||
| id="volunteer-activity-summary" | ||
| name="volunteer_activity_summary" | ||
| className="VARQ2-input" | ||
| value={value} | ||
| onChange={handleChange} | ||
| onFocus={onFocus} | ||
| onBlur={onBlur} | ||
| placeholder="Enter text..." | ||
| rows={1} | ||
| /> | ||
| <div className="VARQ2-counter-wrapper"> | ||
| <span className={`VARQ2-char-count ${isOverLimit ? 'error-color' : ''}`}> | ||
| {charCount}/150 | ||
| </span> | ||
| </div> | ||
| </div> | ||
| {isOverLimit && ( | ||
| <div className="VARQ2-error-message"> | ||
| Please limit your response to 150 characters. | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| VolunteerActivityReportingQ2.propTypes = { | ||
| className: PropTypes.string, | ||
| value: PropTypes.string.isRequired, | ||
| setValue: PropTypes.func.isRequired, | ||
| isOverLimit: PropTypes.bool.isRequired, | ||
| isFocused: PropTypes.bool.isRequired, | ||
| onFocus: PropTypes.func, | ||
| onBlur: PropTypes.func, | ||
| }; | ||
|
|
||
| export default VolunteerActivityReportingQ2; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...entsBySection/VolunteerActivityReporting/stories/VolunteerActivityReportingQ2.stories.jsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import React, { useState } from 'react'; | ||
| import VolunteerActivityReportingQ2 from '../VolunteerActivityReportingQ2'; | ||
|
|
||
| export default { | ||
| title: 'VolunteerActivityReporting/Q2', | ||
| component: VolunteerActivityReportingQ2, | ||
| }; | ||
|
|
||
| const Template = (args) => { | ||
| const [value, setValue] = useState(args.value); | ||
| const [isFocused, setIsFocused] = useState(false); | ||
|
|
||
| // Calculate isOverLimit based on the current value state | ||
| const isOverLimit = value.length > 150; | ||
|
|
||
| return ( | ||
| <VolunteerActivityReportingQ2 | ||
| {...args} | ||
| value={value} | ||
| setValue={setValue} | ||
| isOverLimit={isOverLimit} | ||
| isFocused={isFocused} // Pass the focus state | ||
| onFocus={() => setIsFocused(true)} | ||
| onBlur={() => setIsFocused(false)} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| export const IdleState = Template.bind({}); | ||
| IdleState.args = { | ||
| value: '', | ||
| }; | ||
| IdleState.parameters = { | ||
| docs: { | ||
| description: { | ||
| story: 'Default state: empty input with no error.', | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export const FilledState = Template.bind({}); | ||
| FilledState.args = { | ||
| value: 'Worked on V16 of the screens. Presented at design team meeting, got feedback.', | ||
| }; | ||
| FilledState.parameters = { | ||
| docs: { | ||
| description: { | ||
| story: 'Input is pre-filled with a valid value.', | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export const ErrorState = Template.bind({}); | ||
| ErrorState.args = { | ||
| // Use a long value to demonstrate the error state | ||
| value: 'I created a new version of the form screens, and then developed the user flow diagram. I also attended the weekly design meeting as well as a team meeting for this assignment. The assigmnment took a lot of time because I had to iterate on the designs multiple times based on feedback from the team. Overall, I am happy with the progress made this week and look forward to continuing to work on this project next week.', | ||
| }; | ||
| ErrorState.parameters = { | ||
| docs: { | ||
| description: { | ||
| story: 'Displays the validation error when the character count exceeds 150.', | ||
| }, | ||
| }, | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand this is the guidance for uncontrolled inputs, but too much functionality is being separated out of this "component". We need to wrap the functionality implemented in the Story Template, and the functionality of VolunteerActivityReportingQ2() into a single file, with the top component that just taking value as a prop. It's just about where to divide the code.
Can you pull the Template code into VolunteerActivityReportingQ2.jsx and name that VolunteerActivityReportingQ2 and then rename the current VolunteerActivityReportingQ2 to something else.
But the other thing that has to be delt with is that value could change, when new data is fetched. The line
won't allow value to change after the initial render.
We will need to add something like
so that if args.value changes, the state changes.
also, args should be changed to props when implementing a component - just to match the component style.