Skip to content

Commit

Permalink
Feature/pxweb2 55 add variable box component (#138)
Browse files Browse the repository at this point in the history
* Add generated files for the VariableBox component

PXWEB2-55 Since we want all components to have the same basic starting
point, we need to use the Nx generator for React components, to generate
the files. No functionality added yet.

* Add variablebox to main app

* Feature/pxweb2 155 use common text styles for bodylong and link (#108)

* PXWEB2-155 Moved text-styles to comm text-style file. Added property for classname

* PXWEB2-155 Made separate classes for bold/regular. Easier to compare for designer.

* PXWEB2-155 use common text-styles for link and use bodyshort as class in link as in Figma

* PXWEB2-155 Removed commented out code

* PXWEB2-155 Removed commented out text

* PXWEB2-55 Add ability to pass styling into Heading

Since we in the VariableBox component need to pass some styling into the
Heading component, it needs to be able to add said styling to it's own.
Without this it would just overwrite the styling of the Heading
component.

* PXWEB2-55 Add early VariableBox component

Adds the files for the VariableBox component, adds the component to the
examples app page.

This is missing the entire Content part of the component, but the
styling of the Header part is done, as a first version atleast.

* Fix warnings in example app

Since we don't want unnecessary warnings and such cluttering the dev
experiance in the browser, we should do easy fixes for warnings. Even
if the site in question is a temporary one. This fixes some warnings
that were clutting the console and dev tools.

PS: My first attempt at commiting a chunk of a file, instead of the
whole file. Hopefully it works.

* Fix CSS variables

* PXWEB2-55 Update translation files

Since we want the new components to use the translation files, so we
don't have to add that later, we need to update the keys in said files.
This also adds the translations needed for the VariableBox for en, no,
sv and ar. Though the translations were gotten from google translate
where I did not know the language.

* Clean up CSS, still WIP

* Add first logic for rendering checkboxes

* Add number formatting to header values

* Add hover css

* Change when select all is shown

* Add padding to show background in wrapper

* Added initial docs

* Added netlify badge in footer template

* Create doc-site.yml

Added a workflow to build and deploy the documentation to GitHub Pages

* Removed netlify badge

* Restored previouse change and removed netlify badge

* Bump actions/setup-node from 3 to 4 (#114)

Bumps [actions/setup-node](https://github.com/actions/setup-node) from 3 to 4.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](actions/setup-node@v3...v4)

---
updated-dependencies:
- dependency-name: actions/setup-node
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump actions/checkout from 3 to 4 (#115)

Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Update dependencies

Since we want to keep the dependencies in the project up-to-date, we
need to update the outdated ones. This updates them with the 'migrate
latest' command from Nx, and then with the normal 'update --save' from
NPM.

Also add a blank space to a readme in the ui lib, to force chromatic to
build, to check for regressions.

* Added Select component

* Possible to add css classes to Button component from the code using the component

* Possible to add css classes to BodyShort component from the code using the component

* Use common text styles

* Replaced alerts with console.log to work also with Safari

* Added onChange event and some minor CSS changes

* Updated tests and stories with onChange event

* Code refactoring and css changes

* Use outline instead of border

* Removed ariaLabelButton since Button is no longer used

* Added tabindex and possibility to use keyboard

* Moved divider border to a separate div

* Separated own includes from external

* WIP: Started working on select, need to update from main to continue

* Pxweb2 100 config (#117)

Added config that can be changed before and after build.
Added config validation with JSON schema, validated on localhost with ajv (this supports validation for config changes after build as well)
Added config types
Used config in language config
Made sure config is loaded before app
Config is available anywhere in the app via getConfig()

* Refactor Select into 2 sub-components (#119)

To get rid of an extra div that the Select component returns, it has
been refactored into being 2 sub components for the variants, instead of
2 functions. Nothing has been done to the logic outside of this.

* Add mapping over codelists for select

* Fix typo in setAllValuesSelected

* PXWEB2-55 Improve select with translations

Add translations to the label/title of the select component in the
variablebox component.

Also fix the styling of the select, it should now correctly take the
entire width instead of only as much as is needed.

Also formatted app.tsx.

* Add generated files for the VariableBox component

PXWEB2-55 Since we want all components to have the same basic starting
point, we need to use the Nx generator for React components, to generate
the files. No functionality added yet.

* Add variablebox to main app

* PXWEB2-55 Add ability to pass styling into Heading

Since we in the VariableBox component need to pass some styling into the
Heading component, it needs to be able to add said styling to it's own.
Without this it would just overwrite the styling of the Heading
component.

* PXWEB2-55 Add early VariableBox component

Adds the files for the VariableBox component, adds the component to the
examples app page.

This is missing the entire Content part of the component, but the
styling of the Header part is done, as a first version atleast.

* Fix warnings in example app

Since we don't want unnecessary warnings and such cluttering the dev
experiance in the browser, we should do easy fixes for warnings. Even
if the site in question is a temporary one. This fixes some warnings
that were clutting the console and dev tools.

PS: My first attempt at commiting a chunk of a file, instead of the
whole file. Hopefully it works.

* Fix CSS variables

* PXWEB2-55 Update translation files

Since we want the new components to use the translation files, so we
don't have to add that later, we need to update the keys in said files.
This also adds the translations needed for the VariableBox for en, no,
sv and ar. Though the translations were gotten from google translate
where I did not know the language.

* Clean up CSS, still WIP

* Add first logic for rendering checkboxes

* Add number formatting to header values

* Add hover css

* Change when select all is shown

* Add padding to show background in wrapper

* WIP: Started working on select, need to update from main to continue

* Add mapping over codelists for select

* Fix typo in setAllValuesSelected

* PXWEB2-55 Improve select with translations

Add translations to the label/title of the select component in the
variablebox component.

Also fix the styling of the select, it should now correctly take the
entire width instead of only as much as is needed.

Also formatted app.tsx.

* Add Search component with some modifications

* Fix Select background in variablebox

* Fix checkboxes length

* Fix for bottom of outline of Select disappearing

* Fix hover and keyboard nav highlighting

Since we want a good experience when using the entire site with a
keyboard, we need to have good navigation and highlighting for this.

This changes the VariableBox to not use the Button component, but
instead uses the Icon component directly and styles it based on hover
and focus etc. TabIndex was also added to enable keyboard navigation to
the komponent Header, so one can activate it. It opens/closes when using
the Enter and Space keys.

The current state of showing that the focus is on the Header component
might not be enough, so will bring this up with the designer.

* Fix focus styling in VB: select+checkbox

* Add generated files for the VariableBox component

PXWEB2-55 Since we want all components to have the same basic starting
point, we need to use the Nx generator for React components, to generate
the files. No functionality added yet.

* Add variablebox to main app

* PXWEB2-55 Add ability to pass styling into Heading

Since we in the VariableBox component need to pass some styling into the
Heading component, it needs to be able to add said styling to it's own.
Without this it would just overwrite the styling of the Heading
component.

* PXWEB2-55 Add early VariableBox component

Adds the files for the VariableBox component, adds the component to the
examples app page.

This is missing the entire Content part of the component, but the
styling of the Header part is done, as a first version atleast.

* Fix CSS variables

* PXWEB2-55 Update translation files

Since we want the new components to use the translation files, so we
don't have to add that later, we need to update the keys in said files.
This also adds the translations needed for the VariableBox for en, no,
sv and ar. Though the translations were gotten from google translate
where I did not know the language.

* Clean up CSS, still WIP

* Add first logic for rendering checkboxes

* Add number formatting to header values

* Add hover css

* Change when select all is shown

* Add padding to show background in wrapper

* Added Select component

* Code refactoring and css changes

* Moved divider border to a separate div

* WIP: Started working on select, need to update from main to continue

* Add mapping over codelists for select

* Fix typo in setAllValuesSelected

* PXWEB2-55 Improve select with translations

Add translations to the label/title of the select component in the
variablebox component.

Also fix the styling of the select, it should now correctly take the
entire width instead of only as much as is needed.

Also formatted app.tsx.

* PXWEB2-55 Add early VariableBox component

Adds the files for the VariableBox component, adds the component to the
examples app page.

This is missing the entire Content part of the component, but the
styling of the Header part is done, as a first version atleast.

* Add hover css

* WIP: Started working on select, need to update from main to continue

* PXWEB2-55 Improve select with translations

Add translations to the label/title of the select component in the
variablebox component.

Also fix the styling of the select, it should now correctly take the
entire width instead of only as much as is needed.

Also formatted app.tsx.

* Add Search component with some modifications

* Fix Select background in variablebox

* Fix checkboxes length

* Fix for bottom of outline of Select disappearing

* Fix hover and keyboard nav highlighting

Since we want a good experience when using the entire site with a
keyboard, we need to have good navigation and highlighting for this.

This changes the VariableBox to not use the Button component, but
instead uses the Icon component directly and styles it based on hover
and focus etc. TabIndex was also added to enable keyboard navigation to
the komponent Header, so one can activate it. It opens/closes when using
the Enter and Space keys.

The current state of showing that the focus is on the Header component
might not be enough, so will bring this up with the designer.

* Fix focus styling in VB: select+checkbox

* Fix color for checkbox focus after merge

* Fix VB usage of Select after branch update

* Add scroll logic to the variablebox's values list

Since we want a show/hide logic when scrolling in the valueslists of a
variablebox, we need to add the logic for this.

Also had to expand on the MixedCheckbox to add a background when used in the variablebox.

* Improve show/hide of search and selectall in VB

* Fix show/hide in VB-values-list

* Add TODO about simplifying the scrolling animations

* Refactor VariableBox into sub components

* Fix section comment in scss

* Fix the current test for VariableBox

* Format Variablebox test file

* Fix typing of state for mixed checkbox text

* Fix typo in variable name in story

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: PerIngeVaaje <[email protected]>
Co-authored-by: petroslikidis <[email protected]>
Co-authored-by: likp <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: MikaelNordberg <[email protected]>
Co-authored-by: Michael Pande <[email protected]>
  • Loading branch information
7 people authored May 7, 2024
1 parent f41e810 commit e006141
Show file tree
Hide file tree
Showing 24 changed files with 847 additions and 61 deletions.
28 changes: 28 additions & 0 deletions apps/pxweb2/public/locales/ar/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,33 @@
"start_page": {
"header": "مرحبا بكم في التطبيق!",
"welcome_trans_test": "مرحبًا بك في <1>التطبيق</1> لـ PxWeb 2.0!"
},
"presentation_page": {
"sidemenu": {
"selection": {
"variablebox": {
"search": {
"placeholder": "عيب",
"label": "عيب",
"arialabelicontext": "أيقونة البحث",
"ariallabelclearbuttontext": "أيقونة لإزالة النص في حقل البحث"
},
"header": {
"tag_selected": "تم تحديد {{selected}} من {{total}}",
"tag_mandatory": "يجب أن يتم اختياره"
},
"content": {
"select": {
"label": "اختر القسم",
"placeholder": "اختر قسما"
},
"mixed_checkbox": {
"select_all": "اختر الكل",
"deselect_all": "الغاء تحديد الكل"
}
}
}
}
}
}
}
21 changes: 19 additions & 2 deletions apps/pxweb2/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@
"generic_buttons": {
"ok": "OK",
"cancel": "Cancel",
"search": "Search",
"save": "Save"
"save": "Save",
"search": "Search"
},
"generic_tags": {
"mandatory": "Mandatory"
}
},
"start_page": {
Expand All @@ -50,6 +53,20 @@
"label": "Search",
"arialabelicontext": "Search icon",
"ariallabelclearbuttontext": "Clear search icon"
},
"header": {
"tag_selected": "{{selected}} of {{total}} selected",
"tag_mandatory": "Mandatory"
},
"content": {
"select": {
"label": "Choose grouping",
"placeholder": "Make a selection"
},
"mixed_checkbox": {
"select_all": "Select all",
"deselect_all": "Deselect all"
}
}
}
},
Expand Down
19 changes: 18 additions & 1 deletion apps/pxweb2/public/locales/no/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
"save": "Lagre"
}
},
"generic_tags": {
"mandatory": "Må velges"
},
"start_page": {
"header": "Velkommen til appen!",
"welcome_trans_test": "Velkommen til <1>appen</1> for PxWeb 2.0!"
Expand All @@ -49,7 +52,21 @@
"placeholder": "Søk",
"label": "Søk",
"arialabelicontext": "Søkeikon",
"ariallabelclearbuttontext": "Fjern søkeikon"
"ariallabelclearbuttontext": "Ikon for å fjerne tekst i søkefeltet"
},
"header": {
"tag_selected": "{{selected}} av {{total}} valgt",
"tag_mandatory": "Må velges"
},
"content": {
"select": {
"label": "Velg inndeling",
"placeholder": "Velg en inndeling"
},
"mixed_checkbox": {
"select_all": "Velg alle",
"deselect_all": "Fjern all valgte"
}
}
}
},
Expand Down
28 changes: 28 additions & 0 deletions apps/pxweb2/public/locales/sv/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,33 @@
"start_page": {
"header": "Välkommen till appen!",
"welcome_trans_test": "Välkommen till <1>appen</1> för PxWeb 2.0!"
},
"presentation_page": {
"sidemenu": {
"selection": {
"variablebox": {
"search": {
"placeholder": "Sök",
"label": "Sök",
"arialabelicontext": "Sök ikon",
"ariallabelclearbuttontext": "Ikon för att ta bort text i sökfältet"
},
"header": {
"tag_selected": "{{selected}} av {{total}} valda",
"mandatory": "Måste väljas"
},
"content": {
"select": {
"label": "Välj division",
"placeholder": "Välj en division"
},
"mixed_checkbox": {
"select_all": "Välj alla",
"deselect_all": "Välj bort alla"
}
}
}
}
}
}
}
17 changes: 17 additions & 0 deletions apps/pxweb2/src/@types/resources.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ interface Resources {
"cancel": "Cancel",
"search": "Search",
"save": "Save"
},
"generic_tags": {
"mandatory": "Mandatory"
}
},
"start_page": {
Expand All @@ -51,6 +54,20 @@ interface Resources {
"label": "Search",
"arialabelicontext": "Search icon",
"ariallabelclearbuttontext": "Clear search icon"
},
"header": {
"tag_selected": "{{selected}} of {{total}} selected",
"tag_mandatory": "Mandatory"
},
"content": {
"select": {
"label": "Choose grouping",
"placeholder": "Make a selection"
},
"mixed_checkbox": {
"select_all": "Select all",
"deselect_all": "Deselect all"
}
}
}
},
Expand Down
6 changes: 6 additions & 0 deletions apps/pxweb2/src/app/app.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
}
}

.variableBoxContainer {
width: 20.25rem;
background: var(--px-color-surface-moderate, #DBEBEB);
padding: 1rem;
}

@media (min-width: fixed.$breakpoints-xsmall-min-width) and (max-width: fixed.$breakpoints-xsmall-max-width) {
.breakpoints {
max-width: 100px;
Expand Down
40 changes: 33 additions & 7 deletions apps/pxweb2/src/app/app.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import { useState } from 'react';
import { useTranslation, Trans } from 'react-i18next';
import cl from 'clsx';

import styles from './app.module.scss';
import {
Button,
Heading,
BodyShort,
BodyLong,
Heading,
Ingress,
Label,
Tag,
Select,
SelectOption,
PxTable,
Search,
Tag,
VariableBox,
} from '@pxweb2/pxweb2-ui';
import useLocalizeDocumentAttributes from '../i18n/useLocalizeDocumentAttributes';
//import { NumberFormatter } from '../i18n/formatters';
import { TableService } from '@pxweb2/pxweb2-api-client';
import { mapTableMetadataResponse } from '../mappers/TableMetadataResponseMapper';
import { useState } from 'react';
import { Header } from './components/Header/Header';
import NavigationRail from './components/NavigationRail/NavigationRail';
import { Content } from './components/Content/Content';
Expand All @@ -32,8 +33,10 @@ function test(event: React.MouseEvent<HTMLButtonElement, MouseEvent>) {
function testSubmit() {
console.log('test submit');
}
function selectedOptionChanged(selectedItem: SelectOption | undefined) {
selectedItem ? console.log('Selected option: ' + selectedItem.label) : console.log('No option selected');
function selectedOptionChanged(selectedItem: SelectOption | undefined) {
selectedItem
? console.log('Selected option: ' + selectedItem.label)
: console.log('No option selected');
}

export function App() {
Expand All @@ -60,6 +63,7 @@ export function App() {
{ label: 'Option 14', value: 'opt14' },
{ label: 'Option 15', value: 'opt15' },
];

const locales = {
en: { title: 'English' },
no: { title: 'Norsk' },
Expand Down Expand Up @@ -132,7 +136,11 @@ export function App() {
Enter table id:
</Label>
<br />
<select onChange={(e) => setTableid(e.target.value)}>
<select
name="tabid"
id="tabid"
onChange={(e) => setTableid(e.target.value)}
>
<option value="TAB638">TAB638</option>
<option value="TAB1292">TAB1292</option>
<option value="TAB5659">TAB5659</option>
Expand All @@ -156,6 +164,24 @@ export function App() {
Get table
</Button>
<br />
<div className={cl(styles.variableBoxContainer)}>
{/* TODO: I think the warning in the console about unique IDs is the variable.id below*/}
{pxTable &&
pxTable.variables.length > 0 &&
pxTable.variables.map(
(variable) =>
variable.id && (
<VariableBox
id={variable.id}
label={variable.label}
mandatory={variable.mandatory}
values={variable.values}
codeLists={variable.codeLists}
/>
)
)}
</div>
<br />
{pxTable && (
<div>
<br></br>
Expand Down Expand Up @@ -231,7 +257,7 @@ export function App() {
<br />
<Search
variant="default"
showLable={true}
showLabel={true}
searchPlaceHolder={t(
'presentation_page.sidemenu.selection.variablebox.search.placeholder'
)}
Expand Down
1 change: 1 addition & 0 deletions libs/pxweb2-ui/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './lib/components/VariableBox/VariableBox';
export * from './lib/components/Tag/Tag';
export * from './lib/components/Typography/Label/Label';
export * from './lib/components/Typography/BodyShort/BodyShort';
Expand Down
13 changes: 12 additions & 1 deletion libs/pxweb2-ui/src/lib/components/Checkbox/Checkbox.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@
min-height: 44px;
display: flex;
position: relative;
border-radius: 4px;

outline: none;

&:hover {
cursor: pointer;
background-color: var(--px-color-surface-action-subtle-hover);
}

&:focus {
background-color: var(--px-color-surface-action-subtle-hover);
}

&:active {
background-color: var(--px-color-surface-action-subtle-active);
}
border-radius: 4px;
}

.checkmark {
Expand Down Expand Up @@ -52,3 +59,7 @@
.strong {
font-family: PxWeb-font-700;
}

.inVariableBox {
background-color: var(--px-color-surface-default);
}
6 changes: 5 additions & 1 deletion libs/pxweb2-ui/src/lib/components/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ interface MixedCheckboxProps {
tabIndex?: number;
strong?: boolean;
noMargin?: boolean;
inVariableBox?: boolean;
}
export const MixedCheckbox: React.FC<MixedCheckboxProps> = ({
id,
Expand All @@ -76,6 +77,7 @@ export const MixedCheckbox: React.FC<MixedCheckboxProps> = ({
tabIndex,
strong,
noMargin,
inVariableBox = false,
}) => {
return (
<div
Expand All @@ -84,7 +86,9 @@ export const MixedCheckbox: React.FC<MixedCheckboxProps> = ({
aria-checked={value}
aria-labelledby={id + '-label'}
aria-controls={ariaControls.join(' ')}
className={styles.checkboxWrapper}
className={cl(styles.checkboxWrapper, {
[styles.inVariableBox]: inVariableBox,
})}
tabIndex={tabIndex ? tabIndex : 0}
onKeyUp={(event) => {
if (event.key === ' ' || event.key === 'Enter') {
Expand Down
Loading

0 comments on commit e006141

Please sign in to comment.