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 datepicker as a fragment component #262

Open
wants to merge 44 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
646baf5
date picker
jz5426 Aug 31, 2023
6cb5cff
clean
jz5426 Aug 31, 2023
0219acf
lint
jz5426 Sep 6, 2023
63ca1b4
focus and datepicker input bottom alignment
jz5426 Sep 15, 2023
404c8a5
angular date picker export
jz5426 Sep 15, 2023
e6a3cf9
react date picker export
jz5426 Sep 15, 2023
668ba8f
fixed
jz5426 Sep 22, 2023
4157f0e
react has type = text
jz5426 Sep 22, 2023
5ed4b0b
Merge branch 'main' of https://github.com/IBM/carbon-ui-builder into …
jz5426 Oct 5, 2023
a381f4e
progress
jz5426 Oct 5, 2023
a3125bd
progress
jz5426 Oct 5, 2023
201484a
lint
jz5426 Oct 5, 2023
65a863c
value change
jz5426 Oct 5, 2023
a4b5655
value change
jz5426 Oct 5, 2023
c8fad9d
lint
jz5426 Oct 5, 2023
3bf5c40
console log error fix
jz5426 Oct 5, 2023
933e7ef
checkin changes
jz5426 Jan 4, 2024
7c3b89e
checkin changes
jz5426 Jan 4, 2024
251e7bb
checkin review changes
jz5426 Jan 10, 2024
a9eb7f7
in progress
Apr 18, 2024
dbb87df
fixed
Apr 18, 2024
a9dd65e
Merge branch 'main' of https://github.com/IBM/carbon-ui-builder into …
May 10, 2024
693d844
lint
May 10, 2024
8ebec46
fix: update date picker exports add missing attributes
Akshat55 May 22, 2024
2f862e0
fix: prevent checkbox inline style from leaking
Akshat55 May 22, 2024
38142f7
fix: show date format input only for 'single' or 'range'
Akshat55 May 28, 2024
ffe362d
style removal
May 28, 2024
81ed09e
quick fix
May 29, 2024
076953b
Update player/react/src/lib/components/ui-date-picker.tsx
jz5426 May 29, 2024
b37fd9f
Update player/react/src/lib/components/ui-date-picker.tsx
jz5426 May 29, 2024
6b82184
Update sdk/react/src/lib/fragment-components/a-date-picker.tsx
jz5426 May 29, 2024
7e92ac5
Update sdk/react/src/lib/fragment-components/a-date-picker.tsx
jz5426 May 29, 2024
acf664f
Update sdk/react/src/lib/fragment-components/a-date-picker.tsx
jz5426 May 29, 2024
ecef193
Update sdk/react/src/lib/fragment-components/a-date-picker.tsx
jz5426 May 29, 2024
4d65d81
fix: replace 'datePickerType' with 'kind' and remove unused styles
Akshat55 May 29, 2024
bc3c30b
fix: remove redundant id
Akshat55 May 30, 2024
9d18919
fix: clean up date picker component
Akshat55 May 30, 2024
9312697
react export fix
May 31, 2024
211e641
angular export
May 31, 2024
2b7fd06
revert context pane changes
Jul 23, 2024
749688e
terneries and indentation
Jul 23, 2024
cf36bd7
rangePlaceHolder
Jul 24, 2024
c2178fa
revision
Jul 25, 2024
8a15d63
revision
Jul 25, 2024
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
2 changes: 2 additions & 0 deletions player/react/src/lib/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as column from './ui-column';
import * as combobox from './ui-combobox';
import * as contentSwitcher from './ui-content-switcher';
import * as dropdown from './ui-dropdown';
import * as datePicker from './ui-date-picker';
import * as grid from './ui-grid';
import * as numberinput from './ui-number-input';
import * as radio from './ui-radio';
Expand Down Expand Up @@ -45,6 +46,7 @@ export const allComponents = {
contentSwitcher,
column,
dropdown,
datePicker,
grid,
loading,
inlineLoading,
Expand Down
128 changes: 128 additions & 0 deletions player/react/src/lib/components/ui-date-picker.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import React from 'react';
import {
DatePicker,
DatePickerInput
} from '@carbon/react';
import { commonSlots, slotsDisabled } from '../common-slots';
import { SendSignal, CssClasses } from '../types';
import { stringToCssClassName } from '../utils';

export interface DatePickerState {
type: string;
id: string;
placeholder?: string;
disabled?: boolean;
invalid?: boolean;
invalidText?: string;
rangeInvalidText?: string;
light?: boolean;
size?: string;
kind?: string;
dateFormat?: string;
value?: string;
rangeStartLabel?: string;
rangeEndLabel?: string;
rangePlaceholder?: string;
cssClasses?: CssClasses[];
codeContext: {
name: string;
};
style?: any;
}

export const type = 'date-picker';

export const slots = {
...commonSlots,
...slotsDisabled,
dateFormat: 'string',
kind: 'string',
placeholder: 'string',
size: 'string',
invalidText: 'string',
rangeStartLabel: 'string',
rangeEndLabel: 'string',
rangePlaceholder: 'string',
rangeInvalidText: 'string',
value: 'string',
invalid: 'boolean',
setInvalid: (state: DatePickerState) => ({
jz5426 marked this conversation as resolved.
Show resolved Hide resolved
...state,
invalid: true
}),
setValid: (state: DatePickerState) => ({
...state,
invalid: false
}),
toggleValid: (state: DatePickerState) => ({
...state,
invalid: !state.invalid
}),
light: 'boolean',
setLight: (state: DatePickerState) => ({
...state,
light: true
}),
setDark: (state: DatePickerState) => ({
...state,
light: false
}),
toggleLight: (state: DatePickerState) => ({
...state,
light: !state.light
})
};

export const signals = ['valueChange', 'click'];

export const UIDatePicker = ({ state, sendSignal }: {
state: DatePickerState;
setState: (state: any) => void;
setGlobalState: (state: any) => void;
sendSignal: SendSignal;
}) => {
if (state.type !== 'date-picker') {
// eslint-disable-next-line react/jsx-no-useless-fragment
return <></>;
}

let cssClasses = state.cssClasses?.map((cc: any) => cc.id).join(' ') || '';

if (state.style) {
if (cssClasses.length > 0) {
cssClasses += ' ';
}
cssClasses += stringToCssClassName(state.codeContext.name);
}

return <DatePicker
className={cssClasses}
dateFormat={state.dateFormat}
datePickerType={state.kind}
value={state.value}
light={state.light}
onClick={() => sendSignal(state.id, 'click')}
onChange={(event: any) => {
sendSignal(state.id, 'valueChange', [event[0].toISOString()], { ...state, value: event[0].toISOString() });
}}>
<DatePickerInput
id={state.id}
placeholder={state.placeholder}
labelText={state.rangeStartLabel}
size={state.size}
disabled={state.disabled}
invalid={state.invalid}
invalidText={state.invalidText}/>
{
state.kind === 'range'
&& <DatePickerInput
id={`${state.id}-end`}
placeholder={state.placeholder}
labelText={state.rangePlaceholder}
size={state.size}
disabled={state.disabled}
invalid={state.invalid}
invalidText={state.rangeInvalidText} />
}
</DatePicker>;
};
4 changes: 4 additions & 0 deletions player/react/src/lib/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { UICodeSnippet } from './components/ui-code-snippet';
import { UIColumn } from './components/ui-column';
import { UIComboBox } from './components/ui-combobox';
import { UIContentSwitcher } from './components/ui-content-switcher';
import { UIDatePicker } from './components/ui-date-picker';
import { UIDropdown } from './components/ui-dropdown';
import { UIExpandableTile } from './components/ui-expandable-tile';
import { UIGrid } from './components/ui-grid';
Expand Down Expand Up @@ -238,6 +239,9 @@ export const renderComponents = (
case 'content-switcher':
return <UIContentSwitcher key={state.id} state={state} sendSignal={sendSignal} setState={setState} setGlobalState={setGlobalState} />;

case 'date-picker':
return <UIDatePicker key={state.id} state={state} sendSignal={sendSignal} setState={setState} setGlobalState={setGlobalState} />;

case 'dropdown':
return <UIDropdown key={state.id} state={state} sendSignal={sendSignal} setState={setState} setGlobalState={setGlobalState} />;

Expand Down
15 changes: 15 additions & 0 deletions sdk/react/src/lib/assets/component-icons/date-picker.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions sdk/react/src/lib/components/settings-context-pane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
if (setExternalSettings) {
setExternalSettings(settings);
}
}, [settings]);

Check warning on line 211 in sdk/react/src/lib/components/settings-context-pane.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has a missing dependency: 'setExternalSettings'. Either include it or remove the dependency array. If 'setExternalSettings' changes too often, find the parent component that defines it and wrap that definition in useCallback

return (
<div className={cx(styleContextPaneStyle, 'context-pane-content')}>
Expand Down Expand Up @@ -237,7 +237,7 @@
</>
}
{
!selectedComponent && <>
!selectedComponent && <div className={cx(styleContextPaneStyle)}>
<Checkbox
id='setFragmentAsTemplate'
checked={fragment.labels && fragment.labels.includes('template')}
Expand Down Expand Up @@ -291,7 +291,7 @@
className={tooltipStyle}>
micro layout
</DefinitionTooltip>
</>
</div>
}
</div>
}
Expand Down
Loading
Loading