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

feat: Add inline loading component #202

Merged
merged 20 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
fa71f16
Add inline loading component
MoizMasud Dec 7, 2022
d541694
Remove extra bracket from react export
Akshat55 Dec 7, 2022
547dfc7
Update src/fragment-components/a-inline-loading.tsx
zvonimirfras Dec 8, 2022
d458029
Update src/fragment-components/a-inline-loading.tsx
zvonimirfras Dec 8, 2022
1b0e3aa
Update src/fragment-components/a-inline-loading.tsx
zvonimirfras Dec 8, 2022
8908868
Update src/fragment-components/a-inline-loading.tsx
zvonimirfras Dec 8, 2022
66e5f5d
Update src/fragment-components/a-inline-loading.tsx
zvonimirfras Dec 8, 2022
55e38ca
Update src/fragment-components/a-inline-loading.tsx
zvonimirfras Dec 8, 2022
a20744d
Update src/fragment-components/a-inline-loading.tsx
zvonimirfras Dec 8, 2022
9e6fbce
Merge branch 'main' into inline-loading-1
Akshat55 Dec 8, 2022
10c3827
Update src/fragment-components/a-inline-loading.tsx
Akshat55 Dec 8, 2022
fec579a
Update src/fragment-components/a-inline-loading.tsx
Akshat55 Dec 8, 2022
0734342
Update src/fragment-components/a-inline-loading.tsx
Akshat55 Dec 8, 2022
5df6c87
Update src/fragment-components/a-inline-loading.tsx
Akshat55 Dec 8, 2022
3af03dc
Update src/fragment-components/a-inline-loading.tsx
Akshat55 Dec 8, 2022
51882f6
Apply suggestions from code review
zvonimirfras Dec 9, 2022
54ea69a
Update src/fragment-components/a-inline-loading.tsx
zvonimirfras Dec 9, 2022
d071f4f
Merge branch 'main' of https://github.com/MoizMasud/carbon-components…
MoizMasud Jan 3, 2023
4c26e52
Add dropdown for status change and added accordian
MoizMasud Jan 3, 2023
feeb2ba
Lint alittle
MoizMasud Jan 3, 2023
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
19 changes: 19 additions & 0 deletions src/assets/component-icons/inline-loading.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
247 changes: 247 additions & 0 deletions src/fragment-components/a-inline-loading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
import React from 'react';
import {
RadioButtonGroup,
RadioButton,
InlineLoading,
TextInput,
NumberInput
} from 'carbon-components-react';
import { AComponent } from './a-component';
import { ComponentInfo } from '.';
import { css } from 'emotion';
import image from './../assets/component-icons/inline-loading.svg';
import {
nameStringToVariableString,
reactClassNamesFromComponentObj,
angularClassNamesFromComponentObj
} from '../utils/fragment-tools';

export const AInlineLoadingSettingsUI = ({ selectedComponent, setComponent }: any) => {
return <>
<legend className='bx--label'>Status</legend>
<RadioButtonGroup
MoizMasud marked this conversation as resolved.
Show resolved Hide resolved
orientation='vertical'
name='status-radio-buttons'
valueSelected={selectedComponent.status}
onChange={(event: any) => setComponent({
...selectedComponent,
status: event
})}>
<RadioButton
id='inactive'
labelText='Inactive'
value='inactive' />
<RadioButton
id='active'
labelText='Active'
value='active' />
<RadioButton
id='finished'
labelText='Finished'
value='finished' />
<RadioButton
id='error'
labelText='Error'
value='error' />
</RadioButtonGroup>
<TextInput
value={selectedComponent.activeText}
labelText='Active text description'
zvonimirfras marked this conversation as resolved.
Show resolved Hide resolved
onChange={(event: any) => setComponent({
...selectedComponent,
activeText: event.currentTarget.value
})} />
<TextInput
value={selectedComponent.inactiveText}
labelText='Inactive text description'
zvonimirfras marked this conversation as resolved.
Show resolved Hide resolved
onChange={(event: any) => setComponent({
...selectedComponent,
inactiveText: event.currentTarget.value
})} />
<TextInput
value={selectedComponent.errorText}
labelText='Error text description'
zvonimirfras marked this conversation as resolved.
Show resolved Hide resolved
onChange={(event: any) => setComponent({
...selectedComponent,
errorText: event.currentTarget.value
})} />
<TextInput
value={selectedComponent.successText}
labelText='Success text description'
zvonimirfras marked this conversation as resolved.
Show resolved Hide resolved
onChange={(event: any) => setComponent({
...selectedComponent,
successText: event.currentTarget.value
})} />
<TextInput
MoizMasud marked this conversation as resolved.
Show resolved Hide resolved
value={selectedComponent.activeIconDescription}
labelText='Active icon description'
onChange={(event: any) => setComponent({
...selectedComponent,
activeIconDescription: event.currentTarget.value
})} />
<TextInput
value={selectedComponent.errorIconDescription}
labelText='Error icon description'
onChange={(event: any) => setComponent({
...selectedComponent,
errorIconDescription: event.currentTarget.value
})} />
<TextInput
value={selectedComponent.finishedIconDescription}
labelText='Finished icon description'
onChange={(event: any) => setComponent({
...selectedComponent,
finishedIconDescription: event.currentTarget.value
})} />
<TextInput
value={selectedComponent.inactiveIconDescription}
labelText='Inactive icon description'
onChange={(event: any) => setComponent({
...selectedComponent,
inactiveIconDescription: event.currentTarget.value
})} />
<NumberInput
id='successDelay'
min={0}
label='Success delay (ms)'
name='successDelay'
value={selectedComponent.successDelay}
zvonimirfras marked this conversation as resolved.
Show resolved Hide resolved
onChange={(event: any) => setComponent({
...selectedComponent,
successDelay: Number(event.imaginaryTarget.value)
})} />
</>;
};

export const AInlineLoadingCodeUI = ({ selectedComponent, setComponent }: any) => <TextInput
value={selectedComponent.codeContext?.name}
labelText='Input name'
onChange={(event: any) => setComponent({
...selectedComponent,
codeContext: {
...selectedComponent.codeContext,
name: event.currentTarget.value
}
})}
/>;

export const AInlineLoading = ({
componentObj,
...rest
}: any) => {
const status: any = {
active: {
iconDescription: componentObj.activeIconDescription,
description: componentObj.activeText
},
error: {
iconDescription: componentObj.errorIconDescription,
description: componentObj.errorText
},
inactive: {
iconDescription: componentObj.inactiveIconDescription,
description: componentObj.inactiveText
},
finished: {
iconDescription: componentObj.finishedIconDescription,
description: componentObj.successText
}
};

return (
<AComponent
componentObj={componentObj}
headingCss={css`display: block;`}
rejectDrop={true}
{...rest}>
<InlineLoading
successDelay={componentObj.successDelay}
description={status[componentObj.status].description}
iconDescription={status[componentObj.status].iconDescription}
status={componentObj.status}
className={componentObj.cssClasses?.map((cc: any) => cc.id).join(' ')} />
</AComponent>
);
};

export const componentInfo: ComponentInfo = {
component: AInlineLoading,
codeUI: AInlineLoadingCodeUI,
settingsUI: AInlineLoadingSettingsUI,
keywords: ['inline', 'loading'],
name: 'Inline Loading',
zvonimirfras marked this conversation as resolved.
Show resolved Hide resolved
type: 'inline-loading',
defaultComponentObj: {
type: 'inline-loading',
status: 'active'
zvonimirfras marked this conversation as resolved.
Show resolved Hide resolved
},
image,
codeExport: {
angular: {
inputs: ({ json }) => `@Input() ${nameStringToVariableString(json.codeContext?.name)}Status = "${json.status}";
@Input() ${nameStringToVariableString(json.codeContext?.name)}LoadingText = "${json.activeText || 'Loading...'}";
@Input() ${nameStringToVariableString(json.codeContext?.name)}SuccessText = "${json.successText || 'Finished.'}";
@Input() ${nameStringToVariableString(json.codeContext?.name)}ErrorText = "${json.errorText || 'Error!'}";
zvonimirfras marked this conversation as resolved.
Show resolved Hide resolved
@Input() ${nameStringToVariableString(json.codeContext?.name)}SuccessDelay = ${json.successDelay === undefined ? 1500 : json.successDelay };`,
outputs: ({ json }) => `@Output() ${nameStringToVariableString(json.codeContext?.name)}OnSuccess = new EventEmitter();`,
imports: ['InlineLoadingModule'],
code: ({ json }) => {
return `<ibm-inline-loading
(onSuccess)="${nameStringToVariableString(json.codeContext?.name)}OnSuccess.emit($event)"
[successDelay]="${nameStringToVariableString(json.codeContext?.name)}SuccessDelay"
[state]="${nameStringToVariableString(json.codeContext?.name)}Status"
[loadingText]="${nameStringToVariableString(json.codeContext?.name)}LoadingText"
[successText]="${nameStringToVariableString(json.codeContext?.name)}SuccessText"
[errorText]="${nameStringToVariableString(json.codeContext?.name)}ErrorText"
${angularClassNamesFromComponentObj(json)}>
</ibm-inline-loading>`;
}
},
react: {
imports: ['InlineLoading'],
code: ({ json }) => {
const status = `state["${nameStringToVariableString(json.codeContext?.name)}"] || "${json.status}"`;
return `<InlineLoading
onSuccess={() => {
if (typeof state.${nameStringToVariableString(json.codeContext?.name)}OnSuccess === "function") {
state.${nameStringToVariableString(json.codeContext?.name)}OnSuccess();
}
}}
successDelay={${json.successDelay}}
description={${nameStringToVariableString(json.codeContext?.name)}StatusDescription}
iconDescription={${nameStringToVariableString(json.codeContext?.name)}StatusIconDescription}
status={${status}}
${reactClassNamesFromComponentObj(json)} />`;
},
additionalCode: (json) => {
const name = nameStringToVariableString(json.codeContext?.name);
const status = `${name}Status`;
const statusDescription = `${name}StatusDescription`;
const statusIconDescription = `${name}StatusIconDescription`;

return {
zvonimirfras marked this conversation as resolved.
Show resolved Hide resolved
[status]: `const ${status} = {
active: {
iconDescription: "${json.activeIconDescription}",
description: "${json.activeText}"
Akshat55 marked this conversation as resolved.
Show resolved Hide resolved
},
error: {
iconDescription: "${json.errorIconDescription}",
description: "${json.errorText}"
Akshat55 marked this conversation as resolved.
Show resolved Hide resolved
},
inactive: {
iconDescription: "${json.inactiveIconDescription}",
description: "${json.inactiveText}"
Akshat55 marked this conversation as resolved.
Show resolved Hide resolved
},
finished: {
iconDescription: "${json.finishedIconDescription}",
description: "${json.successText}"
Akshat55 marked this conversation as resolved.
Show resolved Hide resolved
}
}`,
[statusDescription]: `const ${statusDescription} = ${status}[state["${name}"] || "${json.status}"].description`,
[statusIconDescription]: `const ${statusIconDescription} = ${status}[state["${name}"] || "${json.status}"].iconDescription`
};
}
}
}
};
3 changes: 3 additions & 0 deletions src/fragment-components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import * as textarea from './a-text-area';
import * as textinput from './a-text-input';
import * as link from './a-link';
import * as loading from './a-loading';
import * as inlineLoading from './a-inline-loading';
import * as overflowMenu from './a-overflow-menu';
// Tiles
import * as tile from './tiles/a-tile';
Expand Down Expand Up @@ -50,6 +51,7 @@ export { AFragment, AFragmentSettingsUI, AFragmentCodeUI } from './a-fragment';
export { AGrid, AGridSettingsUI } from './a-grid';
export { ALoading, ALoadingCodeUI, ALoadingSettingsUI } from './a-loading';
export { ALink, ALinkSettingsUI, ALinkCodeUI } from './a-link';
export { AInlineLoading, AInlineLoadingCodeUI, AInlineLoadingSettingsUI } from './a-inline-loading';
export { ANumberInput, ANumberInputSettingsUI, ANumberInputCodeUI } from './a-numberinput';
export { AProgressIndicator, AProgressIndicatorSettingsUI, AProgressIndicatorCodeUI } from './a-progress-indicator';
export { ARow, ARowSettingsUI } from './a-row';
Expand Down Expand Up @@ -87,6 +89,7 @@ export const allComponents = {
fragment,
grid,
loading,
inlineLoading,
radio,
radioGroup,
link,
Expand Down
56 changes: 56 additions & 0 deletions src/ui-fragment/src/components/ui-inline-loading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React from 'react';
import { InlineLoading } from 'carbon-components-react';
import { CssClasses } from '../types';

export interface InlineLoadingState {
type: string;
status: string;
activeIconDescription: string;
activeText: string;
errorIconDescription: string;
errorText: string;
inactiveIconDescription: string;
inactiveText: string;
finishedIconDescription: string;
successText: string;
successDelay: number;
cssClasses?: CssClasses[];
codeContext?: {
name: string;
};
}

export const UIInlineLoading = ({ state }: {
state: InlineLoadingState;
setState: (state: any) => void;
setGlobalState: (state: any) => void;
}) => {
if (state.type !== 'inline-loading') {
// eslint-disable-next-line react/jsx-no-useless-fragment
return <></>;
}
const status: any = {
active: {
iconDescription: state.activeIconDescription,
description: state.activeText
},
error: {
iconDescription: state.errorIconDescription,
description: state.errorText
},
inactive: {
iconDescription: state.inactiveIconDescription,
description: state.inactiveText
},
finished: {
iconDescription: state.finishedIconDescription,
description: state.successText
}
};
return <InlineLoading
successDelay={state.successDelay}
description={status[state.status].description}
iconDescription={status[state.status].iconDescription}
status={state.status}
className={state.cssClasses?.map((cc: any) => cc.id).join(' ')} />;
};
4 changes: 4 additions & 0 deletions src/ui-fragment/src/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { UIDropdown } from './components/ui-dropdown';
import { UIExpandableTile } from './components/ui-expandable-tile';
import { UIGrid } from './components/ui-grid';
import { UILink } from './components/ui-link';
import { UIInlineLoading } from './components/ui-inline-loading';
import { UILoading } from './components/ui-loading';
import { UINumberInput } from './components/ui-number-input';
import { UIOverflowMenu } from './components/ui-overflow-menu';
Expand Down Expand Up @@ -151,6 +152,9 @@ export const renderComponents = (state: any, setState: (state: any) => void, set
case 'loading':
return <UILoading key={state.id} state={state} setState={setState} setGlobalState={setGlobalState} />;

case 'inline-loading':
return <UIInlineLoading key={state.id} state={state} setState={setState} setGlobalState={setGlobalState} />;

case 'radio-group':
return <UIRadioGroup key={state.id} state={state} setState={setState} setGlobalState={setGlobalState} />;

Expand Down