Skip to content
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

[hackathon-2024]: Add Component Selector to storybook #32865

Open
wants to merge 116 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
1d4b550
Initial commit for Component Selector
adamsamec Sep 11, 2023
86e77de
initial decision tree
kolaps33 Sep 11, 2023
16dd110
Proper nesting in conditional rendering
adamsamec Sep 11, 2023
4ea181f
create method updateDecisionProps
kolaps33 Sep 12, 2023
1499616
fix types
kolaps33 Sep 12, 2023
15a6609
adding jsons
kolaps33 Sep 12, 2023
f9ede7c
adding styles + change to radiogroup
kolaps33 Sep 12, 2023
41962bf
import jsons, merging base objects
kolaps33 Sep 12, 2023
8e779a0
Refactor multiple decision states into single object state and fix er…
adamsamec Sep 12, 2023
56923c5
Do not include interactive and composition decisions in the selected …
adamsamec Sep 12, 2023
674d78a
Add navigation by decision
adamsamec Sep 12, 2023
9d96ca2
getComponent update JSONS
kolaps33 Sep 12, 2023
0a80ea9
fix adding prop from radio
kolaps33 Sep 13, 2023
ff30825
removing composition
kolaps33 Sep 13, 2023
10d4d3a
amend jsons add static or interactive
kolaps33 Sep 13, 2023
068fec3
adding interactivity to decisions array
kolaps33 Sep 13, 2023
ab45763
Fix filtering of interactive/static components
adamsamec Sep 13, 2023
7dc49cd
Group checkboxes into group role
adamsamec Sep 13, 2023
6eed75e
Clear decisions from the same category upon radio selection
adamsamec Sep 13, 2023
399eec6
fix category, adding more components jsons
kolaps33 Sep 13, 2023
17063ca
last fixes to get category
kolaps33 Sep 14, 2023
f8aa74d
add label for checkboxes, add number of found comp
kolaps33 Sep 14, 2023
91ac0e2
add weight for heading
kolaps33 Sep 14, 2023
d169a18
adding margin for found text
kolaps33 Sep 14, 2023
3082b47
fix typo in list
kolaps33 Sep 14, 2023
55a90ee
adding components constant
kolaps33 Sep 14, 2023
e7048bc
Merge branch 'master' into adamsamec/component-selector
Sep 16, 2024
e4c5175
Add component example URL retrieval function
Sep 16, 2024
bab3cf9
Retrieve default example when no example is given
Sep 17, 2024
a3eef07
adding according and component selector grid
mituron Sep 17, 2024
a02f15b
Reformat JSON component definitions, add attributes and questions
Sep 18, 2024
4715ebc
Merge branch 'adamsamec/component-selector' of https://github.com/ada…
Sep 18, 2024
b096caf
Use new names of component definitions
Sep 18, 2024
e8bb36c
fix name of table base
mituron Sep 18, 2024
9af45d4
amending headings
mituron Sep 18, 2024
7de3af0
amending headings of second accordion
mituron Sep 18, 2024
891f3cc
Restructure groups and questions
Sep 18, 2024
76243c4
fix merging of attribute between child and base JSON
mituron Sep 18, 2024
8844e1b
Add attributes to components definitions from questions
Sep 18, 2024
3389d02
Merge branch 'adamsamec/component-selector' of https://github.com/ada…
Sep 18, 2024
d5043ef
show components in results where are selected
mituron Sep 18, 2024
af10011
change URL to production, amend link creation in utils
mituron Sep 18, 2024
4d3587b
Add folder for components defs and generate proper URL
Sep 18, 2024
6a49974
Adding questionnaire to Selector | Removed duplicate Selector page | …
hanys7 Sep 18, 2024
a5f18f3
removing according, behaviour section started
mituron Sep 18, 2024
fff8928
adding behaviours toggle buttons
mituron Sep 18, 2024
d3b766a
removing radio and adding toggle buttons
mituron Sep 19, 2024
0ef7583
fix wrong import
mituron Sep 19, 2024
289a884
Merge branch 'master' into adamsamec/component-selector
Sep 19, 2024
ab50b19
Changes in component def attributes
Sep 19, 2024
2e97359
dipslay questions based on the logic
mituron Sep 19, 2024
fe8ed88
Add InfoLabel and Tooltip definitions and fixes
Sep 19, 2024
e406446
Merge branch 'adamsamec/component-selector' of https://github.com/ada…
Sep 19, 2024
24f49fe
Removed questions annotation from json files, generate numbering base…
hanys7 Sep 19, 2024
11ba4fe
trying to fix radio state logic do not work still
mituron Sep 19, 2024
73cf139
trying to fix radio state logic do not work still
mituron Sep 19, 2024
b38fe68
clean up
mituron Sep 19, 2024
053589d
Added image for UI types, fixed UI for input selections, used selecta…
hanys7 Sep 20, 2024
b71a37c
trying to fix displaying components after selection
mituron Sep 22, 2024
6f51a67
changes to add component into array
mituron Sep 24, 2024
f4ef707
fix questions radio
mituron Oct 5, 2024
674d327
remove unused code, add questions heading
mituron Dec 2, 2024
6f2152c
Change folder structure
Dec 10, 2024
e634d5d
Add categories json
Dec 10, 2024
7a01e57
change import all JSONs in one
mituron Dec 10, 2024
6c45608
Add selection from categories logic
Dec 10, 2024
e80cdf8
fix for pushing into field
mituron Dec 10, 2024
782acc4
Add components filter feature
Dec 11, 2024
e49a82e
Small refactoring
Dec 11, 2024
057125d
Fix typ errors
Dec 11, 2024
842f180
Fix type error
Dec 11, 2024
75313c6
Small refactoring
Dec 11, 2024
2180e1b
Rename vars and functions
Dec 11, 2024
175d803
Extract MatchingComponents into React component in separate file
Dec 11, 2024
dcb276a
Small refactoring
Dec 11, 2024
7c34446
amend suitable components logic
mituron Dec 12, 2024
969e71f
Extract BehaviorSelection component and refactor
Dec 12, 2024
aa544c2
Move behaviorOptions to JSON file
Dec 12, 2024
f71298e
Refactor mainly keys in Reacgt mappings
Dec 12, 2024
937e7a5
Refactor and fix keys
Dec 16, 2024
93054a9
Add aria-labelledby for radio groups
Dec 16, 2024
e0eb96c
Rename variables
Dec 16, 2024
4da4f21
fix checkbox name
mituron Dec 16, 2024
2be1aed
Apply filter also to story names
Dec 16, 2024
f198a12
Add number of components available
Dec 16, 2024
d7f7b8b
Add number of matching components to heading
Dec 16, 2024
fb1e1be
Improve alt text for component card images
Dec 17, 2024
40190b4
Load component images from file based on component name rather than J…
Dec 17, 2024
9d12fdb
Small refactor for fully matching
Dec 17, 2024
7f9e0e8
Fix component name and story in matching components list
Dec 17, 2024
ca4f55d
Remove some unused imports
Dec 17, 2024
9f37ab2
Separate functionality into two modes
Dec 17, 2024
3414556
Fix lint errors and refactor
Dec 17, 2024
598dfef
Refactor function into useEffect
Jan 2, 2025
ca0f5fb
adding images from Kay
mituron Jan 6, 2025
d5bd244
import rest of missing component picture, preview
mituron Jan 6, 2025
6f088f2
Fix TabList.png file name
Jan 6, 2025
15b703c
Reset form when mode changes
Jan 6, 2025
aa2d92c
Fix some filtering bugs
Jan 6, 2025
462f2ac
Fix component selection but still bugs with component removal
Jan 6, 2025
f1c2b80
Fix updating matching components after deselecting components
Jan 7, 2025
4dab3e3
sending as welll state selected
mituron Jan 7, 2025
71ebb03
Fix Tag display
Jan 7, 2025
d5020c6
Fix cards selected state display and small refactoring
Jan 7, 2025
01b2f81
Selected components tags now work and added remove all components button
Jan 7, 2025
ae4bedc
Add link to skip to questions section
Jan 7, 2025
7649060
Focus first accordion button on last tag removal
Jan 7, 2025
73b1871
Refactor matching components into useMemo
Jan 7, 2025
9443182
removing tablist png
mituron Jan 8, 2025
864f714
adding tabList png
mituron Jan 8, 2025
021f0d9
Matching components heading and message changes
Jan 8, 2025
6b1adc1
adjust UI
mituron Jan 8, 2025
cec6116
Merge branch 'adamsamec/component-selector' of https://github.com/ada…
mituron Jan 8, 2025
9bb6e0d
adding rest of components
mituron Jan 30, 2025
ae01ee1
UI changes, moved search to right corner, clean up UI
mituron Jan 30, 2025
af2db5f
adding rest of components JSON
mituron Jan 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import * as React from 'react';
import { ToggleButton, makeStyles } from '@fluentui/react-components';

import behaviorOptions from './selection-logic/BehaviorOptions.json';

const useStyles = makeStyles({
heading: { margin: '30px 0 10px 0' },
behaviors: { display: 'flex', gap: '10px' },
});

const getDefaultBehaviors = () => {
const behaviors = {};
behaviorOptions.forEach(category => {
category.behaviors.forEach(behavior => {
behaviors[behavior.id] = false;
});
});
return behaviors;
};

export const BehaviorSelection = ({ updateBehaviorDecision }) => {
const classes = useStyles();
const [behaviors, setBehaviors] = React.useState<Record<string, boolean>>(getDefaultBehaviors());

return (
<>
{behaviorOptions.map(category => (
<React.Fragment key={category.id}>
<h2 className={classes.heading}>{category.title}</h2>
<div className={classes.behaviors}>
{category.behaviors.map(behavior => (
<ToggleButton
key={behavior.id}
checked={behaviors[behavior.id]}
shape="circular"
onClick={() => {
const newValue = !behaviors[behavior.id];
const newBehaviors = { ...behaviors };
newBehaviors[behavior.id] = newValue;
setBehaviors(newBehaviors);
updateBehaviorDecision(behavior.id, newValue);
}}
>
{behavior.name}
</ToggleButton>
))}
</div>
</React.Fragment>
))}
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as React from 'react';
import { Divider, Link, Text, makeStyles } from '@fluentui/react-components';

import { getComponentStoryUrl } from './utils';

export const MatchingComponents = ({ components }) => {
return (
<>
<div role="group" aria-labelledby="matching-heading">
{components.map((component, index) => {
return (
<div key={`component-${index}}`}>
<Text weight="semibold">
Component name:{' '}
<Link target="_blank" inline href={getComponentStoryUrl(component)}>
{component.component}{' '}
</Link>
</Text>
<br />
<Text weight="semibold">Example:</Text> {component.story ? component.story : 'Default'}
{component.note && (
<div>
<Text weight="semibold">Note:</Text> <Text>{component.note}</Text>
</div>
)}
<Divider appearance="strong" />
</div>
);
})}
</div>
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import * as React from 'react';
import {
Accordion,
AccordionHeader,
AccordionItem,
AccordionPanel,
Checkbox,
Divider,
Field,
Label,
Link,
Radio,
RadioGroup,
Select,
Text,
ToggleButton,
Image,
makeStyles,
tokens,
useId,
} from '@fluentui/react-components';

const useStyles = makeStyles({
secondLevel: { 'margin-left': '30px' },
thirdLevel: { 'margin-left': '60px' },
forthLevel: { 'margin-left': '90px' },
foundMessage: { 'margin-bottom': '10px' },
heading: { margin: '30px 0 10px 0' },
root: {
// Stack the label above the field with a gap
display: 'flex',
flexWrap: 'wrap',
gap: '2px',
maxWidth: '1600px',
},
tagsList: {
listStyleType: 'none',
marginBottom: tokens.spacingVerticalXXS,
marginTop: 0,
paddingLeft: 0,
display: 'flex',
gridGap: tokens.spacingHorizontalXXS,
},
tooltip: { maxWidth: '500px important!', backgroundColor: 'red' },
componentWrapper: {
margin: '10px',
padding: '10px',
border: '1px solid #ccc',
borderRadius: '5px',
display: 'flex',
alignItems: 'center',
gap: '10px',
},
questionsWrapper: {
padding: '20px',
margin: '20px 0',
backgroundColor: 'white',
borderRadius: '16px',
border: '1px solid var(--colorNeutralStroke1, #e1dfdd)',
boxShadow: '0 0 10px rgba(0, 0, 0, 0.1)',
},
questionsLabel: {
color: '#ff00ff',
fontWeight: tokens.fontWeightBold,
marginRight: '8px',
},
questionsText: {
fontWeight: tokens.fontWeightBold,
fontSize: tokens.fontSizeBase400,
},
questionContainer: {
display: 'flex',
},
questionRightSide: {
borderLeft: '1px solid #ff00ff',
padding: '0 10px',
},
radioItem: {
display: 'flex',
},
behaviors: { display: 'flex', gap: '10px' },
});

export const Question = ({ question, number, updateDecisionForQuestion }) => {
const classes = useStyles();
const [value, setValue] = React.useState('none');

React.useEffect(() => {
console.log(`UseEffect: Question${number}: Value: ${value}`);
}, [number, value]);

return (
<div className={classes.questionsWrapper}>
<Field className={classes.questionsField}>
<RadioGroup
key={question.id}
value={value}
onChange={(_, data) => {
setValue(previousValue => {
updateDecisionForQuestion(data.value, previousValue);
return data.value;
});
}}
aria-labelledby={`${question.id}-heading`}
>
<div className={classes.questionContainer}>
<div className={classes.questionLeftSide}>
<span className={classes.questionsLabel}>{`Q${number}`}</span>
</div>
<div className={classes.questionRightSide}>
<span className={classes.questionsText} id={`${question.id}-heading`}>
{question.question}
</span>
{question.answers.map(anser => (
<Radio key={anser.value} value={anser.value} label={anser.text} className={classes.radioItem} />
))}
<Radio value={'none'} label="Not applicable" className={classes.radioItem} />
</div>
</div>
</RadioGroup>
</Field>
</div>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import * as React from 'react';
import {
Button,
Caption1,
Card,
CardHeader,
CardPreview,
CardProps,
Checkbox,
Text,
makeStyles,
tokens,
} from '@fluentui/react-components';
import { MoreHorizontal20Regular } from '@fluentui/react-icons';
import { stat } from 'fs';

import * as componentsImagesImported from './components-images/index';

const useStyles = makeStyles({
main: {
gap: '16px',
display: 'flex',
flexWrap: 'wrap',
margin: '5px 10px 10px 5px',
},

card: {
width: '250px',
maxWidth: '100%',
height: 'fit-content',
},

caption: {
color: tokens.colorNeutralForeground3,
},

cardImage: {
borderRadius: tokens.borderRadiusXLarge,
border: '1px solid var(--colorNeutralStroke1, #e1dfdd)',
filter: 'grayscale(100%) brightness(95%)',
opacity: 0.5,

'&:hover': {
filter: 'grayscale(0%) brightness(100%)',
opacity: 1,
},
},
cardImageSelected: {
borderRadius: tokens.borderRadiusXLarge,
border: '1px solid var(--colorNeutralStroke1, #e1dfdd)',
filter: 'grayscale(0%) brightness(100%)',
opacity: 1,
},

grayBackground: {
padding: '0 15px 15px',
},
});

export const SelectionCard = props => {
const styles = useStyles();
const { name, displayName, selected, updateComponentSelection } = props;
const [hovered, setHovered] = React.useState(false);

const onSelectionChange = React.useCallback(
(_, data) => {
updateComponentSelection(name, data.checked || data.selected);
},
[updateComponentSelection, name],
);

const componentImage = React.useMemo(() => {
let src;
const importName = `${name}Img`;
if (componentsImagesImported[importName]) {
const result = {
src: componentsImagesImported[importName],
alt: `Preview for ${props.displayName}`,
};
return result;
} else {
return undefined;
}
}, [name, displayName]);

return (
<div className={styles.main}>
<Card
className={styles.card}
floatingAction={<Checkbox aria-label={displayName} onChange={onSelectionChange} checked={selected} />}
selected={selected}
onSelectionChange={onSelectionChange}
// onMouseOver={() => setHovered(true)}
// onMouseOut={() => setHovered(false)}
{...props}
>
<CardHeader description={<Caption1 className={styles.caption}>{displayName}</Caption1>} />
<CardPreview className={styles.grayBackground}>
{componentImage && (
<img
className={selected || hovered ? styles.cardImageSelected : styles.cardImage}
src={componentImage.src}
alt={componentImage.alt}
/>
)}
</CardPreview>
</Card>
</div>
);
};
Loading
Loading