diff --git a/packages/mdc-segmented-button/index.ts b/packages/mdc-segmented-button/index.ts new file mode 100644 index 00000000000..e6e7a4d580a --- /dev/null +++ b/packages/mdc-segmented-button/index.ts @@ -0,0 +1,25 @@ +/** + * @license + * Copyright 2020 Google Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +export * from './segmented-button/index'; +export * from './segment/index'; diff --git a/packages/mdc-segmented-button/package.json b/packages/mdc-segmented-button/package.json index 8ae17e91ba5..5f527891b7a 100644 --- a/packages/mdc-segmented-button/package.json +++ b/packages/mdc-segmented-button/package.json @@ -15,5 +15,8 @@ ], "publishConfig": { "access": "public" + }, + "dependencies": { + "@material/base": "^7.0.0" } } diff --git a/packages/mdc-segmented-button/segment/adapter.ts b/packages/mdc-segmented-button/segment/adapter.ts new file mode 100644 index 00000000000..990c11a2b76 --- /dev/null +++ b/packages/mdc-segmented-button/segment/adapter.ts @@ -0,0 +1,38 @@ +/** + * @license + * Copyright 2020 Google Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +export interface MDCSegmentedButtonSegmentAdapter { + isSingleSelect(): boolean; + + getAttr(attrName: string): string; + + setAttr(attrName: string, value: string): void; + + addClass(className: string): void; + + removeClass(className: string): void; + + hasClass(className: string): boolean; + + notifySelectedChange(selected: boolean): void; +} diff --git a/packages/mdc-segmented-button/segment/foundation.ts b/packages/mdc-segmented-button/segment/foundation.ts new file mode 100644 index 00000000000..4c7611cb7c8 --- /dev/null +++ b/packages/mdc-segmented-button/segment/foundation.ts @@ -0,0 +1,63 @@ +/** + * @license + * Copyright 2020 Google Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +import {MDCFoundation} from '@material/base/foundation'; +import {MDCSegmentedButtonSegmentAdapter} from './adapter'; + +export class MDCSegmentedButtonSegmentFoundation extends MDCFoundation { + static get defaultAdapter(): MDCSegmentedButtonSegmentAdapter { + return { + isSingleSelect: () => false, + getAttr: () => '', + setAttr: () => undefined, + addClass: () => undefined, + removeClass: () => undefined, + hasClass: () => false, + notifySelectedChange: () => undefined + } + } + + constructor(adapter?: Partial) { + super({...MDCSegmentedButtonSegmentFoundation.defaultAdapter, ...adapter}); + } + + isSelected(): boolean { + return false; + } + + setSelected() { + return; + } + + setUnselected() { + return; + } + + getSegmentId(): string { + return ''; + } + + handleClick() { + return; + } +} diff --git a/packages/mdc-segmented-button/segment/index.ts b/packages/mdc-segmented-button/segment/index.ts new file mode 100644 index 00000000000..4d2c9c2aafa --- /dev/null +++ b/packages/mdc-segmented-button/segment/index.ts @@ -0,0 +1,25 @@ +/** + * @license + * Copyright 2020 Google Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +export * from './adapter'; +export * from './foundation'; diff --git a/packages/mdc-segmented-button/segmented-button/adapter.ts b/packages/mdc-segmented-button/segmented-button/adapter.ts new file mode 100644 index 00000000000..e24e7237c26 --- /dev/null +++ b/packages/mdc-segmented-button/segmented-button/adapter.ts @@ -0,0 +1,36 @@ +/** + * @license + * Copyright 2020 Google Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +import {SegmentDetail} from '../types'; + +export interface MDCSegmentedButtonAdapter { + hasClass(className: string): boolean; + + getSegments(): readonly SegmentDetail[]; + + selectSegment(indexOrSegmentId: number | string): void; + + unselectSegment(indexOrSegmentId: number | string): void; + + notifySelectedChange(detail: SegmentDetail): void; +} diff --git a/packages/mdc-segmented-button/segmented-button/foundation.ts b/packages/mdc-segmented-button/segmented-button/foundation.ts new file mode 100644 index 00000000000..786a216b238 --- /dev/null +++ b/packages/mdc-segmented-button/segmented-button/foundation.ts @@ -0,0 +1,66 @@ +/** + * @license + * Copyright 2020 Google Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +import {MDCFoundation} from '@material/base/foundation'; +import {MDCSegmentedButtonAdapter} from './adapter'; +import {SegmentDetail} from '../types'; + +export class MDCSegmentedButtonFoundation extends MDCFoundation { + static get defaultAdapter(): MDCSegmentedButtonAdapter { + return { + hasClass: () => false, + getSegments: () => [], + selectSegment: () => undefined, + unselectSegment: () => undefined, + notifySelectedChange: () => undefined + } + } + + constructor(adapter?: Partial) { + super({...MDCSegmentedButtonFoundation.defaultAdapter, ...adapter}); + } + + selectSegment(_indexOrSegmentId: number | string) { + return; + } + + unselectSegment(_indexOrSegmentId: number | string) { + return; + } + + getSelectedSegments(): readonly SegmentDetail[] { + return []; + } + + isSegmentSelected(_indexOrSegmentId: number | string): boolean { + return false; + } + + isSingleSelect(): boolean { + return false; + } + + handleSelected(_detail: SegmentDetail) { + return; + } +} diff --git a/packages/mdc-segmented-button/segmented-button/index.ts b/packages/mdc-segmented-button/segmented-button/index.ts new file mode 100644 index 00000000000..4d2c9c2aafa --- /dev/null +++ b/packages/mdc-segmented-button/segmented-button/index.ts @@ -0,0 +1,25 @@ +/** + * @license + * Copyright 2020 Google Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +export * from './adapter'; +export * from './foundation'; diff --git a/packages/mdc-segmented-button/types.ts b/packages/mdc-segmented-button/types.ts new file mode 100644 index 00000000000..4616c7b5d93 --- /dev/null +++ b/packages/mdc-segmented-button/types.ts @@ -0,0 +1,40 @@ +/** + * @license + * Copyright 2020 Google Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + + /** + * Event detail triggered by a click on a segment. This event detail is used + * to alert the segment-button to the change and trigger a DOM event. + */ + export interface SegmentDetail { + index: number; + selected: boolean; + segmentId?: string; + } + + /** + * Event emitted by segment to alert the segment-button of a change in its + * selected status. + */ + export interface MDCSegmentedButtonEvent extends Event { + readonly detail: SegmentDetail; + }