preact#createRef TypeScript Examples
The following examples show how to use
preact#createRef.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: config.ts From gridjs with MIT License | 6 votes |
static defaultConfig(): Config {
return {
plugin: new PluginManager(),
dispatcher: new Dispatcher<any>(),
tableRef: createRef(),
tempRef: createRef(),
width: '100%',
height: 'auto',
autoWidth: true,
style: {},
className: {},
} as Config;
}
Example #2
Source File: TextEditTool.tsx From LogicFlow with Apache License 2.0 | 5 votes |
ref = createRef();
Example #3
Source File: header.ts From gridjs with MIT License | 5 votes |
/**
* Tries to automatically adjust the width of columns based on:
* - Header cell content
* - Cell content of the first row
* - Cell content of the last row
*
* @param config
*/
adjustWidth(config: Config): this {
const container: Element = config.container;
const tableRef: RefObject<Component> = config.tableRef;
const tempRef: RefObject<HTMLDivElement> = config.tempRef;
const autoWidth = config.tempRef || true;
if (!container) {
// we can't calculate the width because the container
// is unknown at this stage
return this;
}
// pixels
const containerWidth = container.clientWidth;
// let's create a shadow table with the first 10 rows of the data
// and let the browser to render the table with table-layout: auto
// no padding, margin or border to get the minimum space required
// to render columns. One the table is rendered and widths are known,
// we unmount the shadow table from the DOM and set the correct width
const shadowTable = createRef();
let widths = {};
if (tableRef.current && autoWidth) {
// render a ShadowTable with the first 10 rows
const el = h(ShadowTable, {
tableRef: tableRef,
});
el.ref = shadowTable;
render(el, tempRef.current);
widths = shadowTable.current.widths();
}
for (const column of flatten(Header.tabularFormat(this.columns))) {
// because we don't want to set the width of parent THs
if (column.columns && column.columns.length > 0) {
continue;
}
if (!column.width && autoWidth) {
// tries to find the corresponding cell
// from the ShadowTable and set the correct width
if (column.id in widths) {
// because a column can be hidden, too
column.width = px(widths[column.id]['width']);
column.minWidth = px(widths[column.id]['minWidth']);
}
} else {
// column width is already defined
// sets the column with based on the width of its container
column.width = px(width(column.width, containerWidth));
}
}
if (tableRef.current && autoWidth) {
// unmount the shadow table from temp
render(null, tempRef.current);
}
return this;
}
Example #4
Source File: footerContainer.tsx From gridjs with MIT License | 5 votes |
private footerRef = createRef();
Example #5
Source File: headerContainer.tsx From gridjs with MIT License | 5 votes |
private headerRef = createRef();
Example #6
Source File: th.tsx From gridjs with MIT License | 5 votes |
private sortRef = createRef();
Example #7
Source File: th.tsx From gridjs with MIT License | 5 votes |
private thRef = createRef();
Example #8
Source File: createMindmap.tsx From remind with MIT License | 5 votes |
function createMindmap(el: HTMLElement, options?: Partial<MindmapProps>) {
const ref = createRef<ContributionAPI>()
render(<MindmapApp ref={ref} {...options} />, el)
return ref
}
Example #9
Source File: OpenInvoice.tsx From adyen-web with MIT License | 4 votes |
export default function OpenInvoice(props: OpenInvoiceProps) {
const { countryCode, visibility } = props;
const { i18n } = useCoreContext();
const initialActiveFieldsets: OpenInvoiceActiveFieldsets = getInitialActiveFieldsets(visibility, props.data);
const [activeFieldsets, setActiveFieldsets] = useState<OpenInvoiceActiveFieldsets>(initialActiveFieldsets);
const fieldsetsRefs: OpenInvoiceFieldsetsRefs = fieldsetsSchema.reduce((acc, fieldset) => {
acc[fieldset] = createRef();
return acc;
}, {});
const checkFieldsets = () => Object.keys(activeFieldsets).every(fieldset => !activeFieldsets[fieldset] || !!valid[fieldset]);
const hasConsentCheckbox = !!props.consentCheckboxLabel;
const isStandAloneButton = !hasConsentCheckbox && Object.keys(activeFieldsets).every(key => !activeFieldsets[key]);
const showSeparateDeliveryAddressCheckbox = visibility.deliveryAddress === 'editable' && visibility.billingAddress !== 'hidden';
const [data, setData] = useState<OpenInvoiceStateData>({
...props.data,
...(hasConsentCheckbox && { consentCheckbox: false })
});
const [errors, setErrors] = useState<OpenInvoiceStateError>({});
const [valid, setValid] = useState<OpenInvoiceStateValid>({});
const [status, setStatus] = useState('ready');
this.setStatus = setStatus;
useEffect(() => {
const fieldsetsAreValid: boolean = checkFieldsets();
const consentCheckboxValid: boolean = !hasConsentCheckbox || !!valid.consentCheckbox;
const isValid: boolean = fieldsetsAreValid && consentCheckboxValid;
const newData: OpenInvoiceStateData = getActiveFieldsData(activeFieldsets, data);
props.onChange({ data: newData, errors, valid, isValid });
}, [data, activeFieldsets]);
const handleFieldset = key => state => {
setData(prevData => ({ ...prevData, [key]: state.data }));
setValid(prevValid => ({ ...prevValid, [key]: state.isValid }));
setErrors(prevErrors => ({ ...prevErrors, [key]: state.errors }));
};
const handleSeparateDeliveryAddress = () => {
setActiveFieldsets(prevActiveFields => ({
...prevActiveFields,
deliveryAddress: !activeFieldsets.deliveryAddress
}));
};
const handleConsentCheckbox = e => {
const { checked } = e.target;
setData(prevData => ({ ...prevData, consentCheckbox: checked }));
setValid(prevValid => ({ ...prevValid, consentCheckbox: checked }));
setErrors(prevErrors => ({ ...prevErrors, consentCheckbox: !checked }));
};
this.showValidation = () => {
fieldsetsSchema.forEach(fieldset => {
if (fieldsetsRefs[fieldset].current) fieldsetsRefs[fieldset].current.showValidation();
});
setErrors({
...(hasConsentCheckbox && { consentCheckbox: !data.consentCheckbox })
});
};
return (
<div className="adyen-checkout__open-invoice">
{activeFieldsets.companyDetails && (
<CompanyDetails
data={props.data.companyDetails}
label="companyDetails"
onChange={handleFieldset('companyDetails')}
ref={fieldsetsRefs.companyDetails}
visibility={visibility.companyDetails}
/>
)}
{activeFieldsets.personalDetails && (
<PersonalDetails
data={props.data.personalDetails}
requiredFields={props.personalDetailsRequiredFields}
label="personalDetails"
onChange={handleFieldset('personalDetails')}
ref={fieldsetsRefs.personalDetails}
visibility={visibility.personalDetails}
/>
)}
{activeFieldsets.bankAccount && (
<IbanInput
holderName={true}
label="bankAccount"
data={data.bankAccount}
onChange={handleFieldset('bankAccount')}
ref={fieldsetsRefs.bankAccount}
/>
)}
{activeFieldsets.billingAddress && (
<Address
allowedCountries={props.allowedCountries}
countryCode={countryCode}
requiredFields={props.billingAddressRequiredFields}
specifications={props.billingAddressSpecification}
data={data.billingAddress}
label="billingAddress"
onChange={handleFieldset('billingAddress')}
ref={fieldsetsRefs.billingAddress}
visibility={visibility.billingAddress}
/>
)}
{showSeparateDeliveryAddressCheckbox && (
<Checkbox
label={i18n.get('separateDeliveryAddress')}
checked={activeFieldsets.deliveryAddress}
classNameModifiers={['separateDeliveryAddress']}
name="separateDeliveryAddress"
onChange={handleSeparateDeliveryAddress}
/>
)}
{activeFieldsets.deliveryAddress && (
<Address
allowedCountries={props.allowedCountries}
countryCode={countryCode}
data={data.deliveryAddress}
label="deliveryAddress"
onChange={handleFieldset('deliveryAddress')}
ref={fieldsetsRefs.deliveryAddress}
visibility={visibility.deliveryAddress}
/>
)}
{hasConsentCheckbox && (
<ConsentCheckbox
data={data}
errorMessage={!!errors.consentCheckbox}
label={props.consentCheckboxLabel}
onChange={handleConsentCheckbox}
/>
)}
{props.showPayButton &&
props.payButton({
status,
classNameModifiers: [...(isStandAloneButton ? ['standalone'] : [])],
label: i18n.get('confirmPurchase')
})}
</div>
);
}