-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce5f7f4
commit a030fd6
Showing
4 changed files
with
88 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// ___ _ | ||
// | _ \_____ _____ __ _| |___ _ _ | ||
// | / -_) V / -_) _` | / -_) '_| | ||
// |_|_\___|\_/\___\__,_|_\___|_| | ||
// | ||
//////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
/** | ||
* ### Revealer | ||
* *Organism* | ||
* | ||
* This module contains the render function for the `<Revealer />` island. | ||
* | ||
* @module | ||
*/ | ||
import { useState } from 'preact/hooks'; | ||
import setup, { iRevealer } from './setup.ts'; | ||
|
||
export default function (props: Partial<iRevealer>) { | ||
const { children, fwd, actuator, ...p } = setup(props); | ||
const [isRevealed, setRevealed] = useState<boolean>(false); | ||
|
||
return ( | ||
<div {...p}> | ||
{isRevealed ? null : ( | ||
<div onClick={() => setRevealed(true)}> | ||
{actuator} | ||
</div> | ||
)} | ||
<div> | ||
{isRevealed ? children : null} | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// ___ _ ___ _ | ||
// | _ \_____ _____ __ _| |___ _ _ / __| ___| |_ _ _ _ __ | ||
// | / -_) V / -_) _` | / -_) '_| \__ \/ -_) _| || | '_ \ | ||
// |_|_\___|\_/\___\__,_|_\___|_| |___/\___|\__|\_,_| .__/ | ||
// |_| | ||
//////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
/** | ||
* This module contains the prop type, default values, and styles for the `<Revealer />` island. | ||
* | ||
* @module | ||
*/ | ||
import { apDef, forward, o } from '../../src/utils.ts'; | ||
import { iComponent, iFwd } from '../../src/types.ts'; | ||
import Link from '../../components/Link/index.tsx'; | ||
import { ComponentChild } from 'preact'; | ||
|
||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
/** Properties of the `<Revealer />` island. */ | ||
export type iRevealer = iComponent<HTMLDivElement> & { | ||
actuator: ComponentChild; | ||
fwd: Partial<iRevealerFwd>; | ||
}; | ||
|
||
type iRevealerFwd = { | ||
revelation: iFwd<HTMLDivElement>; | ||
}; | ||
|
||
/** These are the default values of the `<Revealer />` island's props. */ | ||
const defaults: iRevealer = { | ||
actuator: Link({ children: 'Read more' }), | ||
fwd: { | ||
revelation: {}, | ||
}, | ||
}; | ||
|
||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
/** Setup function of the `<Revealer />` island. */ | ||
export default (props: Partial<iRevealer>) => { | ||
const p = apDef<iRevealer>(defaults, props); | ||
|
||
p.class = o('revealer', { ...p }); | ||
|
||
p.fwd = forward({ | ||
revelation: 'revealer__revelation', | ||
}, p.fwd); | ||
|
||
return p; | ||
}; |